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
,
259 struct gl_renderbuffer_attachment
*att
)
261 if (att
->Type
== GL_TEXTURE
) {
262 ASSERT(att
->Texture
);
263 if (ctx
->Driver
.FinishRenderTexture
) {
264 /* tell driver that we're done rendering to this texture. */
265 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
267 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
268 ASSERT(!att
->Texture
);
270 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
271 ASSERT(!att
->Texture
);
272 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
273 ASSERT(!att
->Renderbuffer
);
276 att
->Complete
= GL_TRUE
;
281 * Bind a texture object to an attachment point.
282 * The previous binding, if any, will be removed first.
285 _mesa_set_texture_attachment(struct gl_context
*ctx
,
286 struct gl_framebuffer
*fb
,
287 struct gl_renderbuffer_attachment
*att
,
288 struct gl_texture_object
*texObj
,
289 GLenum texTarget
, GLuint level
, GLuint zoffset
)
291 if (att
->Texture
== texObj
) {
292 /* re-attaching same texture */
293 ASSERT(att
->Type
== GL_TEXTURE
);
294 if (ctx
->Driver
.FinishRenderTexture
)
295 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
299 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
300 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
301 _mesa_remove_attachment(ctx
, att
);
302 att
->Type
= GL_TEXTURE
;
303 assert(!att
->Texture
);
304 _mesa_reference_texobj(&att
->Texture
, texObj
);
307 /* always update these fields */
308 att
->TextureLevel
= level
;
309 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
310 att
->Zoffset
= zoffset
;
311 att
->Complete
= GL_FALSE
;
313 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
314 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
317 invalidate_framebuffer(fb
);
322 * Bind a renderbuffer to an attachment point.
323 * The previous binding, if any, will be removed first.
326 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
327 struct gl_renderbuffer_attachment
*att
,
328 struct gl_renderbuffer
*rb
)
330 /* XXX check if re-doing same attachment, exit early */
331 _mesa_remove_attachment(ctx
, att
);
332 att
->Type
= GL_RENDERBUFFER_EXT
;
333 att
->Texture
= NULL
; /* just to be safe */
334 att
->Complete
= GL_FALSE
;
335 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
340 * Fallback for ctx->Driver.FramebufferRenderbuffer()
341 * Attach a renderbuffer object to a framebuffer object.
344 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
345 struct gl_framebuffer
*fb
,
346 GLenum attachment
, struct gl_renderbuffer
*rb
)
348 struct gl_renderbuffer_attachment
*att
;
350 _glthread_LOCK_MUTEX(fb
->Mutex
);
352 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
355 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
356 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
357 /* do stencil attachment here (depth already done above) */
358 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
360 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
364 _mesa_remove_attachment(ctx
, att
);
367 invalidate_framebuffer(fb
);
369 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
377 att_incomplete(const char *msg
)
380 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
391 fbo_incomplete(const char *msg
, int index
)
394 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
403 * Is the given base format a legal format for a color renderbuffer?
406 is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
408 switch (baseFormat
) {
413 case GL_LUMINANCE_ALPHA
:
416 return ctx
->Extensions
.ARB_framebuffer_object
;
419 return ctx
->Extensions
.ARB_texture_rg
;
427 * Is the given base format a legal format for a depth/stencil renderbuffer?
430 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
432 switch (baseFormat
) {
433 case GL_DEPTH_COMPONENT
:
434 case GL_DEPTH_STENCIL_EXT
:
443 * Test if an attachment point is complete and update its Complete field.
444 * \param format if GL_COLOR, this is a color attachment point,
445 * if GL_DEPTH, this is a depth component attachment point,
446 * if GL_STENCIL, this is a stencil component attachment point.
449 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
450 struct gl_renderbuffer_attachment
*att
)
452 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
454 /* assume complete */
455 att
->Complete
= GL_TRUE
;
457 /* Look for reasons why the attachment might be incomplete */
458 if (att
->Type
== GL_TEXTURE
) {
459 const struct gl_texture_object
*texObj
= att
->Texture
;
460 struct gl_texture_image
*texImage
;
464 att_incomplete("no texobj");
465 att
->Complete
= GL_FALSE
;
469 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
471 att_incomplete("no teximage");
472 att
->Complete
= GL_FALSE
;
475 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
476 att_incomplete("teximage width/height=0");
477 printf("texobj = %u\n", texObj
->Name
);
478 printf("level = %d\n", att
->TextureLevel
);
479 att
->Complete
= GL_FALSE
;
482 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
483 att_incomplete("bad z offset");
484 att
->Complete
= GL_FALSE
;
488 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
490 if (format
== GL_COLOR
) {
491 if (!is_legal_color_format(ctx
, baseFormat
)) {
492 att_incomplete("bad format");
493 att
->Complete
= GL_FALSE
;
496 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
497 att_incomplete("compressed internalformat");
498 att
->Complete
= GL_FALSE
;
502 else if (format
== GL_DEPTH
) {
503 if (baseFormat
== GL_DEPTH_COMPONENT
) {
506 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
507 ctx
->Extensions
.ARB_depth_texture
&&
508 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
512 att
->Complete
= GL_FALSE
;
513 att_incomplete("bad depth format");
518 ASSERT(format
== GL_STENCIL
);
519 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
520 ctx
->Extensions
.ARB_depth_texture
&&
521 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
525 /* no such thing as stencil-only textures */
526 att_incomplete("illegal stencil texture");
527 att
->Complete
= GL_FALSE
;
532 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
533 const GLenum baseFormat
=
534 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
536 ASSERT(att
->Renderbuffer
);
537 if (!att
->Renderbuffer
->InternalFormat
||
538 att
->Renderbuffer
->Width
< 1 ||
539 att
->Renderbuffer
->Height
< 1) {
540 att_incomplete("0x0 renderbuffer");
541 att
->Complete
= GL_FALSE
;
544 if (format
== GL_COLOR
) {
545 if (!is_legal_color_format(ctx
, baseFormat
)) {
546 att_incomplete("bad renderbuffer color format");
547 att
->Complete
= GL_FALSE
;
551 else if (format
== GL_DEPTH
) {
552 if (baseFormat
== GL_DEPTH_COMPONENT
) {
555 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
556 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
560 att_incomplete("bad renderbuffer depth format");
561 att
->Complete
= GL_FALSE
;
566 assert(format
== GL_STENCIL
);
567 if (baseFormat
== GL_STENCIL_INDEX
) {
570 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
571 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
575 att
->Complete
= GL_FALSE
;
576 att_incomplete("bad renderbuffer stencil format");
582 ASSERT(att
->Type
== GL_NONE
);
590 * Test if the given framebuffer object is complete and update its
591 * Status field with the results.
592 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
593 * driver to make hardware-specific validation/completeness checks.
594 * Also update the framebuffer's Width and Height fields if the
595 * framebuffer is complete.
598 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
599 struct gl_framebuffer
*fb
)
602 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
603 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
604 GLint numSamples
= -1;
608 assert(fb
->Name
!= 0);
614 /* Start at -2 to more easily loop over all attachment points.
619 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
620 struct gl_renderbuffer_attachment
*att
;
622 gl_format mesaFormat
;
625 * XXX for ARB_fbo, only check color buffers that are named by
626 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
629 /* check for attachment completeness
632 att
= &fb
->Attachment
[BUFFER_DEPTH
];
633 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
634 if (!att
->Complete
) {
635 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
636 fbo_incomplete("depth attachment incomplete", -1);
641 att
= &fb
->Attachment
[BUFFER_STENCIL
];
642 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
643 if (!att
->Complete
) {
644 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
645 fbo_incomplete("stencil attachment incomplete", -1);
650 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
651 test_attachment_completeness(ctx
, GL_COLOR
, att
);
652 if (!att
->Complete
) {
653 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
654 fbo_incomplete("color attachment incomplete", i
);
659 /* get width, height, format of the renderbuffer/texture
661 if (att
->Type
== GL_TEXTURE
) {
662 const struct gl_texture_image
*texImg
663 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
664 minWidth
= MIN2(minWidth
, texImg
->Width
);
665 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
666 minHeight
= MIN2(minHeight
, texImg
->Height
);
667 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
668 f
= texImg
->_BaseFormat
;
669 mesaFormat
= texImg
->TexFormat
;
671 if (!is_legal_color_format(ctx
, f
) &&
672 !is_legal_depth_format(ctx
, f
)) {
673 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
674 fbo_incomplete("texture attachment incomplete", -1);
678 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
679 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
680 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
681 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
682 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
683 f
= att
->Renderbuffer
->InternalFormat
;
684 mesaFormat
= att
->Renderbuffer
->Format
;
688 assert(att
->Type
== GL_NONE
);
692 if (numSamples
< 0) {
694 numSamples
= att
->Renderbuffer
->NumSamples
;
697 /* check if integer color */
698 fb
->_IntegerColor
= _mesa_is_format_integer_color(mesaFormat
);
700 /* Error-check width, height, format, samples
702 if (numImages
== 1) {
703 /* save format, num samples */
709 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
710 /* check that width, height, format are same */
711 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
712 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
713 fbo_incomplete("width or height mismatch", -1);
716 /* check that all color buffer have same format */
717 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
718 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
719 fbo_incomplete("format mismatch", -1);
723 if (att
->Renderbuffer
&&
724 att
->Renderbuffer
->NumSamples
!= numSamples
) {
725 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
726 fbo_incomplete("inconsistant number of samples", i
);
734 if (ctx
->API
== API_OPENGL
) {
735 /* Check that all DrawBuffers are present */
736 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
737 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
738 const struct gl_renderbuffer_attachment
*att
739 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
741 if (att
->Type
== GL_NONE
) {
742 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
743 fbo_incomplete("missing drawbuffer", j
);
749 /* Check that the ReadBuffer is present */
750 if (fb
->ColorReadBuffer
!= GL_NONE
) {
751 const struct gl_renderbuffer_attachment
*att
752 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
754 if (att
->Type
== GL_NONE
) {
755 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
756 fbo_incomplete("missing readbuffer", -1);
765 if (numImages
== 0) {
766 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
767 fbo_incomplete("no attachments", -1);
771 /* Provisionally set status = COMPLETE ... */
772 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
774 /* ... but the driver may say the FB is incomplete.
775 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
778 if (ctx
->Driver
.ValidateFramebuffer
) {
779 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
780 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
781 fbo_incomplete("driver marked FBO as incomplete", -1);
785 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
787 * Note that if ARB_framebuffer_object is supported and the attached
788 * renderbuffers/textures are different sizes, the framebuffer
789 * width/height will be set to the smallest width/height.
791 fb
->Width
= minWidth
;
792 fb
->Height
= minHeight
;
794 /* finally, update the visual info for the framebuffer */
795 _mesa_update_framebuffer_visual(fb
);
801 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
803 GET_CURRENT_CONTEXT(ctx
);
804 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
806 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
807 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
815 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
817 struct gl_renderbuffer
*newRb
;
818 GET_CURRENT_CONTEXT(ctx
);
820 ASSERT_OUTSIDE_BEGIN_END(ctx
);
822 if (target
!= GL_RENDERBUFFER_EXT
) {
823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
827 /* No need to flush here since the render buffer binding has no
828 * effect on rendering state.
832 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
833 if (newRb
== &DummyRenderbuffer
) {
834 /* ID was reserved, but no real renderbuffer object made yet */
837 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
838 /* All RB IDs must be Gen'd */
839 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
844 /* create new renderbuffer object */
845 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
847 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
850 ASSERT(newRb
->AllocStorage
);
851 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
852 newRb
->RefCount
= 1; /* referenced by hash table */
859 ASSERT(newRb
!= &DummyRenderbuffer
);
861 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
866 * If the given renderbuffer is anywhere attached to the framebuffer, detach
868 * This is used when a renderbuffer object is deleted.
869 * The spec calls for unbinding.
872 detach_renderbuffer(struct gl_context
*ctx
,
873 struct gl_framebuffer
*fb
,
874 struct gl_renderbuffer
*rb
)
877 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
878 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
879 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
882 invalidate_framebuffer(fb
);
887 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
890 GET_CURRENT_CONTEXT(ctx
);
892 ASSERT_OUTSIDE_BEGIN_END(ctx
);
893 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
895 for (i
= 0; i
< n
; i
++) {
896 if (renderbuffers
[i
] > 0) {
897 struct gl_renderbuffer
*rb
;
898 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
900 /* check if deleting currently bound renderbuffer object */
901 if (rb
== ctx
->CurrentRenderbuffer
) {
903 ASSERT(rb
->RefCount
>= 2);
904 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
907 if (ctx
->DrawBuffer
->Name
) {
908 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
910 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
911 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
914 /* Remove from hash table immediately, to free the ID.
915 * But the object will not be freed until it's no longer
916 * referenced anywhere else.
918 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
920 if (rb
!= &DummyRenderbuffer
) {
921 /* no longer referenced by hash table */
922 _mesa_reference_renderbuffer(&rb
, NULL
);
931 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
933 GET_CURRENT_CONTEXT(ctx
);
937 ASSERT_OUTSIDE_BEGIN_END(ctx
);
940 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
947 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
949 for (i
= 0; i
< n
; i
++) {
950 GLuint name
= first
+ i
;
951 renderbuffers
[i
] = name
;
952 /* insert dummy placeholder into hash table */
953 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
954 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
955 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
961 * Given an internal format token for a render buffer, return the
962 * corresponding base format.
963 * This is very similar to _mesa_base_tex_format() but the set of valid
964 * internal formats is somewhat different.
966 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
967 * GL_DEPTH_STENCIL_EXT or zero if error.
969 * XXX in the future when we support red-only and red-green formats
970 * we'll also return GL_RED and GL_RG.
973 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
975 switch (internalFormat
) {
999 case GL_RGBA16_SNORM
:
1001 case GL_STENCIL_INDEX
:
1002 case GL_STENCIL_INDEX1_EXT
:
1003 case GL_STENCIL_INDEX4_EXT
:
1004 case GL_STENCIL_INDEX8_EXT
:
1005 case GL_STENCIL_INDEX16_EXT
:
1006 return GL_STENCIL_INDEX
;
1007 case GL_DEPTH_COMPONENT
:
1008 case GL_DEPTH_COMPONENT16
:
1009 case GL_DEPTH_COMPONENT24
:
1010 case GL_DEPTH_COMPONENT32
:
1011 return GL_DEPTH_COMPONENT
;
1012 case GL_DEPTH_STENCIL_EXT
:
1013 case GL_DEPTH24_STENCIL8_EXT
:
1014 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
1015 return GL_DEPTH_STENCIL_EXT
;
1018 /* XXX add floating point formats eventually */
1025 /** sentinal value, see below */
1026 #define NO_SAMPLES 1000
1030 * Helper function used by _mesa_RenderbufferStorageEXT() and
1031 * _mesa_RenderbufferStorageMultisample().
1032 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1035 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1036 GLsizei width
, GLsizei height
, GLsizei samples
)
1038 const char *func
= samples
== NO_SAMPLES
?
1039 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1040 struct gl_renderbuffer
*rb
;
1042 GET_CURRENT_CONTEXT(ctx
);
1044 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1046 if (target
!= GL_RENDERBUFFER_EXT
) {
1047 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1051 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1052 if (baseFormat
== 0) {
1053 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1057 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1058 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1062 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1063 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1067 if (samples
== NO_SAMPLES
) {
1068 /* NumSamples == 0 indicates non-multisampling */
1071 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1072 /* note: driver may choose to use more samples than what's requested */
1073 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1077 rb
= ctx
->CurrentRenderbuffer
;
1079 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1083 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1085 if (rb
->InternalFormat
== internalFormat
&&
1086 rb
->Width
== (GLuint
) width
&&
1087 rb
->Height
== (GLuint
) height
) {
1088 /* no change in allocation needed */
1092 /* These MUST get set by the AllocStorage func */
1093 rb
->Format
= MESA_FORMAT_NONE
;
1094 rb
->NumSamples
= samples
;
1096 /* Now allocate the storage */
1097 ASSERT(rb
->AllocStorage
);
1098 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1099 /* No error - check/set fields now */
1100 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1101 assert(rb
->Width
== (GLuint
) width
);
1102 assert(rb
->Height
== (GLuint
) height
);
1103 rb
->InternalFormat
= internalFormat
;
1104 rb
->_BaseFormat
= baseFormat
;
1105 assert(rb
->_BaseFormat
!= 0);
1108 /* Probably ran out of memory - clear the fields */
1111 rb
->Format
= MESA_FORMAT_NONE
;
1112 rb
->InternalFormat
= GL_NONE
;
1113 rb
->_BaseFormat
= GL_NONE
;
1118 test_framebuffer_completeness(ctx, fb);
1120 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1126 #if FEATURE_OES_EGL_image
1128 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1130 struct gl_renderbuffer
*rb
;
1131 GET_CURRENT_CONTEXT(ctx
);
1132 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1134 if (!ctx
->Extensions
.OES_EGL_image
) {
1135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1136 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1140 if (target
!= GL_RENDERBUFFER
) {
1141 _mesa_error(ctx
, GL_INVALID_ENUM
,
1142 "EGLImageTargetRenderbufferStorageOES");
1146 rb
= ctx
->CurrentRenderbuffer
;
1148 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1149 "EGLImageTargetRenderbufferStorageOES");
1153 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1155 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1161 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1162 * _mesa_GetFramebufferAttachmentParameterivEXT()
1163 * We have to be careful to respect the base format. For example, if a
1164 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1165 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1166 * we need to return zero.
1169 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1172 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1173 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1174 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1175 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1176 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1177 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1178 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1179 return _mesa_get_format_bits(format
, pname
);
1182 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1183 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1184 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1185 return _mesa_get_format_bits(format
, pname
);
1188 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1189 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1190 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1191 return _mesa_get_format_bits(format
, pname
);
1194 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1195 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1196 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1197 return _mesa_get_format_bits(format
, pname
);
1208 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1209 GLsizei width
, GLsizei height
)
1211 /* GL_ARB_fbo says calling this function is equivalent to calling
1212 * glRenderbufferStorageMultisample() with samples=0. We pass in
1213 * a token value here just for error reporting purposes.
1215 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1220 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1221 GLenum internalFormat
,
1222 GLsizei width
, GLsizei height
)
1224 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1229 * OpenGL ES version of glRenderBufferStorage.
1232 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1233 GLsizei width
, GLsizei height
)
1235 switch (internalFormat
) {
1237 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1238 /* choose a closest format */
1239 internalFormat
= GL_RGB5
;
1245 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1250 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1252 struct gl_renderbuffer
*rb
;
1253 GET_CURRENT_CONTEXT(ctx
);
1255 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1257 if (target
!= GL_RENDERBUFFER_EXT
) {
1258 _mesa_error(ctx
, GL_INVALID_ENUM
,
1259 "glGetRenderbufferParameterivEXT(target)");
1263 rb
= ctx
->CurrentRenderbuffer
;
1265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1266 "glGetRenderbufferParameterivEXT");
1270 /* No need to flush here since we're just quering state which is
1271 * not effected by rendering.
1275 case GL_RENDERBUFFER_WIDTH_EXT
:
1276 *params
= rb
->Width
;
1278 case GL_RENDERBUFFER_HEIGHT_EXT
:
1279 *params
= rb
->Height
;
1281 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1282 *params
= rb
->InternalFormat
;
1284 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1285 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1286 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1287 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1288 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1289 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1290 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1292 case GL_RENDERBUFFER_SAMPLES
:
1293 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1294 *params
= rb
->NumSamples
;
1299 _mesa_error(ctx
, GL_INVALID_ENUM
,
1300 "glGetRenderbufferParameterivEXT(target)");
1306 GLboolean GLAPIENTRY
1307 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1309 GET_CURRENT_CONTEXT(ctx
);
1310 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1312 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1313 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1321 * Check if any of the attachments of the given framebuffer are textures
1322 * (render to texture). Call ctx->Driver.RenderTexture() for such
1326 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1329 ASSERT(ctx
->Driver
.RenderTexture
);
1332 return; /* can't render to texture with winsys framebuffers */
1334 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1335 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1336 struct gl_texture_object
*texObj
= att
->Texture
;
1338 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1339 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1346 * Examine all the framebuffer's attachments to see if any are textures.
1347 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1348 * notify the device driver that the texture image may have changed.
1351 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1354 return; /* can't render to texture with winsys framebuffers */
1356 if (ctx
->Driver
.FinishRenderTexture
) {
1358 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1359 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1360 if (att
->Texture
&& att
->Renderbuffer
) {
1361 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1369 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1371 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1372 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1373 GLboolean bindReadBuf
, bindDrawBuf
;
1374 GET_CURRENT_CONTEXT(ctx
);
1377 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1378 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1379 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1383 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1385 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1386 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1387 "glBindFramebufferEXT(unsupported)");
1392 #if FEATURE_EXT_framebuffer_blit
1393 case GL_DRAW_FRAMEBUFFER_EXT
:
1394 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1395 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1398 bindDrawBuf
= GL_TRUE
;
1399 bindReadBuf
= GL_FALSE
;
1401 case GL_READ_FRAMEBUFFER_EXT
:
1402 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1403 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1406 bindDrawBuf
= GL_FALSE
;
1407 bindReadBuf
= GL_TRUE
;
1410 case GL_FRAMEBUFFER_EXT
:
1411 bindDrawBuf
= GL_TRUE
;
1412 bindReadBuf
= GL_TRUE
;
1415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1420 /* Binding a user-created framebuffer object */
1421 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1422 if (newDrawFb
== &DummyFramebuffer
) {
1423 /* ID was reserved, but no real framebuffer object made yet */
1426 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1427 /* All FBO IDs must be Gen'd */
1428 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1433 /* create new framebuffer object */
1434 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1436 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1439 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1441 newReadFb
= newDrawFb
;
1444 /* Binding the window system framebuffer (which was originally set
1445 * with MakeCurrent).
1447 newDrawFb
= ctx
->WinSysDrawBuffer
;
1448 newReadFb
= ctx
->WinSysReadBuffer
;
1452 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1454 /* save pointers to current/old framebuffers */
1455 oldDrawFb
= ctx
->DrawBuffer
;
1456 oldReadFb
= ctx
->ReadBuffer
;
1458 /* check if really changing bindings */
1459 if (oldDrawFb
== newDrawFb
)
1460 bindDrawBuf
= GL_FALSE
;
1461 if (oldReadFb
== newReadFb
)
1462 bindReadBuf
= GL_FALSE
;
1465 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1467 * We also check if we're beginning and/or ending render-to-texture.
1468 * When a framebuffer with texture attachments is unbound, call
1469 * ctx->Driver.FinishRenderTexture().
1470 * When a framebuffer with texture attachments is bound, call
1471 * ctx->Driver.RenderTexture().
1473 * Note that if the ReadBuffer has texture attachments we don't consider
1474 * that a render-to-texture case.
1477 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1479 /* check if old readbuffer was render-to-texture */
1480 check_end_texture_render(ctx
, oldReadFb
);
1482 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1486 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1488 /* check if old read/draw buffers were render-to-texture */
1490 check_end_texture_render(ctx
, oldReadFb
);
1492 if (oldDrawFb
!= oldReadFb
)
1493 check_end_texture_render(ctx
, oldDrawFb
);
1495 /* check if newly bound framebuffer has any texture attachments */
1496 check_begin_texture_render(ctx
, newDrawFb
);
1498 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1501 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1502 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1508 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1511 GET_CURRENT_CONTEXT(ctx
);
1513 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1514 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1516 for (i
= 0; i
< n
; i
++) {
1517 if (framebuffers
[i
] > 0) {
1518 struct gl_framebuffer
*fb
;
1519 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1521 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1523 /* check if deleting currently bound framebuffer object */
1524 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1525 /* separate draw/read binding points */
1526 if (fb
== ctx
->DrawBuffer
) {
1528 ASSERT(fb
->RefCount
>= 2);
1529 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1531 if (fb
== ctx
->ReadBuffer
) {
1533 ASSERT(fb
->RefCount
>= 2);
1534 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1538 /* only one binding point for read/draw buffers */
1539 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1541 ASSERT(fb
->RefCount
>= 2);
1542 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1546 /* remove from hash table immediately, to free the ID */
1547 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1549 if (fb
!= &DummyFramebuffer
) {
1550 /* But the object will not be freed until it's no longer
1551 * bound in any context.
1553 _mesa_reference_framebuffer(&fb
, NULL
);
1562 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1564 GET_CURRENT_CONTEXT(ctx
);
1568 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1578 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1580 for (i
= 0; i
< n
; i
++) {
1581 GLuint name
= first
+ i
;
1582 framebuffers
[i
] = name
;
1583 /* insert dummy placeholder into hash table */
1584 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1585 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1586 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1593 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1595 struct gl_framebuffer
*buffer
;
1596 GET_CURRENT_CONTEXT(ctx
);
1598 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1601 #if FEATURE_EXT_framebuffer_blit
1602 case GL_DRAW_FRAMEBUFFER_EXT
:
1603 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1604 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1607 buffer
= ctx
->DrawBuffer
;
1609 case GL_READ_FRAMEBUFFER_EXT
:
1610 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1611 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1614 buffer
= ctx
->ReadBuffer
;
1617 case GL_FRAMEBUFFER_EXT
:
1618 buffer
= ctx
->DrawBuffer
;
1621 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1622 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1625 if (buffer
->Name
== 0) {
1626 /* The window system / default framebuffer is always complete */
1627 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1630 /* No need to flush here */
1632 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1633 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1636 return buffer
->_Status
;
1642 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1645 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1646 GLenum attachment
, GLenum textarget
, GLuint texture
,
1647 GLint level
, GLint zoffset
)
1649 struct gl_renderbuffer_attachment
*att
;
1650 struct gl_texture_object
*texObj
= NULL
;
1651 struct gl_framebuffer
*fb
;
1652 GLboolean error
= GL_FALSE
;
1654 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1657 case GL_READ_FRAMEBUFFER_EXT
:
1658 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1659 fb
= ctx
->ReadBuffer
;
1661 case GL_DRAW_FRAMEBUFFER_EXT
:
1662 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1664 case GL_FRAMEBUFFER_EXT
:
1665 fb
= ctx
->DrawBuffer
;
1672 _mesa_error(ctx
, GL_INVALID_ENUM
,
1673 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1679 /* check framebuffer binding */
1680 if (fb
->Name
== 0) {
1681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1682 "glFramebufferTexture%sEXT", caller
);
1687 /* The textarget, level, and zoffset parameters are only validated if
1688 * texture is non-zero.
1691 GLboolean err
= GL_TRUE
;
1693 texObj
= _mesa_lookup_texture(ctx
, texture
);
1694 if (texObj
!= NULL
) {
1695 if (textarget
== 0) {
1696 /* XXX what's the purpose of this? */
1697 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1698 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1699 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1702 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1703 ? !IS_CUBE_FACE(textarget
)
1704 : (texObj
->Target
!= textarget
);
1708 /* can't render to a non-existant texture */
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "glFramebufferTexture%sEXT(non existant texture)",
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "glFramebufferTexture%sEXT(texture target mismatch)",
1722 if (texObj
->Target
== GL_TEXTURE_3D
) {
1723 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1724 if (zoffset
< 0 || zoffset
>= maxSize
) {
1725 _mesa_error(ctx
, GL_INVALID_VALUE
,
1726 "glFramebufferTexture%sEXT(zoffset)", caller
);
1730 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1731 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1732 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1733 _mesa_error(ctx
, GL_INVALID_VALUE
,
1734 "glFramebufferTexture%sEXT(layer)", caller
);
1740 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1741 _mesa_error(ctx
, GL_INVALID_VALUE
,
1742 "glFramebufferTexture%sEXT(level)", caller
);
1747 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1749 _mesa_error(ctx
, GL_INVALID_ENUM
,
1750 "glFramebufferTexture%sEXT(attachment)", caller
);
1754 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1756 _glthread_LOCK_MUTEX(fb
->Mutex
);
1758 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1760 /* Set the render-to-texture flag. We'll check this flag in
1761 * glTexImage() and friends to determine if we need to revalidate
1762 * any FBOs that might be rendering into this texture.
1763 * This flag never gets cleared since it's non-trivial to determine
1764 * when all FBOs might be done rendering to this texture. That's OK
1765 * though since it's uncommon to render to a texture then repeatedly
1766 * call glTexImage() to change images in the texture.
1768 texObj
->_RenderToTexture
= GL_TRUE
;
1771 _mesa_remove_attachment(ctx
, att
);
1774 invalidate_framebuffer(fb
);
1776 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1782 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1783 GLenum textarget
, GLuint texture
, GLint level
)
1785 GET_CURRENT_CONTEXT(ctx
);
1787 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1788 _mesa_error(ctx
, GL_INVALID_ENUM
,
1789 "glFramebufferTexture1DEXT(textarget)");
1793 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1799 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1800 GLenum textarget
, GLuint texture
, GLint level
)
1802 GET_CURRENT_CONTEXT(ctx
);
1804 if ((texture
!= 0) &&
1805 (textarget
!= GL_TEXTURE_2D
) &&
1806 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1807 (!IS_CUBE_FACE(textarget
))) {
1808 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1809 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1813 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1819 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1820 GLenum textarget
, GLuint texture
,
1821 GLint level
, GLint zoffset
)
1823 GET_CURRENT_CONTEXT(ctx
);
1825 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1826 _mesa_error(ctx
, GL_INVALID_ENUM
,
1827 "glFramebufferTexture3DEXT(textarget)");
1831 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1837 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1838 GLuint texture
, GLint level
, GLint layer
)
1840 GET_CURRENT_CONTEXT(ctx
);
1842 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1848 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1849 GLenum renderbufferTarget
,
1850 GLuint renderbuffer
)
1852 struct gl_renderbuffer_attachment
*att
;
1853 struct gl_framebuffer
*fb
;
1854 struct gl_renderbuffer
*rb
;
1855 GET_CURRENT_CONTEXT(ctx
);
1857 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1860 #if FEATURE_EXT_framebuffer_blit
1861 case GL_DRAW_FRAMEBUFFER_EXT
:
1862 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1863 _mesa_error(ctx
, GL_INVALID_ENUM
,
1864 "glFramebufferRenderbufferEXT(target)");
1867 fb
= ctx
->DrawBuffer
;
1869 case GL_READ_FRAMEBUFFER_EXT
:
1870 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1871 _mesa_error(ctx
, GL_INVALID_ENUM
,
1872 "glFramebufferRenderbufferEXT(target)");
1875 fb
= ctx
->ReadBuffer
;
1878 case GL_FRAMEBUFFER_EXT
:
1879 fb
= ctx
->DrawBuffer
;
1882 _mesa_error(ctx
, GL_INVALID_ENUM
,
1883 "glFramebufferRenderbufferEXT(target)");
1887 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1888 _mesa_error(ctx
, GL_INVALID_ENUM
,
1889 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1893 if (fb
->Name
== 0) {
1894 /* Can't attach new renderbuffers to a window system framebuffer */
1895 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1899 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1901 _mesa_error(ctx
, GL_INVALID_ENUM
,
1902 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1903 _mesa_lookup_enum_by_nr(attachment
));
1908 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1910 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1911 "glFramebufferRenderbufferEXT(non-existant"
1912 " renderbuffer %u)", renderbuffer
);
1917 /* remove renderbuffer attachment */
1921 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1922 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1923 /* make sure the renderbuffer is a depth/stencil format */
1924 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1925 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1926 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1927 "glFramebufferRenderbufferEXT(renderbuffer"
1928 " is not DEPTH_STENCIL format)");
1934 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1936 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1937 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1939 /* Some subsequent GL commands may depend on the framebuffer's visual
1940 * after the binding is updated. Update visual info now.
1942 _mesa_update_framebuffer_visual(fb
);
1947 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1948 GLenum pname
, GLint
*params
)
1950 const struct gl_renderbuffer_attachment
*att
;
1951 struct gl_framebuffer
*buffer
;
1952 GET_CURRENT_CONTEXT(ctx
);
1954 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1957 #if FEATURE_EXT_framebuffer_blit
1958 case GL_DRAW_FRAMEBUFFER_EXT
:
1959 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1960 _mesa_error(ctx
, GL_INVALID_ENUM
,
1961 "glGetFramebufferAttachmentParameterivEXT(target)");
1964 buffer
= ctx
->DrawBuffer
;
1966 case GL_READ_FRAMEBUFFER_EXT
:
1967 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1968 _mesa_error(ctx
, GL_INVALID_ENUM
,
1969 "glGetFramebufferAttachmentParameterivEXT(target)");
1972 buffer
= ctx
->ReadBuffer
;
1975 case GL_FRAMEBUFFER_EXT
:
1976 buffer
= ctx
->DrawBuffer
;
1979 _mesa_error(ctx
, GL_INVALID_ENUM
,
1980 "glGetFramebufferAttachmentParameterivEXT(target)");
1984 if (buffer
->Name
== 0) {
1985 /* the default / window-system FBO */
1986 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
1989 /* user-created framebuffer FBO */
1990 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1994 _mesa_error(ctx
, GL_INVALID_ENUM
,
1995 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1999 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2000 /* the depth and stencil attachments must point to the same buffer */
2001 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2002 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2003 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2004 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2006 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2007 " attachments differ)");
2012 /* No need to flush here */
2015 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2016 *params
= buffer
->Name
== 0 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2018 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2019 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2020 *params
= att
->Renderbuffer
->Name
;
2022 else if (att
->Type
== GL_TEXTURE
) {
2023 *params
= att
->Texture
->Name
;
2026 assert(att
->Type
== GL_NONE
);
2030 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2031 if (att
->Type
== GL_TEXTURE
) {
2032 *params
= att
->TextureLevel
;
2035 _mesa_error(ctx
, GL_INVALID_ENUM
,
2036 "glGetFramebufferAttachmentParameterivEXT(pname)");
2039 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2040 if (att
->Type
== GL_TEXTURE
) {
2041 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2042 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2049 _mesa_error(ctx
, GL_INVALID_ENUM
,
2050 "glGetFramebufferAttachmentParameterivEXT(pname)");
2053 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2054 if (att
->Type
== GL_TEXTURE
) {
2055 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2056 *params
= att
->Zoffset
;
2063 _mesa_error(ctx
, GL_INVALID_ENUM
,
2064 "glGetFramebufferAttachmentParameterivEXT(pname)");
2067 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2068 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2069 _mesa_error(ctx
, GL_INVALID_ENUM
,
2070 "glGetFramebufferAttachmentParameterivEXT(pname)");
2073 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2076 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2077 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2078 _mesa_error(ctx
, GL_INVALID_ENUM
,
2079 "glGetFramebufferAttachmentParameterivEXT(pname)");
2083 gl_format format
= att
->Renderbuffer
->Format
;
2084 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2089 *params
= _mesa_get_format_datatype(format
);
2093 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2094 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2095 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2096 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2097 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2098 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2099 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2100 _mesa_error(ctx
, GL_INVALID_ENUM
,
2101 "glGetFramebufferAttachmentParameterivEXT(pname)");
2103 else if (att
->Texture
) {
2104 const struct gl_texture_image
*texImage
=
2105 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2108 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2109 texImage
->TexFormat
);
2115 else if (att
->Renderbuffer
) {
2116 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2117 att
->Renderbuffer
->Format
);
2124 _mesa_error(ctx
, GL_INVALID_ENUM
,
2125 "glGetFramebufferAttachmentParameterivEXT(pname)");
2132 _mesa_GenerateMipmapEXT(GLenum target
)
2134 struct gl_texture_object
*texObj
;
2135 GET_CURRENT_CONTEXT(ctx
);
2137 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2138 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2144 case GL_TEXTURE_CUBE_MAP
:
2145 /* OK, legal value */
2148 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2149 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2153 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2155 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2160 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2161 !_mesa_cube_complete(texObj
)) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glGenerateMipmap(incomplete cube map)");
2167 _mesa_lock_texture(ctx
, texObj
);
2168 if (target
== GL_TEXTURE_CUBE_MAP
) {
2170 for (face
= 0; face
< 6; face
++)
2171 ctx
->Driver
.GenerateMipmap(ctx
,
2172 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2176 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2178 _mesa_unlock_texture(ctx
, texObj
);
2182 #if FEATURE_EXT_framebuffer_blit
2184 static const struct gl_renderbuffer_attachment
*
2185 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2188 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2189 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2190 return &fb
->Attachment
[i
];
2198 * Blit rectangular region, optionally from one framebuffer to another.
2200 * Note, if the src buffer is multisampled and the dest is not, this is
2201 * when the samples must be resolved to a single color.
2204 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2205 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2206 GLbitfield mask
, GLenum filter
)
2208 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2209 GL_DEPTH_BUFFER_BIT
|
2210 GL_STENCIL_BUFFER_BIT
);
2211 const struct gl_framebuffer
*readFb
, *drawFb
;
2212 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2213 GET_CURRENT_CONTEXT(ctx
);
2215 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2216 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2218 if (ctx
->NewState
) {
2219 _mesa_update_state(ctx
);
2222 readFb
= ctx
->ReadBuffer
;
2223 drawFb
= ctx
->DrawBuffer
;
2225 if (!readFb
|| !drawFb
) {
2226 /* This will normally never happen but someday we may want to
2227 * support MakeCurrent() with no drawables.
2232 /* check for complete framebuffers */
2233 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2234 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2235 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2236 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2240 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2241 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2245 if (mask
& ~legalMaskBits
) {
2246 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2250 /* depth/stencil must be blitted with nearest filtering */
2251 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2252 && filter
!= GL_NEAREST
) {
2253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2254 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2258 /* get color read/draw renderbuffers */
2259 if (mask
& GL_COLOR_BUFFER_BIT
) {
2260 colorReadRb
= readFb
->_ColorReadBuffer
;
2261 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2264 colorReadRb
= colorDrawRb
= NULL
;
2267 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2268 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2269 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2272 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2273 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2275 "glBlitFramebufferEXT(stencil buffer size mismatch");
2280 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2281 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2282 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2285 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2286 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2287 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2288 "glBlitFramebufferEXT(depth buffer size mismatch");
2293 if (readFb
->Visual
.samples
> 0 &&
2294 drawFb
->Visual
.samples
> 0 &&
2295 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2296 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2297 "glBlitFramebufferEXT(mismatched samples");
2301 /* extra checks for multisample copies... */
2302 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2303 /* src and dest region sizes must be the same */
2304 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2305 srcY1
- srcY0
!= dstY1
- dstY0
) {
2306 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2307 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2311 /* color formats must match */
2314 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2315 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2316 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2321 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2322 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2328 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2330 srcX0
, srcY0
, srcX1
, srcY1
,
2331 dstX0
, dstY0
, dstX1
, dstY1
,
2334 const struct gl_renderbuffer_attachment
*att
;
2336 att
= find_attachment(readFb
, colorReadRb
);
2337 printf(" Src FBO %u RB %u (%dx%d) ",
2338 readFb
->Name
, colorReadRb
->Name
,
2339 colorReadRb
->Width
, colorReadRb
->Height
);
2340 if (att
&& att
->Texture
) {
2341 printf("Tex %u tgt 0x%x level %u face %u",
2343 att
->Texture
->Target
,
2349 att
= find_attachment(drawFb
, colorDrawRb
);
2350 printf(" Dst FBO %u RB %u (%dx%d) ",
2351 drawFb
->Name
, colorDrawRb
->Name
,
2352 colorDrawRb
->Width
, colorDrawRb
->Height
);
2353 if (att
&& att
->Texture
) {
2354 printf("Tex %u tgt 0x%x level %u face %u",
2356 att
->Texture
->Target
,
2364 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2365 ctx
->Driver
.BlitFramebuffer(ctx
,
2366 srcX0
, srcY0
, srcX1
, srcY1
,
2367 dstX0
, dstY0
, dstX1
, dstY1
,
2370 #endif /* FEATURE_EXT_framebuffer_blit */
2372 #if FEATURE_ARB_geometry_shader4
2374 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2375 GLuint texture
, GLint level
)
2377 GET_CURRENT_CONTEXT(ctx
);
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2379 "glFramebufferTextureARB "
2380 "not implemented!");
2384 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2385 GLuint texture
, GLint level
, GLenum face
)
2387 GET_CURRENT_CONTEXT(ctx
);
2388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2389 "glFramebufferTextureFaceARB "
2390 "not implemented!");
2392 #endif /* FEATURE_ARB_geometry_shader4 */