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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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(GLcontext
*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 GLcontext
*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 att_incomplete("bad format");
456 att
->Complete
= GL_FALSE
;
459 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
460 att_incomplete("compressed internalformat");
461 att
->Complete
= GL_FALSE
;
465 else if (format
== GL_DEPTH
) {
466 if (baseFormat
== GL_DEPTH_COMPONENT
) {
469 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
470 ctx
->Extensions
.ARB_depth_texture
&&
471 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
475 att
->Complete
= GL_FALSE
;
476 att_incomplete("bad depth format");
481 ASSERT(format
== GL_STENCIL
);
482 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
483 ctx
->Extensions
.ARB_depth_texture
&&
484 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
488 /* no such thing as stencil-only textures */
489 att_incomplete("illegal stencil texture");
490 att
->Complete
= GL_FALSE
;
495 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
496 const GLenum baseFormat
=
497 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
499 ASSERT(att
->Renderbuffer
);
500 if (!att
->Renderbuffer
->InternalFormat
||
501 att
->Renderbuffer
->Width
< 1 ||
502 att
->Renderbuffer
->Height
< 1) {
503 att_incomplete("0x0 renderbuffer");
504 att
->Complete
= GL_FALSE
;
507 if (format
== GL_COLOR
) {
508 if (baseFormat
!= GL_RGB
&&
509 baseFormat
!= GL_RGBA
) {
510 att_incomplete("bad renderbuffer color format");
511 att
->Complete
= GL_FALSE
;
515 else if (format
== GL_DEPTH
) {
516 if (baseFormat
== GL_DEPTH_COMPONENT
) {
519 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
520 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
524 att_incomplete("bad renderbuffer depth format");
525 att
->Complete
= GL_FALSE
;
530 assert(format
== GL_STENCIL
);
531 if (baseFormat
== GL_STENCIL_INDEX
) {
534 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
535 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
539 att
->Complete
= GL_FALSE
;
540 att_incomplete("bad renderbuffer stencil format");
546 ASSERT(att
->Type
== GL_NONE
);
554 * Test if the given framebuffer object is complete and update its
555 * Status field with the results.
556 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
557 * driver to make hardware-specific validation/completeness checks.
558 * Also update the framebuffer's Width and Height fields if the
559 * framebuffer is complete.
562 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
565 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
566 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
567 GLint numSamples
= -1;
571 assert(fb
->Name
!= 0);
577 /* Start at -2 to more easily loop over all attachment points.
582 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
583 struct gl_renderbuffer_attachment
*att
;
587 * XXX for ARB_fbo, only check color buffers that are named by
588 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
591 /* check for attachment completeness
594 att
= &fb
->Attachment
[BUFFER_DEPTH
];
595 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
596 if (!att
->Complete
) {
597 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
598 fbo_incomplete("depth attachment incomplete", -1);
603 att
= &fb
->Attachment
[BUFFER_STENCIL
];
604 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
605 if (!att
->Complete
) {
606 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
607 fbo_incomplete("stencil attachment incomplete", -1);
612 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
613 test_attachment_completeness(ctx
, GL_COLOR
, att
);
614 if (!att
->Complete
) {
615 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
616 fbo_incomplete("color attachment incomplete", i
);
621 /* get width, height, format of the renderbuffer/texture
623 if (att
->Type
== GL_TEXTURE
) {
624 const struct gl_texture_image
*texImg
625 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
626 minWidth
= MIN2(minWidth
, texImg
->Width
);
627 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
628 minHeight
= MIN2(minHeight
, texImg
->Height
);
629 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
630 f
= texImg
->_BaseFormat
;
632 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
633 && f
!= GL_DEPTH_STENCIL_EXT
634 && (!ctx
->Extensions
.ARB_framebuffer_object
|| f
!= GL_ALPHA
)) {
635 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
636 fbo_incomplete("texture attachment incomplete", -1);
640 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
641 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
642 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
643 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
644 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
645 f
= att
->Renderbuffer
->InternalFormat
;
649 assert(att
->Type
== GL_NONE
);
653 if (numSamples
< 0) {
655 numSamples
= att
->Renderbuffer
->NumSamples
;
658 /* Error-check width, height, format, samples
660 if (numImages
== 1) {
661 /* save format, num samples */
667 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
668 /* check that width, height, format are same */
669 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
670 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
671 fbo_incomplete("width or height mismatch", -1);
674 /* check that all color buffer have same format */
675 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
676 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
677 fbo_incomplete("format mismatch", -1);
681 if (att
->Renderbuffer
&&
682 att
->Renderbuffer
->NumSamples
!= numSamples
) {
683 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
684 fbo_incomplete("inconsistant number of samples", i
);
692 if (ctx
->API
== API_OPENGL
) {
693 /* Check that all DrawBuffers are present */
694 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
695 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
696 const struct gl_renderbuffer_attachment
*att
697 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
699 if (att
->Type
== GL_NONE
) {
700 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
701 fbo_incomplete("missing drawbuffer", j
);
707 /* Check that the ReadBuffer is present */
708 if (fb
->ColorReadBuffer
!= GL_NONE
) {
709 const struct gl_renderbuffer_attachment
*att
710 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
712 if (att
->Type
== GL_NONE
) {
713 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
714 fbo_incomplete("missing readbuffer", -1);
723 if (numImages
== 0) {
724 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
725 fbo_incomplete("no attachments", -1);
729 /* Provisionally set status = COMPLETE ... */
730 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
732 /* ... but the driver may say the FB is incomplete.
733 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
736 if (ctx
->Driver
.ValidateFramebuffer
) {
737 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
738 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
739 fbo_incomplete("driver marked FBO as incomplete", -1);
743 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
745 * Note that if ARB_framebuffer_object is supported and the attached
746 * renderbuffers/textures are different sizes, the framebuffer
747 * width/height will be set to the smallest width/height.
749 fb
->Width
= minWidth
;
750 fb
->Height
= minHeight
;
752 /* finally, update the visual info for the framebuffer */
753 _mesa_update_framebuffer_visual(fb
);
759 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
761 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
764 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
765 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
773 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
775 struct gl_renderbuffer
*newRb
;
776 GET_CURRENT_CONTEXT(ctx
);
778 ASSERT_OUTSIDE_BEGIN_END(ctx
);
780 if (target
!= GL_RENDERBUFFER_EXT
) {
781 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
785 /* No need to flush here since the render buffer binding has no
786 * effect on rendering state.
790 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
791 if (newRb
== &DummyRenderbuffer
) {
792 /* ID was reserved, but no real renderbuffer object made yet */
795 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
796 /* All RB IDs must be Gen'd */
797 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
802 /* create new renderbuffer object */
803 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
805 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
808 ASSERT(newRb
->AllocStorage
);
809 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
810 newRb
->RefCount
= 1; /* referenced by hash table */
817 ASSERT(newRb
!= &DummyRenderbuffer
);
819 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
824 * If the given renderbuffer is anywhere attached to the framebuffer, detach
826 * This is used when a renderbuffer object is deleted.
827 * The spec calls for unbinding.
830 detach_renderbuffer(GLcontext
*ctx
,
831 struct gl_framebuffer
*fb
,
832 struct gl_renderbuffer
*rb
)
835 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
836 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
837 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
840 invalidate_framebuffer(fb
);
845 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
848 GET_CURRENT_CONTEXT(ctx
);
850 ASSERT_OUTSIDE_BEGIN_END(ctx
);
851 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
853 for (i
= 0; i
< n
; i
++) {
854 if (renderbuffers
[i
] > 0) {
855 struct gl_renderbuffer
*rb
;
856 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
858 /* check if deleting currently bound renderbuffer object */
859 if (rb
== ctx
->CurrentRenderbuffer
) {
861 ASSERT(rb
->RefCount
>= 2);
862 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
865 if (ctx
->DrawBuffer
->Name
) {
866 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
868 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
869 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
872 /* Remove from hash table immediately, to free the ID.
873 * But the object will not be freed until it's no longer
874 * referenced anywhere else.
876 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
878 if (rb
!= &DummyRenderbuffer
) {
879 /* no longer referenced by hash table */
880 _mesa_reference_renderbuffer(&rb
, NULL
);
889 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
891 GET_CURRENT_CONTEXT(ctx
);
895 ASSERT_OUTSIDE_BEGIN_END(ctx
);
898 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
905 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
907 for (i
= 0; i
< n
; i
++) {
908 GLuint name
= first
+ i
;
909 renderbuffers
[i
] = name
;
910 /* insert dummy placeholder into hash table */
911 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
912 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
913 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
919 * Given an internal format token for a render buffer, return the
920 * corresponding base format.
921 * This is very similar to _mesa_base_tex_format() but the set of valid
922 * internal formats is somewhat different.
924 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
925 * GL_DEPTH_STENCIL_EXT or zero if error.
927 * XXX in the future when we support red-only and red-green formats
928 * we'll also return GL_RED and GL_RG.
931 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
933 switch (internalFormat
) {
957 case GL_RGBA16_SNORM
:
959 case GL_STENCIL_INDEX
:
960 case GL_STENCIL_INDEX1_EXT
:
961 case GL_STENCIL_INDEX4_EXT
:
962 case GL_STENCIL_INDEX8_EXT
:
963 case GL_STENCIL_INDEX16_EXT
:
964 return GL_STENCIL_INDEX
;
965 case GL_DEPTH_COMPONENT
:
966 case GL_DEPTH_COMPONENT16
:
967 case GL_DEPTH_COMPONENT24
:
968 case GL_DEPTH_COMPONENT32
:
969 return GL_DEPTH_COMPONENT
;
970 case GL_DEPTH_STENCIL_EXT
:
971 case GL_DEPTH24_STENCIL8_EXT
:
972 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
973 return GL_DEPTH_STENCIL_EXT
;
976 /* XXX add floating point formats eventually */
983 /** sentinal value, see below */
984 #define NO_SAMPLES 1000
988 * Helper function used by _mesa_RenderbufferStorageEXT() and
989 * _mesa_RenderbufferStorageMultisample().
990 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
993 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
994 GLsizei width
, GLsizei height
, GLsizei samples
)
996 const char *func
= samples
== NO_SAMPLES
?
997 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
998 struct gl_renderbuffer
*rb
;
1000 GET_CURRENT_CONTEXT(ctx
);
1002 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1004 if (target
!= GL_RENDERBUFFER_EXT
) {
1005 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1009 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1010 if (baseFormat
== 0) {
1011 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1015 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1016 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1020 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1021 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1025 if (samples
== NO_SAMPLES
) {
1026 /* NumSamples == 0 indicates non-multisampling */
1029 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1030 /* note: driver may choose to use more samples than what's requested */
1031 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1035 rb
= ctx
->CurrentRenderbuffer
;
1037 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1041 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1043 if (rb
->InternalFormat
== internalFormat
&&
1044 rb
->Width
== (GLuint
) width
&&
1045 rb
->Height
== (GLuint
) height
) {
1046 /* no change in allocation needed */
1050 /* These MUST get set by the AllocStorage func */
1051 rb
->Format
= MESA_FORMAT_NONE
;
1052 rb
->NumSamples
= samples
;
1054 /* Now allocate the storage */
1055 ASSERT(rb
->AllocStorage
);
1056 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1057 /* No error - check/set fields now */
1058 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1059 assert(rb
->Width
== (GLuint
) width
);
1060 assert(rb
->Height
== (GLuint
) height
);
1061 rb
->InternalFormat
= internalFormat
;
1062 rb
->_BaseFormat
= baseFormat
;
1063 assert(rb
->_BaseFormat
!= 0);
1066 /* Probably ran out of memory - clear the fields */
1069 rb
->Format
= MESA_FORMAT_NONE
;
1070 rb
->InternalFormat
= GL_NONE
;
1071 rb
->_BaseFormat
= GL_NONE
;
1076 test_framebuffer_completeness(ctx, fb);
1078 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1084 #if FEATURE_OES_EGL_image
1086 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1088 struct gl_renderbuffer
*rb
;
1089 GET_CURRENT_CONTEXT(ctx
);
1090 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1092 if (!ctx
->Extensions
.OES_EGL_image
) {
1093 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1094 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1098 if (target
!= GL_RENDERBUFFER
) {
1099 _mesa_error(ctx
, GL_INVALID_ENUM
,
1100 "EGLImageTargetRenderbufferStorageOES");
1104 rb
= ctx
->CurrentRenderbuffer
;
1106 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1107 "EGLImageTargetRenderbufferStorageOES");
1111 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1113 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1119 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1120 * _mesa_GetFramebufferAttachmentParameterivEXT()
1121 * We have to be careful to respect the base format. For example, if a
1122 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1123 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1124 * we need to return zero.
1127 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1130 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1131 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1132 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1133 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1134 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1135 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1136 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1137 return _mesa_get_format_bits(format
, pname
);
1140 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1141 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1142 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1143 return _mesa_get_format_bits(format
, pname
);
1146 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1147 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1148 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1149 return _mesa_get_format_bits(format
, pname
);
1152 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1153 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1154 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1155 return _mesa_get_format_bits(format
, pname
);
1166 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1167 GLsizei width
, GLsizei height
)
1169 /* GL_ARB_fbo says calling this function is equivalent to calling
1170 * glRenderbufferStorageMultisample() with samples=0. We pass in
1171 * a token value here just for error reporting purposes.
1173 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1178 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1179 GLenum internalFormat
,
1180 GLsizei width
, GLsizei height
)
1182 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1187 * OpenGL ES version of glRenderBufferStorage.
1190 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1191 GLsizei width
, GLsizei height
)
1193 switch (internalFormat
) {
1195 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1196 /* choose a closest format */
1197 internalFormat
= GL_RGB5
;
1203 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1208 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1210 struct gl_renderbuffer
*rb
;
1211 GET_CURRENT_CONTEXT(ctx
);
1213 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1215 if (target
!= GL_RENDERBUFFER_EXT
) {
1216 _mesa_error(ctx
, GL_INVALID_ENUM
,
1217 "glGetRenderbufferParameterivEXT(target)");
1221 rb
= ctx
->CurrentRenderbuffer
;
1223 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1224 "glGetRenderbufferParameterivEXT");
1228 /* No need to flush here since we're just quering state which is
1229 * not effected by rendering.
1233 case GL_RENDERBUFFER_WIDTH_EXT
:
1234 *params
= rb
->Width
;
1236 case GL_RENDERBUFFER_HEIGHT_EXT
:
1237 *params
= rb
->Height
;
1239 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1240 *params
= rb
->InternalFormat
;
1242 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1243 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1244 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1245 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1246 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1247 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1248 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1250 case GL_RENDERBUFFER_SAMPLES
:
1251 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1252 *params
= rb
->NumSamples
;
1257 _mesa_error(ctx
, GL_INVALID_ENUM
,
1258 "glGetRenderbufferParameterivEXT(target)");
1264 GLboolean GLAPIENTRY
1265 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1267 GET_CURRENT_CONTEXT(ctx
);
1268 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1270 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1271 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1279 * Check if any of the attachments of the given framebuffer are textures
1280 * (render to texture). Call ctx->Driver.RenderTexture() for such
1284 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1287 ASSERT(ctx
->Driver
.RenderTexture
);
1290 return; /* can't render to texture with winsys framebuffers */
1292 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1293 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1294 struct gl_texture_object
*texObj
= att
->Texture
;
1296 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1297 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1304 * Examine all the framebuffer's attachments to see if any are textures.
1305 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1306 * notify the device driver that the texture image may have changed.
1309 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1312 return; /* can't render to texture with winsys framebuffers */
1314 if (ctx
->Driver
.FinishRenderTexture
) {
1316 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1317 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1318 if (att
->Texture
&& att
->Renderbuffer
) {
1319 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1327 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1329 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1330 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1331 GLboolean bindReadBuf
, bindDrawBuf
;
1332 GET_CURRENT_CONTEXT(ctx
);
1335 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1336 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1337 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1341 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1343 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1345 "glBindFramebufferEXT(unsupported)");
1350 #if FEATURE_EXT_framebuffer_blit
1351 case GL_DRAW_FRAMEBUFFER_EXT
:
1352 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1353 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1356 bindDrawBuf
= GL_TRUE
;
1357 bindReadBuf
= GL_FALSE
;
1359 case GL_READ_FRAMEBUFFER_EXT
:
1360 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1361 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1364 bindDrawBuf
= GL_FALSE
;
1365 bindReadBuf
= GL_TRUE
;
1368 case GL_FRAMEBUFFER_EXT
:
1369 bindDrawBuf
= GL_TRUE
;
1370 bindReadBuf
= GL_TRUE
;
1373 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1378 /* Binding a user-created framebuffer object */
1379 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1380 if (newDrawFb
== &DummyFramebuffer
) {
1381 /* ID was reserved, but no real framebuffer object made yet */
1384 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1385 /* All FBO IDs must be Gen'd */
1386 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1391 /* create new framebuffer object */
1392 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1394 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1397 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1399 newReadFb
= newDrawFb
;
1402 /* Binding the window system framebuffer (which was originally set
1403 * with MakeCurrent).
1405 newDrawFb
= ctx
->WinSysDrawBuffer
;
1406 newReadFb
= ctx
->WinSysReadBuffer
;
1410 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1412 /* save pointers to current/old framebuffers */
1413 oldDrawFb
= ctx
->DrawBuffer
;
1414 oldReadFb
= ctx
->ReadBuffer
;
1416 /* check if really changing bindings */
1417 if (oldDrawFb
== newDrawFb
)
1418 bindDrawBuf
= GL_FALSE
;
1419 if (oldReadFb
== newReadFb
)
1420 bindReadBuf
= GL_FALSE
;
1423 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1425 * We also check if we're beginning and/or ending render-to-texture.
1426 * When a framebuffer with texture attachments is unbound, call
1427 * ctx->Driver.FinishRenderTexture().
1428 * When a framebuffer with texture attachments is bound, call
1429 * ctx->Driver.RenderTexture().
1431 * Note that if the ReadBuffer has texture attachments we don't consider
1432 * that a render-to-texture case.
1435 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1437 /* check if old readbuffer was render-to-texture */
1438 check_end_texture_render(ctx
, oldReadFb
);
1440 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1444 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1446 /* check if old read/draw buffers were render-to-texture */
1448 check_end_texture_render(ctx
, oldReadFb
);
1450 if (oldDrawFb
!= oldReadFb
)
1451 check_end_texture_render(ctx
, oldDrawFb
);
1453 /* check if newly bound framebuffer has any texture attachments */
1454 check_begin_texture_render(ctx
, newDrawFb
);
1456 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1459 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1460 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1466 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1469 GET_CURRENT_CONTEXT(ctx
);
1471 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1472 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1474 for (i
= 0; i
< n
; i
++) {
1475 if (framebuffers
[i
] > 0) {
1476 struct gl_framebuffer
*fb
;
1477 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1479 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1481 /* check if deleting currently bound framebuffer object */
1482 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1483 /* separate draw/read binding points */
1484 if (fb
== ctx
->DrawBuffer
) {
1486 ASSERT(fb
->RefCount
>= 2);
1487 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1489 if (fb
== ctx
->ReadBuffer
) {
1491 ASSERT(fb
->RefCount
>= 2);
1492 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1496 /* only one binding point for read/draw buffers */
1497 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1499 ASSERT(fb
->RefCount
>= 2);
1500 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1504 /* remove from hash table immediately, to free the ID */
1505 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1507 if (fb
!= &DummyFramebuffer
) {
1508 /* But the object will not be freed until it's no longer
1509 * bound in any context.
1511 _mesa_reference_framebuffer(&fb
, NULL
);
1520 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1522 GET_CURRENT_CONTEXT(ctx
);
1526 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1529 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1536 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1538 for (i
= 0; i
< n
; i
++) {
1539 GLuint name
= first
+ i
;
1540 framebuffers
[i
] = name
;
1541 /* insert dummy placeholder into hash table */
1542 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1543 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1544 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1551 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1553 struct gl_framebuffer
*buffer
;
1554 GET_CURRENT_CONTEXT(ctx
);
1556 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1559 #if FEATURE_EXT_framebuffer_blit
1560 case GL_DRAW_FRAMEBUFFER_EXT
:
1561 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1562 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1565 buffer
= ctx
->DrawBuffer
;
1567 case GL_READ_FRAMEBUFFER_EXT
:
1568 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1569 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1572 buffer
= ctx
->ReadBuffer
;
1575 case GL_FRAMEBUFFER_EXT
:
1576 buffer
= ctx
->DrawBuffer
;
1579 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1580 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1583 if (buffer
->Name
== 0) {
1584 /* The window system / default framebuffer is always complete */
1585 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1588 /* No need to flush here */
1590 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1591 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1594 return buffer
->_Status
;
1600 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1603 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1604 GLenum attachment
, GLenum textarget
, GLuint texture
,
1605 GLint level
, GLint zoffset
)
1607 struct gl_renderbuffer_attachment
*att
;
1608 struct gl_texture_object
*texObj
= NULL
;
1609 struct gl_framebuffer
*fb
;
1610 GLboolean error
= GL_FALSE
;
1612 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1615 case GL_READ_FRAMEBUFFER_EXT
:
1616 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1617 fb
= ctx
->ReadBuffer
;
1619 case GL_DRAW_FRAMEBUFFER_EXT
:
1620 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1622 case GL_FRAMEBUFFER_EXT
:
1623 fb
= ctx
->DrawBuffer
;
1630 _mesa_error(ctx
, GL_INVALID_ENUM
,
1631 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1637 /* check framebuffer binding */
1638 if (fb
->Name
== 0) {
1639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1640 "glFramebufferTexture%sEXT", caller
);
1645 /* The textarget, level, and zoffset parameters are only validated if
1646 * texture is non-zero.
1649 GLboolean err
= GL_TRUE
;
1651 texObj
= _mesa_lookup_texture(ctx
, texture
);
1652 if (texObj
!= NULL
) {
1653 if (textarget
== 0) {
1654 /* XXX what's the purpose of this? */
1655 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1656 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1657 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1660 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1661 ? !IS_CUBE_FACE(textarget
)
1662 : (texObj
->Target
!= textarget
);
1666 /* can't render to a non-existant texture */
1667 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1668 "glFramebufferTexture%sEXT(non existant texture)",
1674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1675 "glFramebufferTexture%sEXT(texture target mismatch)",
1680 if (texObj
->Target
== GL_TEXTURE_3D
) {
1681 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1682 if (zoffset
< 0 || zoffset
>= maxSize
) {
1683 _mesa_error(ctx
, GL_INVALID_VALUE
,
1684 "glFramebufferTexture%sEXT(zoffset)", caller
);
1688 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1689 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1690 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1691 _mesa_error(ctx
, GL_INVALID_VALUE
,
1692 "glFramebufferTexture%sEXT(layer)", caller
);
1698 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1699 _mesa_error(ctx
, GL_INVALID_VALUE
,
1700 "glFramebufferTexture%sEXT(level)", caller
);
1705 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1707 _mesa_error(ctx
, GL_INVALID_ENUM
,
1708 "glFramebufferTexture%sEXT(attachment)", caller
);
1712 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1714 _glthread_LOCK_MUTEX(fb
->Mutex
);
1716 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1718 /* Set the render-to-texture flag. We'll check this flag in
1719 * glTexImage() and friends to determine if we need to revalidate
1720 * any FBOs that might be rendering into this texture.
1721 * This flag never gets cleared since it's non-trivial to determine
1722 * when all FBOs might be done rendering to this texture. That's OK
1723 * though since it's uncommon to render to a texture then repeatedly
1724 * call glTexImage() to change images in the texture.
1726 texObj
->_RenderToTexture
= GL_TRUE
;
1729 _mesa_remove_attachment(ctx
, att
);
1732 invalidate_framebuffer(fb
);
1734 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1740 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1741 GLenum textarget
, GLuint texture
, GLint level
)
1743 GET_CURRENT_CONTEXT(ctx
);
1745 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1746 _mesa_error(ctx
, GL_INVALID_ENUM
,
1747 "glFramebufferTexture1DEXT(textarget)");
1751 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1757 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1758 GLenum textarget
, GLuint texture
, GLint level
)
1760 GET_CURRENT_CONTEXT(ctx
);
1762 if ((texture
!= 0) &&
1763 (textarget
!= GL_TEXTURE_2D
) &&
1764 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1765 (!IS_CUBE_FACE(textarget
))) {
1766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1767 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1771 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1777 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1778 GLenum textarget
, GLuint texture
,
1779 GLint level
, GLint zoffset
)
1781 GET_CURRENT_CONTEXT(ctx
);
1783 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1784 _mesa_error(ctx
, GL_INVALID_ENUM
,
1785 "glFramebufferTexture3DEXT(textarget)");
1789 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1795 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1796 GLuint texture
, GLint level
, GLint layer
)
1798 GET_CURRENT_CONTEXT(ctx
);
1800 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1806 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1807 GLenum renderbufferTarget
,
1808 GLuint renderbuffer
)
1810 struct gl_renderbuffer_attachment
*att
;
1811 struct gl_framebuffer
*fb
;
1812 struct gl_renderbuffer
*rb
;
1813 GET_CURRENT_CONTEXT(ctx
);
1815 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1818 #if FEATURE_EXT_framebuffer_blit
1819 case GL_DRAW_FRAMEBUFFER_EXT
:
1820 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1821 _mesa_error(ctx
, GL_INVALID_ENUM
,
1822 "glFramebufferRenderbufferEXT(target)");
1825 fb
= ctx
->DrawBuffer
;
1827 case GL_READ_FRAMEBUFFER_EXT
:
1828 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1829 _mesa_error(ctx
, GL_INVALID_ENUM
,
1830 "glFramebufferRenderbufferEXT(target)");
1833 fb
= ctx
->ReadBuffer
;
1836 case GL_FRAMEBUFFER_EXT
:
1837 fb
= ctx
->DrawBuffer
;
1840 _mesa_error(ctx
, GL_INVALID_ENUM
,
1841 "glFramebufferRenderbufferEXT(target)");
1845 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1846 _mesa_error(ctx
, GL_INVALID_ENUM
,
1847 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1851 if (fb
->Name
== 0) {
1852 /* Can't attach new renderbuffers to a window system framebuffer */
1853 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1857 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1859 _mesa_error(ctx
, GL_INVALID_ENUM
,
1860 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1861 _mesa_lookup_enum_by_nr(attachment
));
1866 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1868 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1869 "glFramebufferRenderbufferEXT(non-existant"
1870 " renderbuffer %u)", renderbuffer
);
1875 /* remove renderbuffer attachment */
1879 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1880 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1881 /* make sure the renderbuffer is a depth/stencil format */
1882 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1883 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1884 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1885 "glFramebufferRenderbufferEXT(renderbuffer"
1886 " is not DEPTH_STENCIL format)");
1892 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1894 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1895 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1897 /* Some subsequent GL commands may depend on the framebuffer's visual
1898 * after the binding is updated. Update visual info now.
1900 _mesa_update_framebuffer_visual(fb
);
1905 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1906 GLenum pname
, GLint
*params
)
1908 const struct gl_renderbuffer_attachment
*att
;
1909 struct gl_framebuffer
*buffer
;
1910 GET_CURRENT_CONTEXT(ctx
);
1912 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1915 #if FEATURE_EXT_framebuffer_blit
1916 case GL_DRAW_FRAMEBUFFER_EXT
:
1917 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1918 _mesa_error(ctx
, GL_INVALID_ENUM
,
1919 "glGetFramebufferAttachmentParameterivEXT(target)");
1922 buffer
= ctx
->DrawBuffer
;
1924 case GL_READ_FRAMEBUFFER_EXT
:
1925 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1926 _mesa_error(ctx
, GL_INVALID_ENUM
,
1927 "glGetFramebufferAttachmentParameterivEXT(target)");
1930 buffer
= ctx
->ReadBuffer
;
1933 case GL_FRAMEBUFFER_EXT
:
1934 buffer
= ctx
->DrawBuffer
;
1937 _mesa_error(ctx
, GL_INVALID_ENUM
,
1938 "glGetFramebufferAttachmentParameterivEXT(target)");
1942 if (buffer
->Name
== 0) {
1943 /* the default / window-system FBO */
1944 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
1947 /* user-created framebuffer FBO */
1948 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1952 _mesa_error(ctx
, GL_INVALID_ENUM
,
1953 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1957 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1958 /* the depth and stencil attachments must point to the same buffer */
1959 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
1960 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
1961 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
1962 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
1963 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1964 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1965 " attachments differ)");
1970 /* No need to flush here */
1973 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1974 *params
= att
->Type
;
1976 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1977 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1978 *params
= att
->Renderbuffer
->Name
;
1980 else if (att
->Type
== GL_TEXTURE
) {
1981 *params
= att
->Texture
->Name
;
1984 _mesa_error(ctx
, GL_INVALID_ENUM
,
1985 "glGetFramebufferAttachmentParameterivEXT(pname)");
1988 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1989 if (att
->Type
== GL_TEXTURE
) {
1990 *params
= att
->TextureLevel
;
1993 _mesa_error(ctx
, GL_INVALID_ENUM
,
1994 "glGetFramebufferAttachmentParameterivEXT(pname)");
1997 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1998 if (att
->Type
== GL_TEXTURE
) {
1999 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2000 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2007 _mesa_error(ctx
, GL_INVALID_ENUM
,
2008 "glGetFramebufferAttachmentParameterivEXT(pname)");
2011 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2012 if (att
->Type
== GL_TEXTURE
) {
2013 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2014 *params
= att
->Zoffset
;
2021 _mesa_error(ctx
, GL_INVALID_ENUM
,
2022 "glGetFramebufferAttachmentParameterivEXT(pname)");
2025 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2026 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2027 _mesa_error(ctx
, GL_INVALID_ENUM
,
2028 "glGetFramebufferAttachmentParameterivEXT(pname)");
2031 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2034 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2035 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2036 _mesa_error(ctx
, GL_INVALID_ENUM
,
2037 "glGetFramebufferAttachmentParameterivEXT(pname)");
2041 gl_format format
= att
->Renderbuffer
->Format
;
2042 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2047 *params
= _mesa_get_format_datatype(format
);
2051 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2052 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2053 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2054 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2055 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2056 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2057 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2058 _mesa_error(ctx
, GL_INVALID_ENUM
,
2059 "glGetFramebufferAttachmentParameterivEXT(pname)");
2061 else if (att
->Texture
) {
2062 const struct gl_texture_image
*texImage
=
2063 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2066 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2067 texImage
->TexFormat
);
2073 else if (att
->Renderbuffer
) {
2074 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2075 att
->Renderbuffer
->Format
);
2082 _mesa_error(ctx
, GL_INVALID_ENUM
,
2083 "glGetFramebufferAttachmentParameterivEXT(pname)");
2090 _mesa_GenerateMipmapEXT(GLenum target
)
2092 struct gl_texture_object
*texObj
;
2093 GET_CURRENT_CONTEXT(ctx
);
2095 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2096 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2102 case GL_TEXTURE_CUBE_MAP
:
2103 /* OK, legal value */
2106 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2110 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2112 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2117 _mesa_lock_texture(ctx
, texObj
);
2118 if (target
== GL_TEXTURE_CUBE_MAP
) {
2120 for (face
= 0; face
< 6; face
++)
2121 ctx
->Driver
.GenerateMipmap(ctx
,
2122 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2126 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2128 _mesa_unlock_texture(ctx
, texObj
);
2132 #if FEATURE_EXT_framebuffer_blit
2134 static const struct gl_renderbuffer_attachment
*
2135 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2138 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2139 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2140 return &fb
->Attachment
[i
];
2148 * Blit rectangular region, optionally from one framebuffer to another.
2150 * Note, if the src buffer is multisampled and the dest is not, this is
2151 * when the samples must be resolved to a single color.
2154 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2155 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2156 GLbitfield mask
, GLenum filter
)
2158 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2159 GL_DEPTH_BUFFER_BIT
|
2160 GL_STENCIL_BUFFER_BIT
);
2161 const struct gl_framebuffer
*readFb
, *drawFb
;
2162 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2163 GET_CURRENT_CONTEXT(ctx
);
2165 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2166 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2168 if (ctx
->NewState
) {
2169 _mesa_update_state(ctx
);
2172 readFb
= ctx
->ReadBuffer
;
2173 drawFb
= ctx
->DrawBuffer
;
2175 if (!readFb
|| !drawFb
) {
2176 /* This will normally never happen but someday we may want to
2177 * support MakeCurrent() with no drawables.
2182 /* check for complete framebuffers */
2183 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2184 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2185 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2186 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2190 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2191 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2195 if (mask
& ~legalMaskBits
) {
2196 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2200 /* depth/stencil must be blitted with nearest filtering */
2201 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2202 && filter
!= GL_NEAREST
) {
2203 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2204 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2208 /* get color read/draw renderbuffers */
2209 if (mask
& GL_COLOR_BUFFER_BIT
) {
2210 colorReadRb
= readFb
->_ColorReadBuffer
;
2211 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2214 colorReadRb
= colorDrawRb
= NULL
;
2217 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2218 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2219 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2222 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2223 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2225 "glBlitFramebufferEXT(stencil buffer size mismatch");
2230 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2231 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2232 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2235 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2236 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2238 "glBlitFramebufferEXT(depth buffer size mismatch");
2243 if (readFb
->Visual
.samples
> 0 &&
2244 drawFb
->Visual
.samples
> 0 &&
2245 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2247 "glBlitFramebufferEXT(mismatched samples");
2251 /* extra checks for multisample copies... */
2252 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2253 /* src and dest region sizes must be the same */
2254 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2255 srcY1
- srcY0
!= dstY1
- dstY0
) {
2256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2257 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2261 /* color formats must match */
2264 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2266 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2271 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2272 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2278 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2280 srcX0
, srcY0
, srcX1
, srcY1
,
2281 dstX0
, dstY0
, dstX1
, dstY1
,
2284 const struct gl_renderbuffer_attachment
*att
;
2286 att
= find_attachment(readFb
, colorReadRb
);
2287 printf(" Src FBO %u RB %u (%dx%d) ",
2288 readFb
->Name
, colorReadRb
->Name
,
2289 colorReadRb
->Width
, colorReadRb
->Height
);
2290 if (att
&& att
->Texture
) {
2291 printf("Tex %u tgt 0x%x level %u face %u",
2293 att
->Texture
->Target
,
2299 att
= find_attachment(drawFb
, colorDrawRb
);
2300 printf(" Dst FBO %u RB %u (%dx%d) ",
2301 drawFb
->Name
, colorDrawRb
->Name
,
2302 colorDrawRb
->Width
, colorDrawRb
->Height
);
2303 if (att
&& att
->Texture
) {
2304 printf("Tex %u tgt 0x%x level %u face %u",
2306 att
->Texture
->Target
,
2314 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2315 ctx
->Driver
.BlitFramebuffer(ctx
,
2316 srcX0
, srcY0
, srcX1
, srcY1
,
2317 dstX0
, dstY0
, dstX1
, dstY1
,
2320 #endif /* FEATURE_EXT_framebuffer_blit */
2322 #if FEATURE_ARB_geometry_shader4
2324 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2325 GLuint texture
, GLint level
)
2327 GET_CURRENT_CONTEXT(ctx
);
2328 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2329 "glFramebufferTextureARB "
2330 "not implemented!");
2334 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2335 GLuint texture
, GLint level
, GLenum face
)
2337 GET_CURRENT_CONTEXT(ctx
);
2338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2339 "glFramebufferTextureFaceARB "
2340 "not implemented!");
2342 #endif /* FEATURE_ARB_geometry_shader4 */