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 "mfeatures.h"
45 #include "renderbuffer.h"
51 /** Set this to 1 to help debug FBO incompleteness problems */
54 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
61 * None of the GL_EXT_framebuffer_object functions are compiled into
68 * When glGenRender/FramebuffersEXT() is called we insert pointers to
69 * these placeholder objects into the hash table.
70 * Later, when the object ID is first bound, we replace the placeholder
71 * with the real frame/renderbuffer.
73 static struct gl_framebuffer DummyFramebuffer
;
74 static struct gl_renderbuffer DummyRenderbuffer
;
76 /* We bind this framebuffer when applications pass a NULL
77 * drawable/surface in make current. */
78 static struct gl_framebuffer IncompleteFramebuffer
;
81 #define IS_CUBE_FACE(TARGET) \
82 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
83 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
87 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
93 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
100 _mesa_init_fbobjects(struct gl_context
*ctx
)
102 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
103 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
104 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
105 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
106 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
107 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
110 struct gl_framebuffer
*
111 _mesa_get_incomplete_framebuffer(void)
113 return &IncompleteFramebuffer
;
117 * Helper routine for getting a gl_renderbuffer.
119 struct gl_renderbuffer
*
120 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
122 struct gl_renderbuffer
*rb
;
127 rb
= (struct gl_renderbuffer
*)
128 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
134 * Helper routine for getting a gl_framebuffer.
136 struct gl_framebuffer
*
137 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
139 struct gl_framebuffer
*fb
;
144 fb
= (struct gl_framebuffer
*)
145 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
151 * Mark the given framebuffer as invalid. This will force the
152 * test for framebuffer completeness to be done before the framebuffer
156 invalidate_framebuffer(struct gl_framebuffer
*fb
)
158 fb
->_Status
= 0; /* "indeterminate" */
163 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
164 * gl_renderbuffer_attachment object.
165 * This function is only used for user-created FB objects, not the
166 * default / window-system FB object.
167 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
168 * the depth buffer attachment point.
170 struct gl_renderbuffer_attachment
*
171 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
176 assert(fb
->Name
> 0);
178 switch (attachment
) {
179 case GL_COLOR_ATTACHMENT0_EXT
:
180 case GL_COLOR_ATTACHMENT1_EXT
:
181 case GL_COLOR_ATTACHMENT2_EXT
:
182 case GL_COLOR_ATTACHMENT3_EXT
:
183 case GL_COLOR_ATTACHMENT4_EXT
:
184 case GL_COLOR_ATTACHMENT5_EXT
:
185 case GL_COLOR_ATTACHMENT6_EXT
:
186 case GL_COLOR_ATTACHMENT7_EXT
:
187 case GL_COLOR_ATTACHMENT8_EXT
:
188 case GL_COLOR_ATTACHMENT9_EXT
:
189 case GL_COLOR_ATTACHMENT10_EXT
:
190 case GL_COLOR_ATTACHMENT11_EXT
:
191 case GL_COLOR_ATTACHMENT12_EXT
:
192 case GL_COLOR_ATTACHMENT13_EXT
:
193 case GL_COLOR_ATTACHMENT14_EXT
:
194 case GL_COLOR_ATTACHMENT15_EXT
:
195 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
196 if (i
>= ctx
->Const
.MaxColorAttachments
) {
199 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
200 case GL_DEPTH_STENCIL_ATTACHMENT
:
202 case GL_DEPTH_BUFFER
:
203 /* fall-through / new in GL 3.0 */
204 case GL_DEPTH_ATTACHMENT_EXT
:
205 return &fb
->Attachment
[BUFFER_DEPTH
];
206 case GL_STENCIL_BUFFER
:
207 /* fall-through / new in GL 3.0 */
208 case GL_STENCIL_ATTACHMENT_EXT
:
209 return &fb
->Attachment
[BUFFER_STENCIL
];
217 * As above, but only used for getting attachments of the default /
218 * window-system framebuffer (not user-created framebuffer objects).
220 static struct gl_renderbuffer_attachment
*
221 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
224 assert(fb
->Name
== 0);
226 switch (attachment
) {
228 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
230 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
232 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
234 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
236 if (fb
->Visual
.numAuxBuffers
== 1) {
237 return &fb
->Attachment
[BUFFER_AUX0
];
240 case GL_DEPTH_BUFFER
:
241 /* fall-through / new in GL 3.0 */
242 case GL_DEPTH_ATTACHMENT_EXT
:
243 return &fb
->Attachment
[BUFFER_DEPTH
];
244 case GL_STENCIL_BUFFER
:
245 /* fall-through / new in GL 3.0 */
246 case GL_STENCIL_ATTACHMENT_EXT
:
247 return &fb
->Attachment
[BUFFER_STENCIL
];
256 * Remove any texture or renderbuffer attached to the given attachment
257 * point. Update reference counts, etc.
260 _mesa_remove_attachment(struct gl_context
*ctx
,
261 struct gl_renderbuffer_attachment
*att
)
263 if (att
->Type
== GL_TEXTURE
) {
264 ASSERT(att
->Texture
);
265 if (ctx
->Driver
.FinishRenderTexture
) {
266 /* tell driver that we're done rendering to this texture. */
267 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
269 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
270 ASSERT(!att
->Texture
);
272 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
273 ASSERT(!att
->Texture
);
274 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
275 ASSERT(!att
->Renderbuffer
);
278 att
->Complete
= GL_TRUE
;
283 * Bind a texture object to an attachment point.
284 * The previous binding, if any, will be removed first.
287 _mesa_set_texture_attachment(struct gl_context
*ctx
,
288 struct gl_framebuffer
*fb
,
289 struct gl_renderbuffer_attachment
*att
,
290 struct gl_texture_object
*texObj
,
291 GLenum texTarget
, GLuint level
, GLuint zoffset
)
293 if (att
->Texture
== texObj
) {
294 /* re-attaching same texture */
295 ASSERT(att
->Type
== GL_TEXTURE
);
296 if (ctx
->Driver
.FinishRenderTexture
)
297 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
301 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
302 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
303 _mesa_remove_attachment(ctx
, att
);
304 att
->Type
= GL_TEXTURE
;
305 assert(!att
->Texture
);
306 _mesa_reference_texobj(&att
->Texture
, texObj
);
309 /* always update these fields */
310 att
->TextureLevel
= level
;
311 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
312 att
->Zoffset
= zoffset
;
313 att
->Complete
= GL_FALSE
;
315 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
316 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
319 invalidate_framebuffer(fb
);
324 * Bind a renderbuffer to an attachment point.
325 * The previous binding, if any, will be removed first.
328 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
329 struct gl_renderbuffer_attachment
*att
,
330 struct gl_renderbuffer
*rb
)
332 /* XXX check if re-doing same attachment, exit early */
333 _mesa_remove_attachment(ctx
, att
);
334 att
->Type
= GL_RENDERBUFFER_EXT
;
335 att
->Texture
= NULL
; /* just to be safe */
336 att
->Complete
= GL_FALSE
;
337 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
342 * Fallback for ctx->Driver.FramebufferRenderbuffer()
343 * Attach a renderbuffer object to a framebuffer object.
346 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
347 struct gl_framebuffer
*fb
,
348 GLenum attachment
, struct gl_renderbuffer
*rb
)
350 struct gl_renderbuffer_attachment
*att
;
352 _glthread_LOCK_MUTEX(fb
->Mutex
);
354 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
357 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
358 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
359 /* do stencil attachment here (depth already done above) */
360 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
362 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
366 _mesa_remove_attachment(ctx
, att
);
369 invalidate_framebuffer(fb
);
371 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
376 * Fallback for ctx->Driver.ValidateFramebuffer()
377 * Check if the renderbuffer's formats are supported by the software
379 * Drivers should probably override this.
382 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
385 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
386 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
388 switch (rb
->_BaseFormat
) {
390 case GL_LUMINANCE_ALPHA
:
393 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
396 /* render buffer format is supported by software rendering */
408 att_incomplete(const char *msg
)
411 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
422 fbo_incomplete(const char *msg
, int index
)
425 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
434 * Is the given base format a legal format for a color renderbuffer?
437 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
439 switch (baseFormat
) {
444 case GL_LUMINANCE_ALPHA
:
447 return ctx
->Extensions
.ARB_framebuffer_object
;
450 return ctx
->Extensions
.ARB_texture_rg
;
458 * Is the given base format a legal format for a depth/stencil renderbuffer?
461 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
463 switch (baseFormat
) {
464 case GL_DEPTH_COMPONENT
:
465 case GL_DEPTH_STENCIL_EXT
:
474 * Test if an attachment point is complete and update its Complete field.
475 * \param format if GL_COLOR, this is a color attachment point,
476 * if GL_DEPTH, this is a depth component attachment point,
477 * if GL_STENCIL, this is a stencil component attachment point.
480 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
481 struct gl_renderbuffer_attachment
*att
)
483 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
485 /* assume complete */
486 att
->Complete
= GL_TRUE
;
488 /* Look for reasons why the attachment might be incomplete */
489 if (att
->Type
== GL_TEXTURE
) {
490 const struct gl_texture_object
*texObj
= att
->Texture
;
491 struct gl_texture_image
*texImage
;
495 att_incomplete("no texobj");
496 att
->Complete
= GL_FALSE
;
500 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
502 att_incomplete("no teximage");
503 att
->Complete
= GL_FALSE
;
506 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
507 att_incomplete("teximage width/height=0");
508 printf("texobj = %u\n", texObj
->Name
);
509 printf("level = %d\n", att
->TextureLevel
);
510 att
->Complete
= GL_FALSE
;
513 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
514 att_incomplete("bad z offset");
515 att
->Complete
= GL_FALSE
;
519 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
521 if (format
== GL_COLOR
) {
522 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
523 att_incomplete("bad format");
524 att
->Complete
= GL_FALSE
;
527 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
528 att_incomplete("compressed internalformat");
529 att
->Complete
= GL_FALSE
;
533 else if (format
== GL_DEPTH
) {
534 if (baseFormat
== GL_DEPTH_COMPONENT
) {
537 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
538 ctx
->Extensions
.ARB_depth_texture
&&
539 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
543 att
->Complete
= GL_FALSE
;
544 att_incomplete("bad depth format");
549 ASSERT(format
== GL_STENCIL
);
550 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
551 ctx
->Extensions
.ARB_depth_texture
&&
552 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
556 /* no such thing as stencil-only textures */
557 att_incomplete("illegal stencil texture");
558 att
->Complete
= GL_FALSE
;
563 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
564 const GLenum baseFormat
=
565 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
567 ASSERT(att
->Renderbuffer
);
568 if (!att
->Renderbuffer
->InternalFormat
||
569 att
->Renderbuffer
->Width
< 1 ||
570 att
->Renderbuffer
->Height
< 1) {
571 att_incomplete("0x0 renderbuffer");
572 att
->Complete
= GL_FALSE
;
575 if (format
== GL_COLOR
) {
576 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
577 att_incomplete("bad renderbuffer color format");
578 att
->Complete
= GL_FALSE
;
582 else if (format
== GL_DEPTH
) {
583 if (baseFormat
== GL_DEPTH_COMPONENT
) {
586 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
587 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
591 att_incomplete("bad renderbuffer depth format");
592 att
->Complete
= GL_FALSE
;
597 assert(format
== GL_STENCIL
);
598 if (baseFormat
== GL_STENCIL_INDEX
) {
601 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
602 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
606 att
->Complete
= GL_FALSE
;
607 att_incomplete("bad renderbuffer stencil format");
613 ASSERT(att
->Type
== GL_NONE
);
621 * Test if the given framebuffer object is complete and update its
622 * Status field with the results.
623 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
624 * driver to make hardware-specific validation/completeness checks.
625 * Also update the framebuffer's Width and Height fields if the
626 * framebuffer is complete.
629 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
630 struct gl_framebuffer
*fb
)
633 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
634 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
635 GLint numSamples
= -1;
639 assert(fb
->Name
!= 0);
645 /* Start at -2 to more easily loop over all attachment points.
650 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
651 struct gl_renderbuffer_attachment
*att
;
653 gl_format mesaFormat
;
656 * XXX for ARB_fbo, only check color buffers that are named by
657 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
660 /* check for attachment completeness
663 att
= &fb
->Attachment
[BUFFER_DEPTH
];
664 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
665 if (!att
->Complete
) {
666 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
667 fbo_incomplete("depth attachment incomplete", -1);
672 att
= &fb
->Attachment
[BUFFER_STENCIL
];
673 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
674 if (!att
->Complete
) {
675 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
676 fbo_incomplete("stencil attachment incomplete", -1);
681 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
682 test_attachment_completeness(ctx
, GL_COLOR
, att
);
683 if (!att
->Complete
) {
684 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
685 fbo_incomplete("color attachment incomplete", i
);
690 /* get width, height, format of the renderbuffer/texture
692 if (att
->Type
== GL_TEXTURE
) {
693 const struct gl_texture_image
*texImg
694 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
695 minWidth
= MIN2(minWidth
, texImg
->Width
);
696 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
697 minHeight
= MIN2(minHeight
, texImg
->Height
);
698 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
699 f
= texImg
->_BaseFormat
;
700 mesaFormat
= texImg
->TexFormat
;
702 if (!_mesa_is_legal_color_format(ctx
, f
) &&
703 !is_legal_depth_format(ctx
, f
)) {
704 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
705 fbo_incomplete("texture attachment incomplete", -1);
709 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
710 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
711 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
712 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
713 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
714 f
= att
->Renderbuffer
->InternalFormat
;
715 mesaFormat
= att
->Renderbuffer
->Format
;
719 assert(att
->Type
== GL_NONE
);
723 if (numSamples
< 0) {
725 numSamples
= att
->Renderbuffer
->NumSamples
;
728 /* check if integer color */
729 fb
->_IntegerColor
= _mesa_is_format_integer_color(mesaFormat
);
731 /* Error-check width, height, format, samples
733 if (numImages
== 1) {
734 /* save format, num samples */
740 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
741 /* check that width, height, format are same */
742 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
743 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
744 fbo_incomplete("width or height mismatch", -1);
747 /* check that all color buffer have same format */
748 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
749 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
750 fbo_incomplete("format mismatch", -1);
754 if (att
->Renderbuffer
&&
755 att
->Renderbuffer
->NumSamples
!= numSamples
) {
756 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
757 fbo_incomplete("inconsistant number of samples", i
);
765 if (ctx
->API
== API_OPENGL
) {
766 /* Check that all DrawBuffers are present */
767 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
768 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
769 const struct gl_renderbuffer_attachment
*att
770 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
772 if (att
->Type
== GL_NONE
) {
773 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
774 fbo_incomplete("missing drawbuffer", j
);
780 /* Check that the ReadBuffer is present */
781 if (fb
->ColorReadBuffer
!= GL_NONE
) {
782 const struct gl_renderbuffer_attachment
*att
783 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
785 if (att
->Type
== GL_NONE
) {
786 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
787 fbo_incomplete("missing readbuffer", -1);
796 if (numImages
== 0) {
797 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
798 fbo_incomplete("no attachments", -1);
802 /* Provisionally set status = COMPLETE ... */
803 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
805 /* ... but the driver may say the FB is incomplete.
806 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
809 if (ctx
->Driver
.ValidateFramebuffer
) {
810 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
811 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
812 fbo_incomplete("driver marked FBO as incomplete", -1);
816 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
818 * Note that if ARB_framebuffer_object is supported and the attached
819 * renderbuffers/textures are different sizes, the framebuffer
820 * width/height will be set to the smallest width/height.
822 fb
->Width
= minWidth
;
823 fb
->Height
= minHeight
;
825 /* finally, update the visual info for the framebuffer */
826 _mesa_update_framebuffer_visual(ctx
, fb
);
832 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
834 GET_CURRENT_CONTEXT(ctx
);
835 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
837 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
838 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
846 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
848 struct gl_renderbuffer
*newRb
;
849 GET_CURRENT_CONTEXT(ctx
);
851 ASSERT_OUTSIDE_BEGIN_END(ctx
);
853 if (target
!= GL_RENDERBUFFER_EXT
) {
854 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
858 /* No need to flush here since the render buffer binding has no
859 * effect on rendering state.
863 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
864 if (newRb
== &DummyRenderbuffer
) {
865 /* ID was reserved, but no real renderbuffer object made yet */
868 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
869 /* All RB IDs must be Gen'd */
870 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
875 /* create new renderbuffer object */
876 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
878 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
881 ASSERT(newRb
->AllocStorage
);
882 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
883 newRb
->RefCount
= 1; /* referenced by hash table */
890 ASSERT(newRb
!= &DummyRenderbuffer
);
892 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
897 * If the given renderbuffer is anywhere attached to the framebuffer, detach
899 * This is used when a renderbuffer object is deleted.
900 * The spec calls for unbinding.
903 detach_renderbuffer(struct gl_context
*ctx
,
904 struct gl_framebuffer
*fb
,
905 struct gl_renderbuffer
*rb
)
908 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
909 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
910 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
913 invalidate_framebuffer(fb
);
918 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
921 GET_CURRENT_CONTEXT(ctx
);
923 ASSERT_OUTSIDE_BEGIN_END(ctx
);
924 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
926 for (i
= 0; i
< n
; i
++) {
927 if (renderbuffers
[i
] > 0) {
928 struct gl_renderbuffer
*rb
;
929 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
931 /* check if deleting currently bound renderbuffer object */
932 if (rb
== ctx
->CurrentRenderbuffer
) {
934 ASSERT(rb
->RefCount
>= 2);
935 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
938 if (ctx
->DrawBuffer
->Name
) {
939 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
941 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
942 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
945 /* Remove from hash table immediately, to free the ID.
946 * But the object will not be freed until it's no longer
947 * referenced anywhere else.
949 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
951 if (rb
!= &DummyRenderbuffer
) {
952 /* no longer referenced by hash table */
953 _mesa_reference_renderbuffer(&rb
, NULL
);
962 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
964 GET_CURRENT_CONTEXT(ctx
);
968 ASSERT_OUTSIDE_BEGIN_END(ctx
);
971 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
978 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
980 for (i
= 0; i
< n
; i
++) {
981 GLuint name
= first
+ i
;
982 renderbuffers
[i
] = name
;
983 /* insert dummy placeholder into hash table */
984 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
985 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
986 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
992 * Given an internal format token for a render buffer, return the
993 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
994 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
995 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
997 * This is similar to _mesa_base_tex_format() but the set of valid
998 * internal formats is different.
1000 * Note that even if a format is determined to be legal here, validation
1001 * of the FBO may fail if the format is not suppoted by the driver/GPU.
1003 * \param internalFormat as passed to glRenderbufferStorage()
1004 * \return the base internal format, or 0 if internalFormat is illegal
1007 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1010 * Notes: some formats such as alpha, luminance, etc. were added
1011 * with GL_ARB_framebuffer_object.
1013 switch (internalFormat
) {
1019 return ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1023 case GL_LUMINANCE12
:
1024 case GL_LUMINANCE16
:
1025 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1026 case GL_LUMINANCE_ALPHA
:
1027 case GL_LUMINANCE4_ALPHA4
:
1028 case GL_LUMINANCE6_ALPHA2
:
1029 case GL_LUMINANCE8_ALPHA8
:
1030 case GL_LUMINANCE12_ALPHA4
:
1031 case GL_LUMINANCE12_ALPHA12
:
1032 case GL_LUMINANCE16_ALPHA16
:
1033 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1037 case GL_INTENSITY12
:
1038 case GL_INTENSITY16
:
1039 return ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1058 case GL_RGBA16_SNORM
:
1059 case GL_SRGB8_ALPHA8_EXT
:
1061 case GL_STENCIL_INDEX
:
1062 case GL_STENCIL_INDEX1_EXT
:
1063 case GL_STENCIL_INDEX4_EXT
:
1064 case GL_STENCIL_INDEX8_EXT
:
1065 case GL_STENCIL_INDEX16_EXT
:
1066 return GL_STENCIL_INDEX
;
1067 case GL_DEPTH_COMPONENT
:
1068 case GL_DEPTH_COMPONENT16
:
1069 case GL_DEPTH_COMPONENT24
:
1070 case GL_DEPTH_COMPONENT32
:
1071 return GL_DEPTH_COMPONENT
;
1072 case GL_DEPTH_STENCIL_EXT
:
1073 case GL_DEPTH24_STENCIL8_EXT
:
1074 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
1075 return GL_DEPTH_STENCIL_EXT
;
1078 /* XXX add floating point formats eventually */
1085 /** sentinal value, see below */
1086 #define NO_SAMPLES 1000
1090 * Helper function used by _mesa_RenderbufferStorageEXT() and
1091 * _mesa_RenderbufferStorageMultisample().
1092 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1095 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1096 GLsizei width
, GLsizei height
, GLsizei samples
)
1098 const char *func
= samples
== NO_SAMPLES
?
1099 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1100 struct gl_renderbuffer
*rb
;
1102 GET_CURRENT_CONTEXT(ctx
);
1104 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1106 if (target
!= GL_RENDERBUFFER_EXT
) {
1107 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1111 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1112 if (baseFormat
== 0) {
1113 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1117 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1118 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1122 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1123 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1127 if (samples
== NO_SAMPLES
) {
1128 /* NumSamples == 0 indicates non-multisampling */
1131 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1132 /* note: driver may choose to use more samples than what's requested */
1133 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1137 rb
= ctx
->CurrentRenderbuffer
;
1139 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1143 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1145 if (rb
->InternalFormat
== internalFormat
&&
1146 rb
->Width
== (GLuint
) width
&&
1147 rb
->Height
== (GLuint
) height
) {
1148 /* no change in allocation needed */
1152 /* These MUST get set by the AllocStorage func */
1153 rb
->Format
= MESA_FORMAT_NONE
;
1154 rb
->NumSamples
= samples
;
1156 /* Now allocate the storage */
1157 ASSERT(rb
->AllocStorage
);
1158 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1159 /* No error - check/set fields now */
1160 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1161 assert(rb
->Width
== (GLuint
) width
);
1162 assert(rb
->Height
== (GLuint
) height
);
1163 rb
->InternalFormat
= internalFormat
;
1164 rb
->_BaseFormat
= baseFormat
;
1165 assert(rb
->_BaseFormat
!= 0);
1168 /* Probably ran out of memory - clear the fields */
1171 rb
->Format
= MESA_FORMAT_NONE
;
1172 rb
->InternalFormat
= GL_NONE
;
1173 rb
->_BaseFormat
= GL_NONE
;
1178 test_framebuffer_completeness(ctx, fb);
1180 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1186 #if FEATURE_OES_EGL_image
1188 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1190 struct gl_renderbuffer
*rb
;
1191 GET_CURRENT_CONTEXT(ctx
);
1192 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1194 if (!ctx
->Extensions
.OES_EGL_image
) {
1195 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1196 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1200 if (target
!= GL_RENDERBUFFER
) {
1201 _mesa_error(ctx
, GL_INVALID_ENUM
,
1202 "EGLImageTargetRenderbufferStorageOES");
1206 rb
= ctx
->CurrentRenderbuffer
;
1208 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1209 "EGLImageTargetRenderbufferStorageOES");
1213 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1215 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1221 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1222 * _mesa_GetFramebufferAttachmentParameterivEXT()
1223 * We have to be careful to respect the base format. For example, if a
1224 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1225 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1226 * we need to return zero.
1229 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1232 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1233 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1234 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1235 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1236 return _mesa_get_format_bits(format
, pname
);
1239 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1240 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1241 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1242 return _mesa_get_format_bits(format
, pname
);
1245 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1246 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1247 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1248 return _mesa_get_format_bits(format
, pname
);
1251 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1252 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1253 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1254 baseFormat
== GL_LUMINANCE_ALPHA
)
1255 return _mesa_get_format_bits(format
, pname
);
1258 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1259 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1260 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1261 return _mesa_get_format_bits(format
, pname
);
1264 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1265 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1266 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1267 return _mesa_get_format_bits(format
, pname
);
1278 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1279 GLsizei width
, GLsizei height
)
1281 /* GL_ARB_fbo says calling this function is equivalent to calling
1282 * glRenderbufferStorageMultisample() with samples=0. We pass in
1283 * a token value here just for error reporting purposes.
1285 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1290 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1291 GLenum internalFormat
,
1292 GLsizei width
, GLsizei height
)
1294 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1299 * OpenGL ES version of glRenderBufferStorage.
1302 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1303 GLsizei width
, GLsizei height
)
1305 switch (internalFormat
) {
1307 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1308 /* choose a closest format */
1309 internalFormat
= GL_RGB5
;
1315 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1320 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1322 struct gl_renderbuffer
*rb
;
1323 GET_CURRENT_CONTEXT(ctx
);
1325 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1327 if (target
!= GL_RENDERBUFFER_EXT
) {
1328 _mesa_error(ctx
, GL_INVALID_ENUM
,
1329 "glGetRenderbufferParameterivEXT(target)");
1333 rb
= ctx
->CurrentRenderbuffer
;
1335 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1336 "glGetRenderbufferParameterivEXT");
1340 /* No need to flush here since we're just quering state which is
1341 * not effected by rendering.
1345 case GL_RENDERBUFFER_WIDTH_EXT
:
1346 *params
= rb
->Width
;
1348 case GL_RENDERBUFFER_HEIGHT_EXT
:
1349 *params
= rb
->Height
;
1351 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1352 *params
= rb
->InternalFormat
;
1354 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1355 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1356 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1357 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1358 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1359 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1360 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1362 case GL_RENDERBUFFER_SAMPLES
:
1363 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1364 *params
= rb
->NumSamples
;
1369 _mesa_error(ctx
, GL_INVALID_ENUM
,
1370 "glGetRenderbufferParameterivEXT(target)");
1376 GLboolean GLAPIENTRY
1377 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1379 GET_CURRENT_CONTEXT(ctx
);
1380 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1382 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1383 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1391 * Check if any of the attachments of the given framebuffer are textures
1392 * (render to texture). Call ctx->Driver.RenderTexture() for such
1396 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1399 ASSERT(ctx
->Driver
.RenderTexture
);
1402 return; /* can't render to texture with winsys framebuffers */
1404 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1405 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1406 struct gl_texture_object
*texObj
= att
->Texture
;
1408 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1409 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1416 * Examine all the framebuffer's attachments to see if any are textures.
1417 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1418 * notify the device driver that the texture image may have changed.
1421 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1424 return; /* can't render to texture with winsys framebuffers */
1426 if (ctx
->Driver
.FinishRenderTexture
) {
1428 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1429 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1430 if (att
->Texture
&& att
->Renderbuffer
) {
1431 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1439 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1441 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1442 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1443 GLboolean bindReadBuf
, bindDrawBuf
;
1444 GET_CURRENT_CONTEXT(ctx
);
1447 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1448 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1449 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1453 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1455 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1457 "glBindFramebufferEXT(unsupported)");
1462 #if FEATURE_EXT_framebuffer_blit
1463 case GL_DRAW_FRAMEBUFFER_EXT
:
1464 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1465 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1468 bindDrawBuf
= GL_TRUE
;
1469 bindReadBuf
= GL_FALSE
;
1471 case GL_READ_FRAMEBUFFER_EXT
:
1472 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1473 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1476 bindDrawBuf
= GL_FALSE
;
1477 bindReadBuf
= GL_TRUE
;
1480 case GL_FRAMEBUFFER_EXT
:
1481 bindDrawBuf
= GL_TRUE
;
1482 bindReadBuf
= GL_TRUE
;
1485 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1490 /* Binding a user-created framebuffer object */
1491 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1492 if (newDrawFb
== &DummyFramebuffer
) {
1493 /* ID was reserved, but no real framebuffer object made yet */
1496 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1497 /* All FBO IDs must be Gen'd */
1498 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1503 /* create new framebuffer object */
1504 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1506 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1509 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1511 newReadFb
= newDrawFb
;
1514 /* Binding the window system framebuffer (which was originally set
1515 * with MakeCurrent).
1517 newDrawFb
= ctx
->WinSysDrawBuffer
;
1518 newReadFb
= ctx
->WinSysReadBuffer
;
1522 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1524 /* save pointers to current/old framebuffers */
1525 oldDrawFb
= ctx
->DrawBuffer
;
1526 oldReadFb
= ctx
->ReadBuffer
;
1528 /* check if really changing bindings */
1529 if (oldDrawFb
== newDrawFb
)
1530 bindDrawBuf
= GL_FALSE
;
1531 if (oldReadFb
== newReadFb
)
1532 bindReadBuf
= GL_FALSE
;
1535 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1537 * We also check if we're beginning and/or ending render-to-texture.
1538 * When a framebuffer with texture attachments is unbound, call
1539 * ctx->Driver.FinishRenderTexture().
1540 * When a framebuffer with texture attachments is bound, call
1541 * ctx->Driver.RenderTexture().
1543 * Note that if the ReadBuffer has texture attachments we don't consider
1544 * that a render-to-texture case.
1547 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1549 /* check if old readbuffer was render-to-texture */
1550 check_end_texture_render(ctx
, oldReadFb
);
1552 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1556 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1558 /* check if old read/draw buffers were render-to-texture */
1560 check_end_texture_render(ctx
, oldReadFb
);
1562 if (oldDrawFb
!= oldReadFb
)
1563 check_end_texture_render(ctx
, oldDrawFb
);
1565 /* check if newly bound framebuffer has any texture attachments */
1566 check_begin_texture_render(ctx
, newDrawFb
);
1568 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1571 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1572 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1578 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1581 GET_CURRENT_CONTEXT(ctx
);
1583 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1584 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1586 for (i
= 0; i
< n
; i
++) {
1587 if (framebuffers
[i
] > 0) {
1588 struct gl_framebuffer
*fb
;
1589 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1591 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1593 /* check if deleting currently bound framebuffer object */
1594 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1595 /* separate draw/read binding points */
1596 if (fb
== ctx
->DrawBuffer
) {
1598 ASSERT(fb
->RefCount
>= 2);
1599 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1601 if (fb
== ctx
->ReadBuffer
) {
1603 ASSERT(fb
->RefCount
>= 2);
1604 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1608 /* only one binding point for read/draw buffers */
1609 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1611 ASSERT(fb
->RefCount
>= 2);
1612 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1616 /* remove from hash table immediately, to free the ID */
1617 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1619 if (fb
!= &DummyFramebuffer
) {
1620 /* But the object will not be freed until it's no longer
1621 * bound in any context.
1623 _mesa_reference_framebuffer(&fb
, NULL
);
1632 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1634 GET_CURRENT_CONTEXT(ctx
);
1638 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1641 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1648 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1650 for (i
= 0; i
< n
; i
++) {
1651 GLuint name
= first
+ i
;
1652 framebuffers
[i
] = name
;
1653 /* insert dummy placeholder into hash table */
1654 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1655 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1656 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1663 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1665 struct gl_framebuffer
*buffer
;
1666 GET_CURRENT_CONTEXT(ctx
);
1668 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1671 #if FEATURE_EXT_framebuffer_blit
1672 case GL_DRAW_FRAMEBUFFER_EXT
:
1673 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1674 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1677 buffer
= ctx
->DrawBuffer
;
1679 case GL_READ_FRAMEBUFFER_EXT
:
1680 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1681 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1684 buffer
= ctx
->ReadBuffer
;
1687 case GL_FRAMEBUFFER_EXT
:
1688 buffer
= ctx
->DrawBuffer
;
1691 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1692 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1695 if (buffer
->Name
== 0) {
1696 /* The window system / default framebuffer is always complete */
1697 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1700 /* No need to flush here */
1702 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1703 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1706 return buffer
->_Status
;
1712 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1715 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1716 GLenum attachment
, GLenum textarget
, GLuint texture
,
1717 GLint level
, GLint zoffset
)
1719 struct gl_renderbuffer_attachment
*att
;
1720 struct gl_texture_object
*texObj
= NULL
;
1721 struct gl_framebuffer
*fb
;
1722 GLboolean error
= GL_FALSE
;
1724 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1727 case GL_READ_FRAMEBUFFER_EXT
:
1728 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1729 fb
= ctx
->ReadBuffer
;
1731 case GL_DRAW_FRAMEBUFFER_EXT
:
1732 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1734 case GL_FRAMEBUFFER_EXT
:
1735 fb
= ctx
->DrawBuffer
;
1742 _mesa_error(ctx
, GL_INVALID_ENUM
,
1743 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1749 /* check framebuffer binding */
1750 if (fb
->Name
== 0) {
1751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1752 "glFramebufferTexture%sEXT", caller
);
1757 /* The textarget, level, and zoffset parameters are only validated if
1758 * texture is non-zero.
1761 GLboolean err
= GL_TRUE
;
1763 texObj
= _mesa_lookup_texture(ctx
, texture
);
1764 if (texObj
!= NULL
) {
1765 if (textarget
== 0) {
1766 /* XXX what's the purpose of this? */
1767 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1768 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1769 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1772 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1773 ? !IS_CUBE_FACE(textarget
)
1774 : (texObj
->Target
!= textarget
);
1778 /* can't render to a non-existant texture */
1779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1780 "glFramebufferTexture%sEXT(non existant texture)",
1786 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1787 "glFramebufferTexture%sEXT(texture target mismatch)",
1792 if (texObj
->Target
== GL_TEXTURE_3D
) {
1793 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1794 if (zoffset
< 0 || zoffset
>= maxSize
) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
,
1796 "glFramebufferTexture%sEXT(zoffset)", caller
);
1800 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1801 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1802 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glFramebufferTexture%sEXT(layer)", caller
);
1810 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1811 _mesa_error(ctx
, GL_INVALID_VALUE
,
1812 "glFramebufferTexture%sEXT(level)", caller
);
1817 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1819 _mesa_error(ctx
, GL_INVALID_ENUM
,
1820 "glFramebufferTexture%sEXT(attachment)", caller
);
1824 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1826 _glthread_LOCK_MUTEX(fb
->Mutex
);
1828 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1830 /* Set the render-to-texture flag. We'll check this flag in
1831 * glTexImage() and friends to determine if we need to revalidate
1832 * any FBOs that might be rendering into this texture.
1833 * This flag never gets cleared since it's non-trivial to determine
1834 * when all FBOs might be done rendering to this texture. That's OK
1835 * though since it's uncommon to render to a texture then repeatedly
1836 * call glTexImage() to change images in the texture.
1838 texObj
->_RenderToTexture
= GL_TRUE
;
1841 _mesa_remove_attachment(ctx
, att
);
1844 invalidate_framebuffer(fb
);
1846 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1852 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1853 GLenum textarget
, GLuint texture
, GLint level
)
1855 GET_CURRENT_CONTEXT(ctx
);
1857 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1858 _mesa_error(ctx
, GL_INVALID_ENUM
,
1859 "glFramebufferTexture1DEXT(textarget)");
1863 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1869 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1870 GLenum textarget
, GLuint texture
, GLint level
)
1872 GET_CURRENT_CONTEXT(ctx
);
1874 if ((texture
!= 0) &&
1875 (textarget
!= GL_TEXTURE_2D
) &&
1876 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1877 (!IS_CUBE_FACE(textarget
))) {
1878 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1879 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1883 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1889 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1890 GLenum textarget
, GLuint texture
,
1891 GLint level
, GLint zoffset
)
1893 GET_CURRENT_CONTEXT(ctx
);
1895 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1896 _mesa_error(ctx
, GL_INVALID_ENUM
,
1897 "glFramebufferTexture3DEXT(textarget)");
1901 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1907 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1908 GLuint texture
, GLint level
, GLint layer
)
1910 GET_CURRENT_CONTEXT(ctx
);
1912 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1918 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1919 GLenum renderbufferTarget
,
1920 GLuint renderbuffer
)
1922 struct gl_renderbuffer_attachment
*att
;
1923 struct gl_framebuffer
*fb
;
1924 struct gl_renderbuffer
*rb
;
1925 GET_CURRENT_CONTEXT(ctx
);
1927 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1930 #if FEATURE_EXT_framebuffer_blit
1931 case GL_DRAW_FRAMEBUFFER_EXT
:
1932 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1933 _mesa_error(ctx
, GL_INVALID_ENUM
,
1934 "glFramebufferRenderbufferEXT(target)");
1937 fb
= ctx
->DrawBuffer
;
1939 case GL_READ_FRAMEBUFFER_EXT
:
1940 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1941 _mesa_error(ctx
, GL_INVALID_ENUM
,
1942 "glFramebufferRenderbufferEXT(target)");
1945 fb
= ctx
->ReadBuffer
;
1948 case GL_FRAMEBUFFER_EXT
:
1949 fb
= ctx
->DrawBuffer
;
1952 _mesa_error(ctx
, GL_INVALID_ENUM
,
1953 "glFramebufferRenderbufferEXT(target)");
1957 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1958 _mesa_error(ctx
, GL_INVALID_ENUM
,
1959 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1963 if (fb
->Name
== 0) {
1964 /* Can't attach new renderbuffers to a window system framebuffer */
1965 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1969 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1971 _mesa_error(ctx
, GL_INVALID_ENUM
,
1972 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1973 _mesa_lookup_enum_by_nr(attachment
));
1978 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1980 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1981 "glFramebufferRenderbufferEXT(non-existant"
1982 " renderbuffer %u)", renderbuffer
);
1985 else if (rb
== &DummyRenderbuffer
) {
1986 /* This is what NVIDIA does */
1987 _mesa_error(ctx
, GL_INVALID_VALUE
,
1988 "glFramebufferRenderbufferEXT(renderbuffer %u)",
1994 /* remove renderbuffer attachment */
1998 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1999 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2000 /* make sure the renderbuffer is a depth/stencil format */
2001 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2002 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2004 "glFramebufferRenderbufferEXT(renderbuffer"
2005 " is not DEPTH_STENCIL format)");
2011 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2013 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2014 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2016 /* Some subsequent GL commands may depend on the framebuffer's visual
2017 * after the binding is updated. Update visual info now.
2019 _mesa_update_framebuffer_visual(ctx
, fb
);
2024 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2025 GLenum pname
, GLint
*params
)
2027 const struct gl_renderbuffer_attachment
*att
;
2028 struct gl_framebuffer
*buffer
;
2029 GET_CURRENT_CONTEXT(ctx
);
2031 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2034 #if FEATURE_EXT_framebuffer_blit
2035 case GL_DRAW_FRAMEBUFFER_EXT
:
2036 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2037 _mesa_error(ctx
, GL_INVALID_ENUM
,
2038 "glGetFramebufferAttachmentParameterivEXT(target)");
2041 buffer
= ctx
->DrawBuffer
;
2043 case GL_READ_FRAMEBUFFER_EXT
:
2044 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2045 _mesa_error(ctx
, GL_INVALID_ENUM
,
2046 "glGetFramebufferAttachmentParameterivEXT(target)");
2049 buffer
= ctx
->ReadBuffer
;
2052 case GL_FRAMEBUFFER_EXT
:
2053 buffer
= ctx
->DrawBuffer
;
2056 _mesa_error(ctx
, GL_INVALID_ENUM
,
2057 "glGetFramebufferAttachmentParameterivEXT(target)");
2061 if (buffer
->Name
== 0) {
2062 /* the default / window-system FBO */
2063 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2066 /* user-created framebuffer FBO */
2067 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2071 _mesa_error(ctx
, GL_INVALID_ENUM
,
2072 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2076 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2077 /* the depth and stencil attachments must point to the same buffer */
2078 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2079 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2080 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2081 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2082 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2083 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2084 " attachments differ)");
2089 /* No need to flush here */
2092 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2093 *params
= buffer
->Name
== 0 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2095 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2096 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2097 *params
= att
->Renderbuffer
->Name
;
2099 else if (att
->Type
== GL_TEXTURE
) {
2100 *params
= att
->Texture
->Name
;
2103 assert(att
->Type
== GL_NONE
);
2107 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2108 if (att
->Type
== GL_TEXTURE
) {
2109 *params
= att
->TextureLevel
;
2112 _mesa_error(ctx
, GL_INVALID_ENUM
,
2113 "glGetFramebufferAttachmentParameterivEXT(pname)");
2116 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2117 if (att
->Type
== GL_TEXTURE
) {
2118 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2119 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2126 _mesa_error(ctx
, GL_INVALID_ENUM
,
2127 "glGetFramebufferAttachmentParameterivEXT(pname)");
2130 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2131 if (att
->Type
== GL_TEXTURE
) {
2132 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2133 *params
= att
->Zoffset
;
2140 _mesa_error(ctx
, GL_INVALID_ENUM
,
2141 "glGetFramebufferAttachmentParameterivEXT(pname)");
2144 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2145 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2146 _mesa_error(ctx
, GL_INVALID_ENUM
,
2147 "glGetFramebufferAttachmentParameterivEXT(pname)");
2150 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2151 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2154 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2155 * if the sRGB conversion is unsupported. */
2156 *params
= GL_LINEAR
;
2160 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2161 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2162 _mesa_error(ctx
, GL_INVALID_ENUM
,
2163 "glGetFramebufferAttachmentParameterivEXT(pname)");
2167 gl_format format
= att
->Renderbuffer
->Format
;
2168 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2173 *params
= _mesa_get_format_datatype(format
);
2177 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2178 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2179 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2180 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2181 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2182 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2183 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2184 _mesa_error(ctx
, GL_INVALID_ENUM
,
2185 "glGetFramebufferAttachmentParameterivEXT(pname)");
2187 else if (att
->Texture
) {
2188 const struct gl_texture_image
*texImage
=
2189 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2192 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2193 texImage
->TexFormat
);
2199 else if (att
->Renderbuffer
) {
2200 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2201 att
->Renderbuffer
->Format
);
2208 _mesa_error(ctx
, GL_INVALID_ENUM
,
2209 "glGetFramebufferAttachmentParameterivEXT(pname)");
2216 _mesa_GenerateMipmapEXT(GLenum target
)
2218 struct gl_texture_object
*texObj
;
2219 GET_CURRENT_CONTEXT(ctx
);
2221 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2222 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2228 case GL_TEXTURE_CUBE_MAP
:
2229 /* OK, legal value */
2232 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2233 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2237 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2239 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2244 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2245 !_mesa_cube_complete(texObj
)) {
2246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2247 "glGenerateMipmap(incomplete cube map)");
2251 _mesa_lock_texture(ctx
, texObj
);
2252 if (target
== GL_TEXTURE_CUBE_MAP
) {
2254 for (face
= 0; face
< 6; face
++)
2255 ctx
->Driver
.GenerateMipmap(ctx
,
2256 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2260 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2262 _mesa_unlock_texture(ctx
, texObj
);
2266 #if FEATURE_EXT_framebuffer_blit
2268 static const struct gl_renderbuffer_attachment
*
2269 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2272 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2273 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2274 return &fb
->Attachment
[i
];
2282 * Blit rectangular region, optionally from one framebuffer to another.
2284 * Note, if the src buffer is multisampled and the dest is not, this is
2285 * when the samples must be resolved to a single color.
2288 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2289 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2290 GLbitfield mask
, GLenum filter
)
2292 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2293 GL_DEPTH_BUFFER_BIT
|
2294 GL_STENCIL_BUFFER_BIT
);
2295 const struct gl_framebuffer
*readFb
, *drawFb
;
2296 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2297 GET_CURRENT_CONTEXT(ctx
);
2299 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2300 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2302 if (ctx
->NewState
) {
2303 _mesa_update_state(ctx
);
2306 readFb
= ctx
->ReadBuffer
;
2307 drawFb
= ctx
->DrawBuffer
;
2309 if (!readFb
|| !drawFb
) {
2310 /* This will normally never happen but someday we may want to
2311 * support MakeCurrent() with no drawables.
2316 /* check for complete framebuffers */
2317 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2318 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2319 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2320 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2324 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2325 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2329 if (mask
& ~legalMaskBits
) {
2330 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2334 /* depth/stencil must be blitted with nearest filtering */
2335 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2336 && filter
!= GL_NEAREST
) {
2337 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2338 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2342 /* get color read/draw renderbuffers */
2343 if (mask
& GL_COLOR_BUFFER_BIT
) {
2344 colorReadRb
= readFb
->_ColorReadBuffer
;
2345 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2348 colorReadRb
= colorDrawRb
= NULL
;
2351 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2352 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2353 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2356 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2357 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2358 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2359 "glBlitFramebufferEXT(stencil buffer size mismatch");
2364 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2365 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2366 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2369 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2370 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2371 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2372 "glBlitFramebufferEXT(depth buffer size mismatch");
2377 if (readFb
->Visual
.samples
> 0 &&
2378 drawFb
->Visual
.samples
> 0 &&
2379 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2381 "glBlitFramebufferEXT(mismatched samples");
2385 /* extra checks for multisample copies... */
2386 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2387 /* src and dest region sizes must be the same */
2388 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2389 srcY1
- srcY0
!= dstY1
- dstY0
) {
2390 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2391 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2395 /* color formats must match */
2398 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2400 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2405 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2406 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2412 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2414 srcX0
, srcY0
, srcX1
, srcY1
,
2415 dstX0
, dstY0
, dstX1
, dstY1
,
2418 const struct gl_renderbuffer_attachment
*att
;
2420 att
= find_attachment(readFb
, colorReadRb
);
2421 printf(" Src FBO %u RB %u (%dx%d) ",
2422 readFb
->Name
, colorReadRb
->Name
,
2423 colorReadRb
->Width
, colorReadRb
->Height
);
2424 if (att
&& att
->Texture
) {
2425 printf("Tex %u tgt 0x%x level %u face %u",
2427 att
->Texture
->Target
,
2433 att
= find_attachment(drawFb
, colorDrawRb
);
2434 printf(" Dst FBO %u RB %u (%dx%d) ",
2435 drawFb
->Name
, colorDrawRb
->Name
,
2436 colorDrawRb
->Width
, colorDrawRb
->Height
);
2437 if (att
&& att
->Texture
) {
2438 printf("Tex %u tgt 0x%x level %u face %u",
2440 att
->Texture
->Target
,
2448 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2449 ctx
->Driver
.BlitFramebuffer(ctx
,
2450 srcX0
, srcY0
, srcX1
, srcY1
,
2451 dstX0
, dstY0
, dstX1
, dstY1
,
2454 #endif /* FEATURE_EXT_framebuffer_blit */
2456 #if FEATURE_ARB_geometry_shader4
2458 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2459 GLuint texture
, GLint level
)
2461 GET_CURRENT_CONTEXT(ctx
);
2462 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2463 "glFramebufferTextureARB "
2464 "not implemented!");
2468 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2469 GLuint texture
, GLint level
, GLenum face
)
2471 GET_CURRENT_CONTEXT(ctx
);
2472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2473 "glFramebufferTextureFaceARB "
2474 "not implemented!");
2476 #endif /* FEATURE_ARB_geometry_shader4 */