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 static INLINE GLboolean
82 is_cube_face(GLenum target
)
84 return (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
85 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
);
90 * Is the given FBO a user-created FBO?
92 static INLINE GLboolean
93 is_user_fbo(const struct gl_framebuffer
*fb
)
100 * Is the given FBO a window system FBO (like an X window)?
102 static INLINE GLboolean
103 is_winsys_fbo(const struct gl_framebuffer
*fb
)
105 return fb
->Name
== 0;
110 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
116 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
123 _mesa_init_fbobjects(struct gl_context
*ctx
)
125 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
126 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
127 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
128 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
129 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
130 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
133 struct gl_framebuffer
*
134 _mesa_get_incomplete_framebuffer(void)
136 return &IncompleteFramebuffer
;
140 * Helper routine for getting a gl_renderbuffer.
142 struct gl_renderbuffer
*
143 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
145 struct gl_renderbuffer
*rb
;
150 rb
= (struct gl_renderbuffer
*)
151 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
157 * Helper routine for getting a gl_framebuffer.
159 struct gl_framebuffer
*
160 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
162 struct gl_framebuffer
*fb
;
167 fb
= (struct gl_framebuffer
*)
168 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
174 * Mark the given framebuffer as invalid. This will force the
175 * test for framebuffer completeness to be done before the framebuffer
179 invalidate_framebuffer(struct gl_framebuffer
*fb
)
181 fb
->_Status
= 0; /* "indeterminate" */
186 * Return the gl_framebuffer object which corresponds to the given
187 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
188 * Check support for GL_EXT_framebuffer_blit to determine if certain
190 * \return gl_framebuffer pointer or NULL if target is illegal
192 static struct gl_framebuffer
*
193 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
196 case GL_DRAW_FRAMEBUFFER
:
197 return ctx
->Extensions
.EXT_framebuffer_blit
? ctx
->DrawBuffer
: NULL
;
198 case GL_READ_FRAMEBUFFER
:
199 return ctx
->Extensions
.EXT_framebuffer_blit
? ctx
->ReadBuffer
: NULL
;
200 case GL_FRAMEBUFFER_EXT
:
201 return ctx
->DrawBuffer
;
209 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
210 * gl_renderbuffer_attachment object.
211 * This function is only used for user-created FB objects, not the
212 * default / window-system FB object.
213 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
214 * the depth buffer attachment point.
216 struct gl_renderbuffer_attachment
*
217 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
222 assert(is_user_fbo(fb
));
224 switch (attachment
) {
225 case GL_COLOR_ATTACHMENT0_EXT
:
226 case GL_COLOR_ATTACHMENT1_EXT
:
227 case GL_COLOR_ATTACHMENT2_EXT
:
228 case GL_COLOR_ATTACHMENT3_EXT
:
229 case GL_COLOR_ATTACHMENT4_EXT
:
230 case GL_COLOR_ATTACHMENT5_EXT
:
231 case GL_COLOR_ATTACHMENT6_EXT
:
232 case GL_COLOR_ATTACHMENT7_EXT
:
233 case GL_COLOR_ATTACHMENT8_EXT
:
234 case GL_COLOR_ATTACHMENT9_EXT
:
235 case GL_COLOR_ATTACHMENT10_EXT
:
236 case GL_COLOR_ATTACHMENT11_EXT
:
237 case GL_COLOR_ATTACHMENT12_EXT
:
238 case GL_COLOR_ATTACHMENT13_EXT
:
239 case GL_COLOR_ATTACHMENT14_EXT
:
240 case GL_COLOR_ATTACHMENT15_EXT
:
241 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
242 if (i
>= ctx
->Const
.MaxColorAttachments
) {
245 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
246 case GL_DEPTH_STENCIL_ATTACHMENT
:
248 case GL_DEPTH_BUFFER
:
249 /* fall-through / new in GL 3.0 */
250 case GL_DEPTH_ATTACHMENT_EXT
:
251 return &fb
->Attachment
[BUFFER_DEPTH
];
252 case GL_STENCIL_BUFFER
:
253 /* fall-through / new in GL 3.0 */
254 case GL_STENCIL_ATTACHMENT_EXT
:
255 return &fb
->Attachment
[BUFFER_STENCIL
];
263 * As above, but only used for getting attachments of the default /
264 * window-system framebuffer (not user-created framebuffer objects).
266 static struct gl_renderbuffer_attachment
*
267 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
270 assert(is_winsys_fbo(fb
));
272 switch (attachment
) {
274 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
276 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
278 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
280 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
282 if (fb
->Visual
.numAuxBuffers
== 1) {
283 return &fb
->Attachment
[BUFFER_AUX0
];
286 case GL_DEPTH_BUFFER
:
287 /* fall-through / new in GL 3.0 */
288 case GL_DEPTH_ATTACHMENT_EXT
:
289 return &fb
->Attachment
[BUFFER_DEPTH
];
290 case GL_STENCIL_BUFFER
:
291 /* fall-through / new in GL 3.0 */
292 case GL_STENCIL_ATTACHMENT_EXT
:
293 return &fb
->Attachment
[BUFFER_STENCIL
];
302 * Remove any texture or renderbuffer attached to the given attachment
303 * point. Update reference counts, etc.
306 _mesa_remove_attachment(struct gl_context
*ctx
,
307 struct gl_renderbuffer_attachment
*att
)
309 if (att
->Type
== GL_TEXTURE
) {
310 ASSERT(att
->Texture
);
311 if (ctx
->Driver
.FinishRenderTexture
) {
312 /* tell driver that we're done rendering to this texture. */
313 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
315 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
316 ASSERT(!att
->Texture
);
318 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
319 ASSERT(!att
->Texture
);
320 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
321 ASSERT(!att
->Renderbuffer
);
324 att
->Complete
= GL_TRUE
;
329 * Bind a texture object to an attachment point.
330 * The previous binding, if any, will be removed first.
333 _mesa_set_texture_attachment(struct gl_context
*ctx
,
334 struct gl_framebuffer
*fb
,
335 struct gl_renderbuffer_attachment
*att
,
336 struct gl_texture_object
*texObj
,
337 GLenum texTarget
, GLuint level
, GLuint zoffset
)
339 if (att
->Texture
== texObj
) {
340 /* re-attaching same texture */
341 ASSERT(att
->Type
== GL_TEXTURE
);
342 if (ctx
->Driver
.FinishRenderTexture
)
343 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
347 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
348 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
349 _mesa_remove_attachment(ctx
, att
);
350 att
->Type
= GL_TEXTURE
;
351 assert(!att
->Texture
);
352 _mesa_reference_texobj(&att
->Texture
, texObj
);
355 /* always update these fields */
356 att
->TextureLevel
= level
;
357 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
358 att
->Zoffset
= zoffset
;
359 att
->Complete
= GL_FALSE
;
361 if (_mesa_get_attachment_teximage(att
)) {
362 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
365 invalidate_framebuffer(fb
);
370 * Bind a renderbuffer to an attachment point.
371 * The previous binding, if any, will be removed first.
374 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
375 struct gl_renderbuffer_attachment
*att
,
376 struct gl_renderbuffer
*rb
)
378 /* XXX check if re-doing same attachment, exit early */
379 _mesa_remove_attachment(ctx
, att
);
380 att
->Type
= GL_RENDERBUFFER_EXT
;
381 att
->Texture
= NULL
; /* just to be safe */
382 att
->Complete
= GL_FALSE
;
383 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
388 * Fallback for ctx->Driver.FramebufferRenderbuffer()
389 * Attach a renderbuffer object to a framebuffer object.
392 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
393 struct gl_framebuffer
*fb
,
394 GLenum attachment
, struct gl_renderbuffer
*rb
)
396 struct gl_renderbuffer_attachment
*att
;
398 _glthread_LOCK_MUTEX(fb
->Mutex
);
400 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
403 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
404 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
405 /* do stencil attachment here (depth already done above) */
406 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
408 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
410 rb
->AttachedAnytime
= GL_TRUE
;
413 _mesa_remove_attachment(ctx
, att
);
416 invalidate_framebuffer(fb
);
418 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
423 * Fallback for ctx->Driver.ValidateFramebuffer()
424 * Check if the renderbuffer's formats are supported by the software
426 * Drivers should probably override this.
429 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
432 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
433 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
435 switch (rb
->_BaseFormat
) {
437 case GL_LUMINANCE_ALPHA
:
442 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
446 switch (rb
->Format
) {
447 /* XXX This list is likely incomplete. */
448 case MESA_FORMAT_RGB9_E5_FLOAT
:
449 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
452 /* render buffer format is supported by software rendering */
464 att_incomplete(const char *msg
)
467 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
478 fbo_incomplete(const char *msg
, int index
)
481 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
490 * Is the given base format a legal format for a color renderbuffer?
493 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
495 switch (baseFormat
) {
500 case GL_LUMINANCE_ALPHA
:
503 return ctx
->Extensions
.ARB_framebuffer_object
;
506 return ctx
->Extensions
.ARB_texture_rg
;
514 * Is the given base format a legal format for a depth/stencil renderbuffer?
517 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
519 switch (baseFormat
) {
520 case GL_DEPTH_COMPONENT
:
521 case GL_DEPTH_STENCIL_EXT
:
530 * Test if an attachment point is complete and update its Complete field.
531 * \param format if GL_COLOR, this is a color attachment point,
532 * if GL_DEPTH, this is a depth component attachment point,
533 * if GL_STENCIL, this is a stencil component attachment point.
536 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
537 struct gl_renderbuffer_attachment
*att
)
539 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
541 /* assume complete */
542 att
->Complete
= GL_TRUE
;
544 /* Look for reasons why the attachment might be incomplete */
545 if (att
->Type
== GL_TEXTURE
) {
546 const struct gl_texture_object
*texObj
= att
->Texture
;
547 struct gl_texture_image
*texImage
;
551 att_incomplete("no texobj");
552 att
->Complete
= GL_FALSE
;
556 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
558 att_incomplete("no teximage");
559 att
->Complete
= GL_FALSE
;
562 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
563 att_incomplete("teximage width/height=0");
564 printf("texobj = %u\n", texObj
->Name
);
565 printf("level = %d\n", att
->TextureLevel
);
566 att
->Complete
= GL_FALSE
;
569 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
570 att_incomplete("bad z offset");
571 att
->Complete
= GL_FALSE
;
575 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
577 if (format
== GL_COLOR
) {
578 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
579 att_incomplete("bad format");
580 att
->Complete
= GL_FALSE
;
583 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
584 att_incomplete("compressed internalformat");
585 att
->Complete
= GL_FALSE
;
589 else if (format
== GL_DEPTH
) {
590 if (baseFormat
== GL_DEPTH_COMPONENT
) {
593 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
594 ctx
->Extensions
.ARB_depth_texture
&&
595 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
599 att
->Complete
= GL_FALSE
;
600 att_incomplete("bad depth format");
605 ASSERT(format
== GL_STENCIL
);
606 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
607 ctx
->Extensions
.ARB_depth_texture
&&
608 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
612 /* no such thing as stencil-only textures */
613 att_incomplete("illegal stencil texture");
614 att
->Complete
= GL_FALSE
;
619 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
620 const GLenum baseFormat
=
621 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
623 ASSERT(att
->Renderbuffer
);
624 if (!att
->Renderbuffer
->InternalFormat
||
625 att
->Renderbuffer
->Width
< 1 ||
626 att
->Renderbuffer
->Height
< 1) {
627 att_incomplete("0x0 renderbuffer");
628 att
->Complete
= GL_FALSE
;
631 if (format
== GL_COLOR
) {
632 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
633 att_incomplete("bad renderbuffer color format");
634 att
->Complete
= GL_FALSE
;
638 else if (format
== GL_DEPTH
) {
639 if (baseFormat
== GL_DEPTH_COMPONENT
) {
642 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
643 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
647 att_incomplete("bad renderbuffer depth format");
648 att
->Complete
= GL_FALSE
;
653 assert(format
== GL_STENCIL
);
654 if (baseFormat
== GL_STENCIL_INDEX
) {
657 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
658 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
662 att
->Complete
= GL_FALSE
;
663 att_incomplete("bad renderbuffer stencil format");
669 ASSERT(att
->Type
== GL_NONE
);
677 * Test if the given framebuffer object is complete and update its
678 * Status field with the results.
679 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
680 * driver to make hardware-specific validation/completeness checks.
681 * Also update the framebuffer's Width and Height fields if the
682 * framebuffer is complete.
685 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
686 struct gl_framebuffer
*fb
)
689 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
690 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
691 GLint numSamples
= -1;
695 assert(is_user_fbo(fb
));
701 /* Start at -2 to more easily loop over all attachment points.
706 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
707 struct gl_renderbuffer_attachment
*att
;
712 * XXX for ARB_fbo, only check color buffers that are named by
713 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
716 /* check for attachment completeness
719 att
= &fb
->Attachment
[BUFFER_DEPTH
];
720 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
721 if (!att
->Complete
) {
722 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
723 fbo_incomplete("depth attachment incomplete", -1);
728 att
= &fb
->Attachment
[BUFFER_STENCIL
];
729 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
730 if (!att
->Complete
) {
731 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
732 fbo_incomplete("stencil attachment incomplete", -1);
737 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
738 test_attachment_completeness(ctx
, GL_COLOR
, att
);
739 if (!att
->Complete
) {
740 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
741 fbo_incomplete("color attachment incomplete", i
);
746 /* get width, height, format of the renderbuffer/texture
748 if (att
->Type
== GL_TEXTURE
) {
749 const struct gl_texture_image
*texImg
=
750 _mesa_get_attachment_teximage(att
);
751 minWidth
= MIN2(minWidth
, texImg
->Width
);
752 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
753 minHeight
= MIN2(minHeight
, texImg
->Height
);
754 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
755 f
= texImg
->_BaseFormat
;
756 attFormat
= texImg
->TexFormat
;
758 if (!_mesa_is_legal_color_format(ctx
, f
) &&
759 !is_legal_depth_format(ctx
, f
)) {
760 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
761 fbo_incomplete("texture attachment incomplete", -1);
765 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
766 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
767 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
768 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
769 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
770 f
= att
->Renderbuffer
->InternalFormat
;
771 attFormat
= att
->Renderbuffer
->Format
;
775 assert(att
->Type
== GL_NONE
);
779 if (att
->Renderbuffer
&& numSamples
< 0) {
781 numSamples
= att
->Renderbuffer
->NumSamples
;
784 /* check if integer color */
785 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
787 /* Error-check width, height, format, samples
789 if (numImages
== 1) {
790 /* save format, num samples */
796 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
797 /* check that width, height, format are same */
798 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
799 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
800 fbo_incomplete("width or height mismatch", -1);
803 /* check that all color buffer have same format */
804 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
805 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
806 fbo_incomplete("format mismatch", -1);
810 if (att
->Renderbuffer
&&
811 att
->Renderbuffer
->NumSamples
!= numSamples
) {
812 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
813 fbo_incomplete("inconsistant number of samples", i
);
821 if (ctx
->API
== API_OPENGL
&& !ctx
->Extensions
.ARB_ES2_compatibility
) {
822 /* Check that all DrawBuffers are present */
823 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
824 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
825 const struct gl_renderbuffer_attachment
*att
826 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
828 if (att
->Type
== GL_NONE
) {
829 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
830 fbo_incomplete("missing drawbuffer", j
);
836 /* Check that the ReadBuffer is present */
837 if (fb
->ColorReadBuffer
!= GL_NONE
) {
838 const struct gl_renderbuffer_attachment
*att
839 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
841 if (att
->Type
== GL_NONE
) {
842 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
843 fbo_incomplete("missing readbuffer", -1);
852 if (numImages
== 0) {
853 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
854 fbo_incomplete("no attachments", -1);
858 /* Provisionally set status = COMPLETE ... */
859 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
861 /* ... but the driver may say the FB is incomplete.
862 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
865 if (ctx
->Driver
.ValidateFramebuffer
) {
866 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
867 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
868 fbo_incomplete("driver marked FBO as incomplete", -1);
872 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
874 * Note that if ARB_framebuffer_object is supported and the attached
875 * renderbuffers/textures are different sizes, the framebuffer
876 * width/height will be set to the smallest width/height.
878 fb
->Width
= minWidth
;
879 fb
->Height
= minHeight
;
881 /* finally, update the visual info for the framebuffer */
882 _mesa_update_framebuffer_visual(ctx
, fb
);
888 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
890 GET_CURRENT_CONTEXT(ctx
);
891 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
893 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
894 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
902 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
904 struct gl_renderbuffer
*newRb
;
905 GET_CURRENT_CONTEXT(ctx
);
907 ASSERT_OUTSIDE_BEGIN_END(ctx
);
909 if (target
!= GL_RENDERBUFFER_EXT
) {
910 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
914 /* No need to flush here since the render buffer binding has no
915 * effect on rendering state.
919 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
920 if (newRb
== &DummyRenderbuffer
) {
921 /* ID was reserved, but no real renderbuffer object made yet */
924 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
925 /* All RB IDs must be Gen'd */
926 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
931 /* create new renderbuffer object */
932 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
934 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
937 ASSERT(newRb
->AllocStorage
);
938 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
939 newRb
->RefCount
= 1; /* referenced by hash table */
946 ASSERT(newRb
!= &DummyRenderbuffer
);
948 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
953 * If the given renderbuffer is anywhere attached to the framebuffer, detach
955 * This is used when a renderbuffer object is deleted.
956 * The spec calls for unbinding.
959 detach_renderbuffer(struct gl_context
*ctx
,
960 struct gl_framebuffer
*fb
,
961 struct gl_renderbuffer
*rb
)
964 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
965 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
966 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
969 invalidate_framebuffer(fb
);
974 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
977 GET_CURRENT_CONTEXT(ctx
);
979 ASSERT_OUTSIDE_BEGIN_END(ctx
);
980 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
982 for (i
= 0; i
< n
; i
++) {
983 if (renderbuffers
[i
] > 0) {
984 struct gl_renderbuffer
*rb
;
985 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
987 /* check if deleting currently bound renderbuffer object */
988 if (rb
== ctx
->CurrentRenderbuffer
) {
990 ASSERT(rb
->RefCount
>= 2);
991 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
994 if (is_user_fbo(ctx
->DrawBuffer
)) {
995 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
997 if (is_user_fbo(ctx
->ReadBuffer
)
998 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
999 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1002 /* Remove from hash table immediately, to free the ID.
1003 * But the object will not be freed until it's no longer
1004 * referenced anywhere else.
1006 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1008 if (rb
!= &DummyRenderbuffer
) {
1009 /* no longer referenced by hash table */
1010 _mesa_reference_renderbuffer(&rb
, NULL
);
1019 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
1021 GET_CURRENT_CONTEXT(ctx
);
1025 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1028 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1035 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1037 for (i
= 0; i
< n
; i
++) {
1038 GLuint name
= first
+ i
;
1039 renderbuffers
[i
] = name
;
1040 /* insert dummy placeholder into hash table */
1041 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1042 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1043 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1049 * Given an internal format token for a render buffer, return the
1050 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1051 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1052 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1054 * This is similar to _mesa_base_tex_format() but the set of valid
1055 * internal formats is different.
1057 * Note that even if a format is determined to be legal here, validation
1058 * of the FBO may fail if the format is not supported by the driver/GPU.
1060 * \param internalFormat as passed to glRenderbufferStorage()
1061 * \return the base internal format, or 0 if internalFormat is illegal
1064 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1067 * Notes: some formats such as alpha, luminance, etc. were added
1068 * with GL_ARB_framebuffer_object.
1070 switch (internalFormat
) {
1076 return ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1080 case GL_LUMINANCE12
:
1081 case GL_LUMINANCE16
:
1082 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1083 case GL_LUMINANCE_ALPHA
:
1084 case GL_LUMINANCE4_ALPHA4
:
1085 case GL_LUMINANCE6_ALPHA2
:
1086 case GL_LUMINANCE8_ALPHA8
:
1087 case GL_LUMINANCE12_ALPHA4
:
1088 case GL_LUMINANCE12_ALPHA12
:
1089 case GL_LUMINANCE16_ALPHA16
:
1090 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1094 case GL_INTENSITY12
:
1095 case GL_INTENSITY16
:
1096 return ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1115 case GL_SRGB8_ALPHA8_EXT
:
1117 case GL_STENCIL_INDEX
:
1118 case GL_STENCIL_INDEX1_EXT
:
1119 case GL_STENCIL_INDEX4_EXT
:
1120 case GL_STENCIL_INDEX8_EXT
:
1121 case GL_STENCIL_INDEX16_EXT
:
1122 return GL_STENCIL_INDEX
;
1123 case GL_DEPTH_COMPONENT
:
1124 case GL_DEPTH_COMPONENT16
:
1125 case GL_DEPTH_COMPONENT24
:
1126 case GL_DEPTH_COMPONENT32
:
1127 return GL_DEPTH_COMPONENT
;
1128 case GL_DEPTH_STENCIL_EXT
:
1129 case GL_DEPTH24_STENCIL8_EXT
:
1130 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
1131 return GL_DEPTH_STENCIL_EXT
;
1134 case GL_DEPTH_COMPONENT32F
:
1135 if (ctx
->Extensions
.ARB_depth_buffer_float
)
1136 return GL_DEPTH_COMPONENT
;
1139 case GL_DEPTH32F_STENCIL8
:
1140 if (ctx
->Extensions
.ARB_depth_buffer_float
)
1141 return GL_DEPTH_STENCIL
;
1147 return ctx
->Extensions
.ARB_texture_rg
? GL_RED
: 0;
1151 return ctx
->Extensions
.ARB_texture_rg
? GL_RG
: 0;
1152 /* signed normalized texture formats */
1156 return ctx
->Extensions
.EXT_texture_snorm
? GL_RED
: 0;
1160 return ctx
->Extensions
.EXT_texture_snorm
? GL_RG
: 0;
1163 case GL_RGB16_SNORM
:
1164 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGB
: 0;
1166 case GL_RGBA8_SNORM
:
1167 case GL_RGBA16_SNORM
:
1168 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGBA
: 0;
1169 case GL_ALPHA_SNORM
:
1170 case GL_ALPHA8_SNORM
:
1171 case GL_ALPHA16_SNORM
:
1172 return ctx
->Extensions
.EXT_texture_snorm
&&
1173 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1174 case GL_LUMINANCE_SNORM
:
1175 case GL_LUMINANCE8_SNORM
:
1176 case GL_LUMINANCE16_SNORM
:
1177 return ctx
->Extensions
.EXT_texture_snorm
&&
1178 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1179 case GL_LUMINANCE_ALPHA_SNORM
:
1180 case GL_LUMINANCE8_ALPHA8_SNORM
:
1181 case GL_LUMINANCE16_ALPHA16_SNORM
:
1182 return ctx
->Extensions
.EXT_texture_snorm
&&
1183 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1184 case GL_INTENSITY_SNORM
:
1185 case GL_INTENSITY8_SNORM
:
1186 case GL_INTENSITY16_SNORM
:
1187 return ctx
->Extensions
.EXT_texture_snorm
&&
1188 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1191 return ctx
->Extensions
.ARB_texture_rg
&&
1192 ctx
->Extensions
.ARB_texture_float
? GL_RED
: 0;
1195 return ctx
->Extensions
.ARB_texture_rg
&&
1196 ctx
->Extensions
.ARB_texture_float
? GL_RG
: 0;
1199 return ctx
->Extensions
.ARB_texture_float
? GL_RGB
: 0;
1202 return ctx
->Extensions
.ARB_texture_float
? GL_RGBA
: 0;
1203 case GL_ALPHA16F_ARB
:
1204 case GL_ALPHA32F_ARB
:
1205 return ctx
->Extensions
.ARB_texture_float
&&
1206 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1207 case GL_LUMINANCE16F_ARB
:
1208 case GL_LUMINANCE32F_ARB
:
1209 return ctx
->Extensions
.ARB_texture_float
&&
1210 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1211 case GL_LUMINANCE_ALPHA16F_ARB
:
1212 case GL_LUMINANCE_ALPHA32F_ARB
:
1213 return ctx
->Extensions
.ARB_texture_float
&&
1214 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1215 case GL_INTENSITY16F_ARB
:
1216 case GL_INTENSITY32F_ARB
:
1217 return ctx
->Extensions
.ARB_texture_float
&&
1218 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1220 return ctx
->Extensions
.EXT_texture_shared_exponent
? GL_RGB
: 0;
1221 case GL_R11F_G11F_B10F
:
1222 return ctx
->Extensions
.EXT_packed_float
? GL_RGB
: 0;
1223 /* XXX add integer formats eventually */
1231 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1234 invalidate_rb(GLuint key
, void *data
, void *userData
)
1236 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1237 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1239 /* If this is a user-created FBO */
1240 if (is_user_fbo(fb
)) {
1242 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1243 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1244 if (att
->Type
== GL_RENDERBUFFER
&&
1245 att
->Renderbuffer
== rb
) {
1246 /* Mark fb status as indeterminate to force re-validation */
1255 /** sentinal value, see below */
1256 #define NO_SAMPLES 1000
1260 * Helper function used by _mesa_RenderbufferStorageEXT() and
1261 * _mesa_RenderbufferStorageMultisample().
1262 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1265 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1266 GLsizei width
, GLsizei height
, GLsizei samples
)
1268 const char *func
= samples
== NO_SAMPLES
?
1269 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1270 struct gl_renderbuffer
*rb
;
1272 GET_CURRENT_CONTEXT(ctx
);
1274 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1276 if (target
!= GL_RENDERBUFFER_EXT
) {
1277 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1281 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1282 if (baseFormat
== 0) {
1283 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1287 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1288 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1292 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1293 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1297 if (samples
== NO_SAMPLES
) {
1298 /* NumSamples == 0 indicates non-multisampling */
1301 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1302 /* note: driver may choose to use more samples than what's requested */
1303 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1307 rb
= ctx
->CurrentRenderbuffer
;
1309 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1313 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1315 if (rb
->InternalFormat
== internalFormat
&&
1316 rb
->Width
== (GLuint
) width
&&
1317 rb
->Height
== (GLuint
) height
) {
1318 /* no change in allocation needed */
1322 /* These MUST get set by the AllocStorage func */
1323 rb
->Format
= MESA_FORMAT_NONE
;
1324 rb
->NumSamples
= samples
;
1326 /* Now allocate the storage */
1327 ASSERT(rb
->AllocStorage
);
1328 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1329 /* No error - check/set fields now */
1330 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1331 assert(rb
->Width
== (GLuint
) width
);
1332 assert(rb
->Height
== (GLuint
) height
);
1333 rb
->InternalFormat
= internalFormat
;
1334 rb
->_BaseFormat
= baseFormat
;
1335 assert(rb
->_BaseFormat
!= 0);
1338 /* Probably ran out of memory - clear the fields */
1341 rb
->Format
= MESA_FORMAT_NONE
;
1342 rb
->InternalFormat
= GL_NONE
;
1343 rb
->_BaseFormat
= GL_NONE
;
1347 /* Invalidate the framebuffers the renderbuffer is attached in. */
1348 if (rb
->AttachedAnytime
) {
1349 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1354 #if FEATURE_OES_EGL_image
1356 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1358 struct gl_renderbuffer
*rb
;
1359 GET_CURRENT_CONTEXT(ctx
);
1360 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1362 if (!ctx
->Extensions
.OES_EGL_image
) {
1363 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1364 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1368 if (target
!= GL_RENDERBUFFER
) {
1369 _mesa_error(ctx
, GL_INVALID_ENUM
,
1370 "EGLImageTargetRenderbufferStorageOES");
1374 rb
= ctx
->CurrentRenderbuffer
;
1376 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1377 "EGLImageTargetRenderbufferStorageOES");
1381 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1383 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1389 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1390 * _mesa_GetFramebufferAttachmentParameterivEXT()
1391 * We have to be careful to respect the base format. For example, if a
1392 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1393 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1394 * we need to return zero.
1397 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1400 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1401 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1402 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1403 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1404 return _mesa_get_format_bits(format
, pname
);
1407 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1408 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1409 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1410 return _mesa_get_format_bits(format
, pname
);
1413 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1414 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1415 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1416 return _mesa_get_format_bits(format
, pname
);
1419 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1420 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1421 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1422 baseFormat
== GL_LUMINANCE_ALPHA
)
1423 return _mesa_get_format_bits(format
, pname
);
1426 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1427 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1428 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1429 return _mesa_get_format_bits(format
, pname
);
1432 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1433 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1434 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1435 return _mesa_get_format_bits(format
, pname
);
1446 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1447 GLsizei width
, GLsizei height
)
1449 /* GL_ARB_fbo says calling this function is equivalent to calling
1450 * glRenderbufferStorageMultisample() with samples=0. We pass in
1451 * a token value here just for error reporting purposes.
1453 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1458 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1459 GLenum internalFormat
,
1460 GLsizei width
, GLsizei height
)
1462 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1467 * OpenGL ES version of glRenderBufferStorage.
1470 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1471 GLsizei width
, GLsizei height
)
1473 switch (internalFormat
) {
1475 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1476 /* choose a closest format */
1477 internalFormat
= GL_RGB5
;
1483 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1488 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1490 struct gl_renderbuffer
*rb
;
1491 GET_CURRENT_CONTEXT(ctx
);
1493 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1495 if (target
!= GL_RENDERBUFFER_EXT
) {
1496 _mesa_error(ctx
, GL_INVALID_ENUM
,
1497 "glGetRenderbufferParameterivEXT(target)");
1501 rb
= ctx
->CurrentRenderbuffer
;
1503 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1504 "glGetRenderbufferParameterivEXT");
1508 /* No need to flush here since we're just quering state which is
1509 * not effected by rendering.
1513 case GL_RENDERBUFFER_WIDTH_EXT
:
1514 *params
= rb
->Width
;
1516 case GL_RENDERBUFFER_HEIGHT_EXT
:
1517 *params
= rb
->Height
;
1519 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1520 *params
= rb
->InternalFormat
;
1522 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1523 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1524 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1525 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1526 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1527 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1528 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1530 case GL_RENDERBUFFER_SAMPLES
:
1531 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1532 *params
= rb
->NumSamples
;
1537 _mesa_error(ctx
, GL_INVALID_ENUM
,
1538 "glGetRenderbufferParameterivEXT(target)");
1544 GLboolean GLAPIENTRY
1545 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1547 GET_CURRENT_CONTEXT(ctx
);
1548 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1550 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1551 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1559 * Check if any of the attachments of the given framebuffer are textures
1560 * (render to texture). Call ctx->Driver.RenderTexture() for such
1564 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1567 ASSERT(ctx
->Driver
.RenderTexture
);
1569 if (is_winsys_fbo(fb
))
1570 return; /* can't render to texture with winsys framebuffers */
1572 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1573 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1574 if (att
->Texture
&& _mesa_get_attachment_teximage(att
)) {
1575 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1582 * Examine all the framebuffer's attachments to see if any are textures.
1583 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1584 * notify the device driver that the texture image may have changed.
1587 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1589 if (is_winsys_fbo(fb
))
1590 return; /* can't render to texture with winsys framebuffers */
1592 if (ctx
->Driver
.FinishRenderTexture
) {
1594 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1595 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1596 if (att
->Texture
&& att
->Renderbuffer
) {
1597 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1605 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1607 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1608 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1609 GLboolean bindReadBuf
, bindDrawBuf
;
1610 GET_CURRENT_CONTEXT(ctx
);
1613 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1614 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1615 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1619 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1621 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1623 "glBindFramebufferEXT(unsupported)");
1628 #if FEATURE_EXT_framebuffer_blit
1629 case GL_DRAW_FRAMEBUFFER_EXT
:
1630 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1631 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1634 bindDrawBuf
= GL_TRUE
;
1635 bindReadBuf
= GL_FALSE
;
1637 case GL_READ_FRAMEBUFFER_EXT
:
1638 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1639 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1642 bindDrawBuf
= GL_FALSE
;
1643 bindReadBuf
= GL_TRUE
;
1646 case GL_FRAMEBUFFER_EXT
:
1647 bindDrawBuf
= GL_TRUE
;
1648 bindReadBuf
= GL_TRUE
;
1651 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1656 /* Binding a user-created framebuffer object */
1657 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1658 if (newDrawFb
== &DummyFramebuffer
) {
1659 /* ID was reserved, but no real framebuffer object made yet */
1662 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1663 /* All FBO IDs must be Gen'd */
1664 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1669 /* create new framebuffer object */
1670 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1672 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1675 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1677 newReadFb
= newDrawFb
;
1680 /* Binding the window system framebuffer (which was originally set
1681 * with MakeCurrent).
1683 newDrawFb
= ctx
->WinSysDrawBuffer
;
1684 newReadFb
= ctx
->WinSysReadBuffer
;
1688 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1690 /* save pointers to current/old framebuffers */
1691 oldDrawFb
= ctx
->DrawBuffer
;
1692 oldReadFb
= ctx
->ReadBuffer
;
1694 /* check if really changing bindings */
1695 if (oldDrawFb
== newDrawFb
)
1696 bindDrawBuf
= GL_FALSE
;
1697 if (oldReadFb
== newReadFb
)
1698 bindReadBuf
= GL_FALSE
;
1701 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1703 * We also check if we're beginning and/or ending render-to-texture.
1704 * When a framebuffer with texture attachments is unbound, call
1705 * ctx->Driver.FinishRenderTexture().
1706 * When a framebuffer with texture attachments is bound, call
1707 * ctx->Driver.RenderTexture().
1709 * Note that if the ReadBuffer has texture attachments we don't consider
1710 * that a render-to-texture case.
1713 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1715 /* check if old readbuffer was render-to-texture */
1716 check_end_texture_render(ctx
, oldReadFb
);
1718 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1722 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1724 /* check if old read/draw buffers were render-to-texture */
1726 check_end_texture_render(ctx
, oldReadFb
);
1728 if (oldDrawFb
!= oldReadFb
)
1729 check_end_texture_render(ctx
, oldDrawFb
);
1731 /* check if newly bound framebuffer has any texture attachments */
1732 check_begin_texture_render(ctx
, newDrawFb
);
1734 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1737 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1738 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1744 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1747 GET_CURRENT_CONTEXT(ctx
);
1749 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1750 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1752 for (i
= 0; i
< n
; i
++) {
1753 if (framebuffers
[i
] > 0) {
1754 struct gl_framebuffer
*fb
;
1755 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1757 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1759 /* check if deleting currently bound framebuffer object */
1760 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1761 /* separate draw/read binding points */
1762 if (fb
== ctx
->DrawBuffer
) {
1764 ASSERT(fb
->RefCount
>= 2);
1765 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1767 if (fb
== ctx
->ReadBuffer
) {
1769 ASSERT(fb
->RefCount
>= 2);
1770 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1774 /* only one binding point for read/draw buffers */
1775 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1777 ASSERT(fb
->RefCount
>= 2);
1778 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1782 /* remove from hash table immediately, to free the ID */
1783 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1785 if (fb
!= &DummyFramebuffer
) {
1786 /* But the object will not be freed until it's no longer
1787 * bound in any context.
1789 _mesa_reference_framebuffer(&fb
, NULL
);
1798 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1800 GET_CURRENT_CONTEXT(ctx
);
1804 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1807 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1814 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1816 for (i
= 0; i
< n
; i
++) {
1817 GLuint name
= first
+ i
;
1818 framebuffers
[i
] = name
;
1819 /* insert dummy placeholder into hash table */
1820 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1821 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1822 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1829 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1831 struct gl_framebuffer
*buffer
;
1832 GET_CURRENT_CONTEXT(ctx
);
1834 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1836 buffer
= get_framebuffer_target(ctx
, target
);
1838 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1842 if (is_winsys_fbo(buffer
)) {
1843 /* The window system / default framebuffer is always complete */
1844 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1847 /* No need to flush here */
1849 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1850 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1853 return buffer
->_Status
;
1859 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1862 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1863 GLenum attachment
, GLenum textarget
, GLuint texture
,
1864 GLint level
, GLint zoffset
)
1866 struct gl_renderbuffer_attachment
*att
;
1867 struct gl_texture_object
*texObj
= NULL
;
1868 struct gl_framebuffer
*fb
;
1870 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1872 fb
= get_framebuffer_target(ctx
, target
);
1874 _mesa_error(ctx
, GL_INVALID_ENUM
,
1875 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1879 /* check framebuffer binding */
1880 if (is_winsys_fbo(fb
)) {
1881 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1882 "glFramebufferTexture%sEXT", caller
);
1887 /* The textarget, level, and zoffset parameters are only validated if
1888 * texture is non-zero.
1891 GLboolean err
= GL_TRUE
;
1893 texObj
= _mesa_lookup_texture(ctx
, texture
);
1894 if (texObj
!= NULL
) {
1895 if (textarget
== 0) {
1896 /* XXX what's the purpose of this? */
1897 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1898 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1899 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1902 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1903 ? !is_cube_face(textarget
)
1904 : (texObj
->Target
!= textarget
);
1908 /* can't render to a non-existant texture */
1909 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1910 "glFramebufferTexture%sEXT(non existant texture)",
1916 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1917 "glFramebufferTexture%sEXT(texture target mismatch)",
1922 if (texObj
->Target
== GL_TEXTURE_3D
) {
1923 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1924 if (zoffset
< 0 || zoffset
>= maxSize
) {
1925 _mesa_error(ctx
, GL_INVALID_VALUE
,
1926 "glFramebufferTexture%sEXT(zoffset)", caller
);
1930 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1931 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1932 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1933 _mesa_error(ctx
, GL_INVALID_VALUE
,
1934 "glFramebufferTexture%sEXT(layer)", caller
);
1940 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1941 _mesa_error(ctx
, GL_INVALID_VALUE
,
1942 "glFramebufferTexture%sEXT(level)", caller
);
1947 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1949 _mesa_error(ctx
, GL_INVALID_ENUM
,
1950 "glFramebufferTexture%sEXT(attachment)", caller
);
1954 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1956 _glthread_LOCK_MUTEX(fb
->Mutex
);
1958 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1960 /* Set the render-to-texture flag. We'll check this flag in
1961 * glTexImage() and friends to determine if we need to revalidate
1962 * any FBOs that might be rendering into this texture.
1963 * This flag never gets cleared since it's non-trivial to determine
1964 * when all FBOs might be done rendering to this texture. That's OK
1965 * though since it's uncommon to render to a texture then repeatedly
1966 * call glTexImage() to change images in the texture.
1968 texObj
->_RenderToTexture
= GL_TRUE
;
1971 _mesa_remove_attachment(ctx
, att
);
1974 invalidate_framebuffer(fb
);
1976 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1982 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1983 GLenum textarget
, GLuint texture
, GLint level
)
1985 GET_CURRENT_CONTEXT(ctx
);
1987 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1988 _mesa_error(ctx
, GL_INVALID_ENUM
,
1989 "glFramebufferTexture1DEXT(textarget)");
1993 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1999 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
2000 GLenum textarget
, GLuint texture
, GLint level
)
2002 GET_CURRENT_CONTEXT(ctx
);
2004 if ((texture
!= 0) &&
2005 (textarget
!= GL_TEXTURE_2D
) &&
2006 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
2007 (!is_cube_face(textarget
))) {
2008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2009 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
2013 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2019 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
2020 GLenum textarget
, GLuint texture
,
2021 GLint level
, GLint zoffset
)
2023 GET_CURRENT_CONTEXT(ctx
);
2025 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2026 _mesa_error(ctx
, GL_INVALID_ENUM
,
2027 "glFramebufferTexture3DEXT(textarget)");
2031 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2037 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
2038 GLuint texture
, GLint level
, GLint layer
)
2040 GET_CURRENT_CONTEXT(ctx
);
2042 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2048 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
2049 GLenum renderbufferTarget
,
2050 GLuint renderbuffer
)
2052 struct gl_renderbuffer_attachment
*att
;
2053 struct gl_framebuffer
*fb
;
2054 struct gl_renderbuffer
*rb
;
2055 GET_CURRENT_CONTEXT(ctx
);
2057 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2059 fb
= get_framebuffer_target(ctx
, target
);
2061 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2065 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2066 _mesa_error(ctx
, GL_INVALID_ENUM
,
2067 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2071 if (is_winsys_fbo(fb
)) {
2072 /* Can't attach new renderbuffers to a window system framebuffer */
2073 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2077 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2079 _mesa_error(ctx
, GL_INVALID_ENUM
,
2080 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2081 _mesa_lookup_enum_by_nr(attachment
));
2086 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2088 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2089 "glFramebufferRenderbufferEXT(non-existant"
2090 " renderbuffer %u)", renderbuffer
);
2093 else if (rb
== &DummyRenderbuffer
) {
2094 /* This is what NVIDIA does */
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2102 /* remove renderbuffer attachment */
2106 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2107 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2108 /* make sure the renderbuffer is a depth/stencil format */
2109 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2110 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2111 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2112 "glFramebufferRenderbufferEXT(renderbuffer"
2113 " is not DEPTH_STENCIL format)");
2119 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2121 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2122 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2124 /* Some subsequent GL commands may depend on the framebuffer's visual
2125 * after the binding is updated. Update visual info now.
2127 _mesa_update_framebuffer_visual(ctx
, fb
);
2132 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2133 GLenum pname
, GLint
*params
)
2135 const struct gl_renderbuffer_attachment
*att
;
2136 struct gl_framebuffer
*buffer
;
2138 GET_CURRENT_CONTEXT(ctx
);
2140 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2142 /* The error differs in GL andd GLES. */
2143 err
= ctx
->API
== API_OPENGL
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2145 buffer
= get_framebuffer_target(ctx
, target
);
2147 _mesa_error(ctx
, GL_INVALID_ENUM
,
2148 "glGetFramebufferAttachmentParameterivEXT(target)");
2152 if (is_winsys_fbo(buffer
)) {
2153 /* the default / window-system FBO */
2154 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2157 /* user-created framebuffer FBO */
2158 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2162 _mesa_error(ctx
, GL_INVALID_ENUM
,
2163 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2167 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2168 /* the depth and stencil attachments must point to the same buffer */
2169 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2170 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2171 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2172 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2174 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2175 " attachments differ)");
2180 /* No need to flush here */
2183 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2184 *params
= is_winsys_fbo(buffer
) ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2186 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2187 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2188 *params
= att
->Renderbuffer
->Name
;
2190 else if (att
->Type
== GL_TEXTURE
) {
2191 *params
= att
->Texture
->Name
;
2194 assert(att
->Type
== GL_NONE
);
2195 if (ctx
->API
== API_OPENGL
) {
2198 _mesa_error(ctx
, GL_INVALID_ENUM
,
2199 "glGetFramebufferAttachmentParameterivEXT(pname)");
2203 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2204 if (att
->Type
== GL_TEXTURE
) {
2205 *params
= att
->TextureLevel
;
2207 else if (att
->Type
== GL_NONE
) {
2208 _mesa_error(ctx
, err
,
2209 "glGetFramebufferAttachmentParameterivEXT(pname)");
2212 _mesa_error(ctx
, GL_INVALID_ENUM
,
2213 "glGetFramebufferAttachmentParameterivEXT(pname)");
2216 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2217 if (att
->Type
== GL_TEXTURE
) {
2218 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2219 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2225 else if (att
->Type
== GL_NONE
) {
2226 _mesa_error(ctx
, err
,
2227 "glGetFramebufferAttachmentParameterivEXT(pname)");
2230 _mesa_error(ctx
, GL_INVALID_ENUM
,
2231 "glGetFramebufferAttachmentParameterivEXT(pname)");
2234 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2235 if (att
->Type
== GL_TEXTURE
) {
2236 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2237 *params
= att
->Zoffset
;
2243 else if (att
->Type
== GL_NONE
) {
2244 _mesa_error(ctx
, err
,
2245 "glGetFramebufferAttachmentParameterivEXT(pname)");
2248 _mesa_error(ctx
, GL_INVALID_ENUM
,
2249 "glGetFramebufferAttachmentParameterivEXT(pname)");
2252 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2253 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2254 _mesa_error(ctx
, GL_INVALID_ENUM
,
2255 "glGetFramebufferAttachmentParameterivEXT(pname)");
2257 else if (att
->Type
== GL_NONE
) {
2258 _mesa_error(ctx
, err
,
2259 "glGetFramebufferAttachmentParameterivEXT(pname)");
2262 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&& ctx
->Const
.sRGBCapable
) {
2263 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2266 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2267 * if the sRGB conversion is unsupported. */
2268 *params
= GL_LINEAR
;
2272 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2273 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2274 _mesa_error(ctx
, GL_INVALID_ENUM
,
2275 "glGetFramebufferAttachmentParameterivEXT(pname)");
2278 else if (att
->Type
== GL_NONE
) {
2279 _mesa_error(ctx
, err
,
2280 "glGetFramebufferAttachmentParameterivEXT(pname)");
2283 gl_format format
= att
->Renderbuffer
->Format
;
2284 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2288 else if (format
== MESA_FORMAT_Z32_FLOAT_X24S8
) {
2289 /* depends on the attachment parameter */
2290 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2298 *params
= _mesa_get_format_datatype(format
);
2302 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2303 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2304 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2305 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2306 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2307 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2308 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2309 _mesa_error(ctx
, GL_INVALID_ENUM
,
2310 "glGetFramebufferAttachmentParameterivEXT(pname)");
2312 else if (att
->Type
== GL_NONE
) {
2313 _mesa_error(ctx
, err
,
2314 "glGetFramebufferAttachmentParameterivEXT(pname)");
2316 else if (att
->Texture
) {
2317 const struct gl_texture_image
*texImage
=
2318 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2321 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2322 texImage
->TexFormat
);
2328 else if (att
->Renderbuffer
) {
2329 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2330 att
->Renderbuffer
->Format
);
2333 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2334 " invalid FBO attachment structure");
2338 _mesa_error(ctx
, GL_INVALID_ENUM
,
2339 "glGetFramebufferAttachmentParameterivEXT(pname)");
2346 _mesa_GenerateMipmapEXT(GLenum target
)
2348 struct gl_texture_object
*texObj
;
2349 GET_CURRENT_CONTEXT(ctx
);
2351 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2352 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2358 case GL_TEXTURE_CUBE_MAP
:
2359 /* OK, legal value */
2362 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2363 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2367 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2369 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2374 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2375 !_mesa_cube_complete(texObj
)) {
2376 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2377 "glGenerateMipmap(incomplete cube map)");
2381 _mesa_lock_texture(ctx
, texObj
);
2382 if (target
== GL_TEXTURE_CUBE_MAP
) {
2384 for (face
= 0; face
< 6; face
++)
2385 ctx
->Driver
.GenerateMipmap(ctx
,
2386 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2390 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2392 _mesa_unlock_texture(ctx
, texObj
);
2396 #if FEATURE_EXT_framebuffer_blit
2398 static const struct gl_renderbuffer_attachment
*
2399 find_attachment(const struct gl_framebuffer
*fb
,
2400 const struct gl_renderbuffer
*rb
)
2403 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2404 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2405 return &fb
->Attachment
[i
];
2413 * Blit rectangular region, optionally from one framebuffer to another.
2415 * Note, if the src buffer is multisampled and the dest is not, this is
2416 * when the samples must be resolved to a single color.
2419 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2420 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2421 GLbitfield mask
, GLenum filter
)
2423 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2424 GL_DEPTH_BUFFER_BIT
|
2425 GL_STENCIL_BUFFER_BIT
);
2426 const struct gl_framebuffer
*readFb
, *drawFb
;
2427 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2428 GET_CURRENT_CONTEXT(ctx
);
2430 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2431 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2433 if (MESA_VERBOSE
& VERBOSE_API
)
2435 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2436 srcX0
, srcY0
, srcX1
, srcY1
,
2437 dstX0
, dstY0
, dstX1
, dstY1
,
2438 mask
, _mesa_lookup_enum_by_nr(filter
));
2440 if (ctx
->NewState
) {
2441 _mesa_update_state(ctx
);
2444 readFb
= ctx
->ReadBuffer
;
2445 drawFb
= ctx
->DrawBuffer
;
2447 if (!readFb
|| !drawFb
) {
2448 /* This will normally never happen but someday we may want to
2449 * support MakeCurrent() with no drawables.
2454 /* check for complete framebuffers */
2455 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2456 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2457 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2458 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2462 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2463 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2467 if (mask
& ~legalMaskBits
) {
2468 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2472 /* depth/stencil must be blitted with nearest filtering */
2473 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2474 && filter
!= GL_NEAREST
) {
2475 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2476 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2480 /* get color read/draw renderbuffers */
2481 if (mask
& GL_COLOR_BUFFER_BIT
) {
2482 colorReadRb
= readFb
->_ColorReadBuffer
;
2483 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2485 /* From the EXT_framebuffer_object spec:
2487 * "If a buffer is specified in <mask> and does not exist in both
2488 * the read and draw framebuffers, the corresponding bit is silently
2491 if ((colorReadRb
== NULL
) || (colorDrawRb
== NULL
)) {
2492 colorReadRb
= colorDrawRb
= NULL
;
2493 mask
&= ~GL_COLOR_BUFFER_BIT
;
2497 colorReadRb
= colorDrawRb
= NULL
;
2500 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2501 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2502 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2504 /* From the EXT_framebuffer_object spec:
2506 * "If a buffer is specified in <mask> and does not exist in both
2507 * the read and draw framebuffers, the corresponding bit is silently
2510 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
2511 readRb
= drawRb
= NULL
;
2512 mask
&= ~GL_STENCIL_BUFFER_BIT
;
2514 else if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2515 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2516 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2517 "glBlitFramebufferEXT(stencil buffer size mismatch)");
2522 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2523 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2524 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2526 /* From the EXT_framebuffer_object spec:
2528 * "If a buffer is specified in <mask> and does not exist in both
2529 * the read and draw framebuffers, the corresponding bit is silently
2532 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
2533 readRb
= drawRb
= NULL
;
2534 mask
&= ~GL_DEPTH_BUFFER_BIT
;
2536 else if (_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2537 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2539 "glBlitFramebufferEXT(depth buffer size mismatch)");
2544 if (readFb
->Visual
.samples
> 0 &&
2545 drawFb
->Visual
.samples
> 0 &&
2546 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2548 "glBlitFramebufferEXT(mismatched samples");
2552 /* extra checks for multisample copies... */
2553 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2554 /* src and dest region sizes must be the same */
2555 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2556 srcY1
- srcY0
!= dstY1
- dstY0
) {
2557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2558 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
2562 /* color formats must match */
2565 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2567 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
2572 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2579 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2581 srcX0
, srcY0
, srcX1
, srcY1
,
2582 dstX0
, dstY0
, dstX1
, dstY1
,
2585 const struct gl_renderbuffer_attachment
*att
;
2587 att
= find_attachment(readFb
, colorReadRb
);
2588 printf(" Src FBO %u RB %u (%dx%d) ",
2589 readFb
->Name
, colorReadRb
->Name
,
2590 colorReadRb
->Width
, colorReadRb
->Height
);
2591 if (att
&& att
->Texture
) {
2592 printf("Tex %u tgt 0x%x level %u face %u",
2594 att
->Texture
->Target
,
2600 att
= find_attachment(drawFb
, colorDrawRb
);
2601 printf(" Dst FBO %u RB %u (%dx%d) ",
2602 drawFb
->Name
, colorDrawRb
->Name
,
2603 colorDrawRb
->Width
, colorDrawRb
->Height
);
2604 if (att
&& att
->Texture
) {
2605 printf("Tex %u tgt 0x%x level %u face %u",
2607 att
->Texture
->Target
,
2619 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2620 ctx
->Driver
.BlitFramebuffer(ctx
,
2621 srcX0
, srcY0
, srcX1
, srcY1
,
2622 dstX0
, dstY0
, dstX1
, dstY1
,
2625 #endif /* FEATURE_EXT_framebuffer_blit */
2627 #if FEATURE_ARB_geometry_shader4
2629 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2630 GLuint texture
, GLint level
)
2632 GET_CURRENT_CONTEXT(ctx
);
2633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2634 "glFramebufferTextureARB "
2635 "not implemented!");
2639 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2640 GLuint texture
, GLint level
, GLenum face
)
2642 GET_CURRENT_CONTEXT(ctx
);
2643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2644 "glFramebufferTextureFaceARB "
2645 "not implemented!");
2647 #endif /* FEATURE_ARB_geometry_shader4 */