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
;
1137 return ctx
->Extensions
.ARB_texture_rg
? GL_RED
: 0;
1141 return ctx
->Extensions
.ARB_texture_rg
? GL_RG
: 0;
1142 /* signed normalized texture formats */
1146 return ctx
->Extensions
.EXT_texture_snorm
? GL_RED
: 0;
1150 return ctx
->Extensions
.EXT_texture_snorm
? GL_RG
: 0;
1153 case GL_RGB16_SNORM
:
1154 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGB
: 0;
1156 case GL_RGBA8_SNORM
:
1157 case GL_RGBA16_SNORM
:
1158 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGBA
: 0;
1159 case GL_ALPHA_SNORM
:
1160 case GL_ALPHA8_SNORM
:
1161 case GL_ALPHA16_SNORM
:
1162 return ctx
->Extensions
.EXT_texture_snorm
&&
1163 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1164 case GL_LUMINANCE_SNORM
:
1165 case GL_LUMINANCE8_SNORM
:
1166 case GL_LUMINANCE16_SNORM
:
1167 return ctx
->Extensions
.EXT_texture_snorm
&&
1168 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1169 case GL_LUMINANCE_ALPHA_SNORM
:
1170 case GL_LUMINANCE8_ALPHA8_SNORM
:
1171 case GL_LUMINANCE16_ALPHA16_SNORM
:
1172 return ctx
->Extensions
.EXT_texture_snorm
&&
1173 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1174 case GL_INTENSITY_SNORM
:
1175 case GL_INTENSITY8_SNORM
:
1176 case GL_INTENSITY16_SNORM
:
1177 return ctx
->Extensions
.EXT_texture_snorm
&&
1178 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1181 return ctx
->Extensions
.ARB_texture_rg
&&
1182 ctx
->Extensions
.ARB_texture_float
? GL_RED
: 0;
1185 return ctx
->Extensions
.ARB_texture_rg
&&
1186 ctx
->Extensions
.ARB_texture_float
? GL_RG
: 0;
1189 return ctx
->Extensions
.ARB_texture_float
? GL_RGB
: 0;
1192 return ctx
->Extensions
.ARB_texture_float
? GL_RGBA
: 0;
1193 case GL_ALPHA16F_ARB
:
1194 case GL_ALPHA32F_ARB
:
1195 return ctx
->Extensions
.ARB_texture_float
&&
1196 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1197 case GL_LUMINANCE16F_ARB
:
1198 case GL_LUMINANCE32F_ARB
:
1199 return ctx
->Extensions
.ARB_texture_float
&&
1200 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1201 case GL_LUMINANCE_ALPHA16F_ARB
:
1202 case GL_LUMINANCE_ALPHA32F_ARB
:
1203 return ctx
->Extensions
.ARB_texture_float
&&
1204 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1205 case GL_INTENSITY16F_ARB
:
1206 case GL_INTENSITY32F_ARB
:
1207 return ctx
->Extensions
.ARB_texture_float
&&
1208 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1210 return ctx
->Extensions
.EXT_texture_shared_exponent
? GL_RGB
: 0;
1211 case GL_R11F_G11F_B10F
:
1212 return ctx
->Extensions
.EXT_packed_float
? GL_RGB
: 0;
1213 /* XXX add integer formats eventually */
1221 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1224 invalidate_rb(GLuint key
, void *data
, void *userData
)
1226 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1227 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1229 /* If this is a user-created FBO */
1230 if (is_user_fbo(fb
)) {
1232 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1233 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1234 if (att
->Type
== GL_RENDERBUFFER
&&
1235 att
->Renderbuffer
== rb
) {
1236 /* Mark fb status as indeterminate to force re-validation */
1245 /** sentinal value, see below */
1246 #define NO_SAMPLES 1000
1250 * Helper function used by _mesa_RenderbufferStorageEXT() and
1251 * _mesa_RenderbufferStorageMultisample().
1252 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1255 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1256 GLsizei width
, GLsizei height
, GLsizei samples
)
1258 const char *func
= samples
== NO_SAMPLES
?
1259 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1260 struct gl_renderbuffer
*rb
;
1262 GET_CURRENT_CONTEXT(ctx
);
1264 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1266 if (target
!= GL_RENDERBUFFER_EXT
) {
1267 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1271 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1272 if (baseFormat
== 0) {
1273 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1277 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1278 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1282 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1283 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1287 if (samples
== NO_SAMPLES
) {
1288 /* NumSamples == 0 indicates non-multisampling */
1291 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1292 /* note: driver may choose to use more samples than what's requested */
1293 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1297 rb
= ctx
->CurrentRenderbuffer
;
1299 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1303 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1305 if (rb
->InternalFormat
== internalFormat
&&
1306 rb
->Width
== (GLuint
) width
&&
1307 rb
->Height
== (GLuint
) height
) {
1308 /* no change in allocation needed */
1312 /* These MUST get set by the AllocStorage func */
1313 rb
->Format
= MESA_FORMAT_NONE
;
1314 rb
->NumSamples
= samples
;
1316 /* Now allocate the storage */
1317 ASSERT(rb
->AllocStorage
);
1318 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1319 /* No error - check/set fields now */
1320 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1321 assert(rb
->Width
== (GLuint
) width
);
1322 assert(rb
->Height
== (GLuint
) height
);
1323 rb
->InternalFormat
= internalFormat
;
1324 rb
->_BaseFormat
= baseFormat
;
1325 assert(rb
->_BaseFormat
!= 0);
1328 /* Probably ran out of memory - clear the fields */
1331 rb
->Format
= MESA_FORMAT_NONE
;
1332 rb
->InternalFormat
= GL_NONE
;
1333 rb
->_BaseFormat
= GL_NONE
;
1337 /* Invalidate the framebuffers the renderbuffer is attached in. */
1338 if (rb
->AttachedAnytime
) {
1339 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1344 #if FEATURE_OES_EGL_image
1346 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1348 struct gl_renderbuffer
*rb
;
1349 GET_CURRENT_CONTEXT(ctx
);
1350 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1352 if (!ctx
->Extensions
.OES_EGL_image
) {
1353 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1354 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1358 if (target
!= GL_RENDERBUFFER
) {
1359 _mesa_error(ctx
, GL_INVALID_ENUM
,
1360 "EGLImageTargetRenderbufferStorageOES");
1364 rb
= ctx
->CurrentRenderbuffer
;
1366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1367 "EGLImageTargetRenderbufferStorageOES");
1371 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1373 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1379 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1380 * _mesa_GetFramebufferAttachmentParameterivEXT()
1381 * We have to be careful to respect the base format. For example, if a
1382 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1383 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1384 * we need to return zero.
1387 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1390 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1391 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1392 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1393 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1394 return _mesa_get_format_bits(format
, pname
);
1397 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1398 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1399 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1400 return _mesa_get_format_bits(format
, pname
);
1403 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1404 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1405 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1406 return _mesa_get_format_bits(format
, pname
);
1409 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1410 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1411 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1412 baseFormat
== GL_LUMINANCE_ALPHA
)
1413 return _mesa_get_format_bits(format
, pname
);
1416 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1417 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1418 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1419 return _mesa_get_format_bits(format
, pname
);
1422 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1423 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1424 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1425 return _mesa_get_format_bits(format
, pname
);
1436 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1437 GLsizei width
, GLsizei height
)
1439 /* GL_ARB_fbo says calling this function is equivalent to calling
1440 * glRenderbufferStorageMultisample() with samples=0. We pass in
1441 * a token value here just for error reporting purposes.
1443 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1448 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1449 GLenum internalFormat
,
1450 GLsizei width
, GLsizei height
)
1452 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1457 * OpenGL ES version of glRenderBufferStorage.
1460 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1461 GLsizei width
, GLsizei height
)
1463 switch (internalFormat
) {
1465 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1466 /* choose a closest format */
1467 internalFormat
= GL_RGB5
;
1473 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1478 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1480 struct gl_renderbuffer
*rb
;
1481 GET_CURRENT_CONTEXT(ctx
);
1483 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1485 if (target
!= GL_RENDERBUFFER_EXT
) {
1486 _mesa_error(ctx
, GL_INVALID_ENUM
,
1487 "glGetRenderbufferParameterivEXT(target)");
1491 rb
= ctx
->CurrentRenderbuffer
;
1493 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1494 "glGetRenderbufferParameterivEXT");
1498 /* No need to flush here since we're just quering state which is
1499 * not effected by rendering.
1503 case GL_RENDERBUFFER_WIDTH_EXT
:
1504 *params
= rb
->Width
;
1506 case GL_RENDERBUFFER_HEIGHT_EXT
:
1507 *params
= rb
->Height
;
1509 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1510 *params
= rb
->InternalFormat
;
1512 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1513 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1514 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1515 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1516 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1517 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1518 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1520 case GL_RENDERBUFFER_SAMPLES
:
1521 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1522 *params
= rb
->NumSamples
;
1527 _mesa_error(ctx
, GL_INVALID_ENUM
,
1528 "glGetRenderbufferParameterivEXT(target)");
1534 GLboolean GLAPIENTRY
1535 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1537 GET_CURRENT_CONTEXT(ctx
);
1538 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1540 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1541 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1549 * Check if any of the attachments of the given framebuffer are textures
1550 * (render to texture). Call ctx->Driver.RenderTexture() for such
1554 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1557 ASSERT(ctx
->Driver
.RenderTexture
);
1559 if (is_winsys_fbo(fb
))
1560 return; /* can't render to texture with winsys framebuffers */
1562 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1563 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1564 if (att
->Texture
&& _mesa_get_attachment_teximage(att
)) {
1565 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1572 * Examine all the framebuffer's attachments to see if any are textures.
1573 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1574 * notify the device driver that the texture image may have changed.
1577 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1579 if (is_winsys_fbo(fb
))
1580 return; /* can't render to texture with winsys framebuffers */
1582 if (ctx
->Driver
.FinishRenderTexture
) {
1584 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1585 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1586 if (att
->Texture
&& att
->Renderbuffer
) {
1587 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1595 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1597 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1598 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1599 GLboolean bindReadBuf
, bindDrawBuf
;
1600 GET_CURRENT_CONTEXT(ctx
);
1603 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1604 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1605 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1609 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1611 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1612 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1613 "glBindFramebufferEXT(unsupported)");
1618 #if FEATURE_EXT_framebuffer_blit
1619 case GL_DRAW_FRAMEBUFFER_EXT
:
1620 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1621 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1624 bindDrawBuf
= GL_TRUE
;
1625 bindReadBuf
= GL_FALSE
;
1627 case GL_READ_FRAMEBUFFER_EXT
:
1628 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1629 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1632 bindDrawBuf
= GL_FALSE
;
1633 bindReadBuf
= GL_TRUE
;
1636 case GL_FRAMEBUFFER_EXT
:
1637 bindDrawBuf
= GL_TRUE
;
1638 bindReadBuf
= GL_TRUE
;
1641 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1646 /* Binding a user-created framebuffer object */
1647 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1648 if (newDrawFb
== &DummyFramebuffer
) {
1649 /* ID was reserved, but no real framebuffer object made yet */
1652 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1653 /* All FBO IDs must be Gen'd */
1654 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1659 /* create new framebuffer object */
1660 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1662 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1665 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1667 newReadFb
= newDrawFb
;
1670 /* Binding the window system framebuffer (which was originally set
1671 * with MakeCurrent).
1673 newDrawFb
= ctx
->WinSysDrawBuffer
;
1674 newReadFb
= ctx
->WinSysReadBuffer
;
1678 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1680 /* save pointers to current/old framebuffers */
1681 oldDrawFb
= ctx
->DrawBuffer
;
1682 oldReadFb
= ctx
->ReadBuffer
;
1684 /* check if really changing bindings */
1685 if (oldDrawFb
== newDrawFb
)
1686 bindDrawBuf
= GL_FALSE
;
1687 if (oldReadFb
== newReadFb
)
1688 bindReadBuf
= GL_FALSE
;
1691 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1693 * We also check if we're beginning and/or ending render-to-texture.
1694 * When a framebuffer with texture attachments is unbound, call
1695 * ctx->Driver.FinishRenderTexture().
1696 * When a framebuffer with texture attachments is bound, call
1697 * ctx->Driver.RenderTexture().
1699 * Note that if the ReadBuffer has texture attachments we don't consider
1700 * that a render-to-texture case.
1703 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1705 /* check if old readbuffer was render-to-texture */
1706 check_end_texture_render(ctx
, oldReadFb
);
1708 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1712 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1714 /* check if old read/draw buffers were render-to-texture */
1716 check_end_texture_render(ctx
, oldReadFb
);
1718 if (oldDrawFb
!= oldReadFb
)
1719 check_end_texture_render(ctx
, oldDrawFb
);
1721 /* check if newly bound framebuffer has any texture attachments */
1722 check_begin_texture_render(ctx
, newDrawFb
);
1724 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1727 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1728 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1734 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1737 GET_CURRENT_CONTEXT(ctx
);
1739 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1740 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1742 for (i
= 0; i
< n
; i
++) {
1743 if (framebuffers
[i
] > 0) {
1744 struct gl_framebuffer
*fb
;
1745 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1747 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1749 /* check if deleting currently bound framebuffer object */
1750 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1751 /* separate draw/read binding points */
1752 if (fb
== ctx
->DrawBuffer
) {
1754 ASSERT(fb
->RefCount
>= 2);
1755 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1757 if (fb
== ctx
->ReadBuffer
) {
1759 ASSERT(fb
->RefCount
>= 2);
1760 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1764 /* only one binding point for read/draw buffers */
1765 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1767 ASSERT(fb
->RefCount
>= 2);
1768 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1772 /* remove from hash table immediately, to free the ID */
1773 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1775 if (fb
!= &DummyFramebuffer
) {
1776 /* But the object will not be freed until it's no longer
1777 * bound in any context.
1779 _mesa_reference_framebuffer(&fb
, NULL
);
1788 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1790 GET_CURRENT_CONTEXT(ctx
);
1794 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1797 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1804 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1806 for (i
= 0; i
< n
; i
++) {
1807 GLuint name
= first
+ i
;
1808 framebuffers
[i
] = name
;
1809 /* insert dummy placeholder into hash table */
1810 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1811 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1812 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1819 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1821 struct gl_framebuffer
*buffer
;
1822 GET_CURRENT_CONTEXT(ctx
);
1824 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1826 buffer
= get_framebuffer_target(ctx
, target
);
1828 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1832 if (is_winsys_fbo(buffer
)) {
1833 /* The window system / default framebuffer is always complete */
1834 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1837 /* No need to flush here */
1839 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1840 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1843 return buffer
->_Status
;
1849 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1852 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1853 GLenum attachment
, GLenum textarget
, GLuint texture
,
1854 GLint level
, GLint zoffset
)
1856 struct gl_renderbuffer_attachment
*att
;
1857 struct gl_texture_object
*texObj
= NULL
;
1858 struct gl_framebuffer
*fb
;
1860 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1862 fb
= get_framebuffer_target(ctx
, target
);
1864 _mesa_error(ctx
, GL_INVALID_ENUM
,
1865 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1869 /* check framebuffer binding */
1870 if (is_winsys_fbo(fb
)) {
1871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1872 "glFramebufferTexture%sEXT", caller
);
1877 /* The textarget, level, and zoffset parameters are only validated if
1878 * texture is non-zero.
1881 GLboolean err
= GL_TRUE
;
1883 texObj
= _mesa_lookup_texture(ctx
, texture
);
1884 if (texObj
!= NULL
) {
1885 if (textarget
== 0) {
1886 /* XXX what's the purpose of this? */
1887 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1888 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1889 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1892 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1893 ? !is_cube_face(textarget
)
1894 : (texObj
->Target
!= textarget
);
1898 /* can't render to a non-existant texture */
1899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1900 "glFramebufferTexture%sEXT(non existant texture)",
1906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1907 "glFramebufferTexture%sEXT(texture target mismatch)",
1912 if (texObj
->Target
== GL_TEXTURE_3D
) {
1913 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1914 if (zoffset
< 0 || zoffset
>= maxSize
) {
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "glFramebufferTexture%sEXT(zoffset)", caller
);
1920 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1921 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1922 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glFramebufferTexture%sEXT(layer)", caller
);
1930 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1931 _mesa_error(ctx
, GL_INVALID_VALUE
,
1932 "glFramebufferTexture%sEXT(level)", caller
);
1937 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1939 _mesa_error(ctx
, GL_INVALID_ENUM
,
1940 "glFramebufferTexture%sEXT(attachment)", caller
);
1944 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1946 _glthread_LOCK_MUTEX(fb
->Mutex
);
1948 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1950 /* Set the render-to-texture flag. We'll check this flag in
1951 * glTexImage() and friends to determine if we need to revalidate
1952 * any FBOs that might be rendering into this texture.
1953 * This flag never gets cleared since it's non-trivial to determine
1954 * when all FBOs might be done rendering to this texture. That's OK
1955 * though since it's uncommon to render to a texture then repeatedly
1956 * call glTexImage() to change images in the texture.
1958 texObj
->_RenderToTexture
= GL_TRUE
;
1961 _mesa_remove_attachment(ctx
, att
);
1964 invalidate_framebuffer(fb
);
1966 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1972 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1973 GLenum textarget
, GLuint texture
, GLint level
)
1975 GET_CURRENT_CONTEXT(ctx
);
1977 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1978 _mesa_error(ctx
, GL_INVALID_ENUM
,
1979 "glFramebufferTexture1DEXT(textarget)");
1983 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1989 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1990 GLenum textarget
, GLuint texture
, GLint level
)
1992 GET_CURRENT_CONTEXT(ctx
);
1994 if ((texture
!= 0) &&
1995 (textarget
!= GL_TEXTURE_2D
) &&
1996 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1997 (!is_cube_face(textarget
))) {
1998 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1999 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
2003 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2009 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
2010 GLenum textarget
, GLuint texture
,
2011 GLint level
, GLint zoffset
)
2013 GET_CURRENT_CONTEXT(ctx
);
2015 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2016 _mesa_error(ctx
, GL_INVALID_ENUM
,
2017 "glFramebufferTexture3DEXT(textarget)");
2021 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2027 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
2028 GLuint texture
, GLint level
, GLint layer
)
2030 GET_CURRENT_CONTEXT(ctx
);
2032 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2038 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
2039 GLenum renderbufferTarget
,
2040 GLuint renderbuffer
)
2042 struct gl_renderbuffer_attachment
*att
;
2043 struct gl_framebuffer
*fb
;
2044 struct gl_renderbuffer
*rb
;
2045 GET_CURRENT_CONTEXT(ctx
);
2047 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2049 fb
= get_framebuffer_target(ctx
, target
);
2051 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2055 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2056 _mesa_error(ctx
, GL_INVALID_ENUM
,
2057 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2061 if (is_winsys_fbo(fb
)) {
2062 /* Can't attach new renderbuffers to a window system framebuffer */
2063 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2067 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2069 _mesa_error(ctx
, GL_INVALID_ENUM
,
2070 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2071 _mesa_lookup_enum_by_nr(attachment
));
2076 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2078 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2079 "glFramebufferRenderbufferEXT(non-existant"
2080 " renderbuffer %u)", renderbuffer
);
2083 else if (rb
== &DummyRenderbuffer
) {
2084 /* This is what NVIDIA does */
2085 _mesa_error(ctx
, GL_INVALID_VALUE
,
2086 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2092 /* remove renderbuffer attachment */
2096 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2097 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2098 /* make sure the renderbuffer is a depth/stencil format */
2099 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2100 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2101 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2102 "glFramebufferRenderbufferEXT(renderbuffer"
2103 " is not DEPTH_STENCIL format)");
2109 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2111 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2112 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2114 /* Some subsequent GL commands may depend on the framebuffer's visual
2115 * after the binding is updated. Update visual info now.
2117 _mesa_update_framebuffer_visual(ctx
, fb
);
2122 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2123 GLenum pname
, GLint
*params
)
2125 const struct gl_renderbuffer_attachment
*att
;
2126 struct gl_framebuffer
*buffer
;
2127 GET_CURRENT_CONTEXT(ctx
);
2129 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2131 buffer
= get_framebuffer_target(ctx
, target
);
2133 _mesa_error(ctx
, GL_INVALID_ENUM
,
2134 "glGetFramebufferAttachmentParameterivEXT(target)");
2138 if (is_winsys_fbo(buffer
)) {
2139 /* the default / window-system FBO */
2140 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2143 /* user-created framebuffer FBO */
2144 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2148 _mesa_error(ctx
, GL_INVALID_ENUM
,
2149 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2153 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2154 /* the depth and stencil attachments must point to the same buffer */
2155 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2156 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2157 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2158 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2160 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2161 " attachments differ)");
2166 /* No need to flush here */
2169 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2170 *params
= is_winsys_fbo(buffer
) ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2172 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2173 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2174 *params
= att
->Renderbuffer
->Name
;
2176 else if (att
->Type
== GL_TEXTURE
) {
2177 *params
= att
->Texture
->Name
;
2180 assert(att
->Type
== GL_NONE
);
2184 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2185 if (att
->Type
== GL_TEXTURE
) {
2186 *params
= att
->TextureLevel
;
2188 else if (att
->Type
== GL_NONE
) {
2189 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2190 "glGetFramebufferAttachmentParameterivEXT(pname)");
2193 _mesa_error(ctx
, GL_INVALID_ENUM
,
2194 "glGetFramebufferAttachmentParameterivEXT(pname)");
2197 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2198 if (att
->Type
== GL_TEXTURE
) {
2199 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2200 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2206 else if (att
->Type
== GL_NONE
) {
2207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2208 "glGetFramebufferAttachmentParameterivEXT(pname)");
2211 _mesa_error(ctx
, GL_INVALID_ENUM
,
2212 "glGetFramebufferAttachmentParameterivEXT(pname)");
2215 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2216 if (att
->Type
== GL_TEXTURE
) {
2217 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2218 *params
= att
->Zoffset
;
2224 else if (att
->Type
== GL_NONE
) {
2225 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2226 "glGetFramebufferAttachmentParameterivEXT(pname)");
2229 _mesa_error(ctx
, GL_INVALID_ENUM
,
2230 "glGetFramebufferAttachmentParameterivEXT(pname)");
2233 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2234 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2235 _mesa_error(ctx
, GL_INVALID_ENUM
,
2236 "glGetFramebufferAttachmentParameterivEXT(pname)");
2238 else if (att
->Type
== GL_NONE
) {
2239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2240 "glGetFramebufferAttachmentParameterivEXT(pname)");
2243 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&& ctx
->Const
.sRGBCapable
) {
2244 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2247 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2248 * if the sRGB conversion is unsupported. */
2249 *params
= GL_LINEAR
;
2253 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2254 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2255 _mesa_error(ctx
, GL_INVALID_ENUM
,
2256 "glGetFramebufferAttachmentParameterivEXT(pname)");
2259 else if (att
->Type
== GL_NONE
) {
2260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2261 "glGetFramebufferAttachmentParameterivEXT(pname)");
2264 gl_format format
= att
->Renderbuffer
->Format
;
2265 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2270 *params
= _mesa_get_format_datatype(format
);
2274 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2275 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2276 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2277 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2278 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2279 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2280 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2281 _mesa_error(ctx
, GL_INVALID_ENUM
,
2282 "glGetFramebufferAttachmentParameterivEXT(pname)");
2284 else if (att
->Type
== GL_NONE
) {
2285 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2286 "glGetFramebufferAttachmentParameterivEXT(pname)");
2288 else if (att
->Texture
) {
2289 const struct gl_texture_image
*texImage
=
2290 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2293 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2294 texImage
->TexFormat
);
2300 else if (att
->Renderbuffer
) {
2301 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2302 att
->Renderbuffer
->Format
);
2305 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2306 " invalid FBO attachment structure");
2310 _mesa_error(ctx
, GL_INVALID_ENUM
,
2311 "glGetFramebufferAttachmentParameterivEXT(pname)");
2318 _mesa_GenerateMipmapEXT(GLenum target
)
2320 struct gl_texture_object
*texObj
;
2321 GET_CURRENT_CONTEXT(ctx
);
2323 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2324 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2330 case GL_TEXTURE_CUBE_MAP
:
2331 /* OK, legal value */
2334 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2335 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2339 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2341 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2346 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2347 !_mesa_cube_complete(texObj
)) {
2348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2349 "glGenerateMipmap(incomplete cube map)");
2353 _mesa_lock_texture(ctx
, texObj
);
2354 if (target
== GL_TEXTURE_CUBE_MAP
) {
2356 for (face
= 0; face
< 6; face
++)
2357 ctx
->Driver
.GenerateMipmap(ctx
,
2358 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2362 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2364 _mesa_unlock_texture(ctx
, texObj
);
2368 #if FEATURE_EXT_framebuffer_blit
2370 static const struct gl_renderbuffer_attachment
*
2371 find_attachment(const struct gl_framebuffer
*fb
,
2372 const struct gl_renderbuffer
*rb
)
2375 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2376 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2377 return &fb
->Attachment
[i
];
2385 * Blit rectangular region, optionally from one framebuffer to another.
2387 * Note, if the src buffer is multisampled and the dest is not, this is
2388 * when the samples must be resolved to a single color.
2391 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2392 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2393 GLbitfield mask
, GLenum filter
)
2395 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2396 GL_DEPTH_BUFFER_BIT
|
2397 GL_STENCIL_BUFFER_BIT
);
2398 const struct gl_framebuffer
*readFb
, *drawFb
;
2399 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2400 GET_CURRENT_CONTEXT(ctx
);
2402 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2403 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2405 if (MESA_VERBOSE
& VERBOSE_API
)
2407 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2408 srcX0
, srcY0
, srcX1
, srcY1
,
2409 dstX0
, dstY0
, dstX1
, dstY1
,
2410 mask
, _mesa_lookup_enum_by_nr(filter
));
2412 if (ctx
->NewState
) {
2413 _mesa_update_state(ctx
);
2416 readFb
= ctx
->ReadBuffer
;
2417 drawFb
= ctx
->DrawBuffer
;
2419 if (!readFb
|| !drawFb
) {
2420 /* This will normally never happen but someday we may want to
2421 * support MakeCurrent() with no drawables.
2426 /* check for complete framebuffers */
2427 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2428 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2429 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2430 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2434 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2435 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2439 if (mask
& ~legalMaskBits
) {
2440 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2444 /* depth/stencil must be blitted with nearest filtering */
2445 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2446 && filter
!= GL_NEAREST
) {
2447 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2448 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2452 /* get color read/draw renderbuffers */
2453 if (mask
& GL_COLOR_BUFFER_BIT
) {
2454 colorReadRb
= readFb
->_ColorReadBuffer
;
2455 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2457 /* From the EXT_framebuffer_object spec:
2459 * "If a buffer is specified in <mask> and does not exist in both
2460 * the read and draw framebuffers, the corresponding bit is silently
2463 if ((colorReadRb
== NULL
) || (colorDrawRb
== NULL
)) {
2464 colorReadRb
= colorDrawRb
= NULL
;
2465 mask
&= ~GL_COLOR_BUFFER_BIT
;
2469 colorReadRb
= colorDrawRb
= NULL
;
2472 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2473 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2474 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2476 /* From the EXT_framebuffer_object spec:
2478 * "If a buffer is specified in <mask> and does not exist in both
2479 * the read and draw framebuffers, the corresponding bit is silently
2482 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
2483 readRb
= drawRb
= NULL
;
2484 mask
&= ~GL_STENCIL_BUFFER_BIT
;
2486 else if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2487 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2489 "glBlitFramebufferEXT(stencil buffer size mismatch)");
2494 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2495 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2496 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2498 /* From the EXT_framebuffer_object spec:
2500 * "If a buffer is specified in <mask> and does not exist in both
2501 * the read and draw framebuffers, the corresponding bit is silently
2504 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
2505 readRb
= drawRb
= NULL
;
2506 mask
&= ~GL_DEPTH_BUFFER_BIT
;
2508 else if (_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2509 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2510 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2511 "glBlitFramebufferEXT(depth buffer size mismatch)");
2516 if (readFb
->Visual
.samples
> 0 &&
2517 drawFb
->Visual
.samples
> 0 &&
2518 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2519 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2520 "glBlitFramebufferEXT(mismatched samples");
2524 /* extra checks for multisample copies... */
2525 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2526 /* src and dest region sizes must be the same */
2527 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2528 srcY1
- srcY0
!= dstY1
- dstY0
) {
2529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2530 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
2534 /* color formats must match */
2537 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2539 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
2544 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2545 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2551 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2553 srcX0
, srcY0
, srcX1
, srcY1
,
2554 dstX0
, dstY0
, dstX1
, dstY1
,
2557 const struct gl_renderbuffer_attachment
*att
;
2559 att
= find_attachment(readFb
, colorReadRb
);
2560 printf(" Src FBO %u RB %u (%dx%d) ",
2561 readFb
->Name
, colorReadRb
->Name
,
2562 colorReadRb
->Width
, colorReadRb
->Height
);
2563 if (att
&& att
->Texture
) {
2564 printf("Tex %u tgt 0x%x level %u face %u",
2566 att
->Texture
->Target
,
2572 att
= find_attachment(drawFb
, colorDrawRb
);
2573 printf(" Dst FBO %u RB %u (%dx%d) ",
2574 drawFb
->Name
, colorDrawRb
->Name
,
2575 colorDrawRb
->Width
, colorDrawRb
->Height
);
2576 if (att
&& att
->Texture
) {
2577 printf("Tex %u tgt 0x%x level %u face %u",
2579 att
->Texture
->Target
,
2587 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2588 ctx
->Driver
.BlitFramebuffer(ctx
,
2589 srcX0
, srcY0
, srcX1
, srcY1
,
2590 dstX0
, dstY0
, dstX1
, dstY1
,
2593 #endif /* FEATURE_EXT_framebuffer_blit */
2595 #if FEATURE_ARB_geometry_shader4
2597 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2598 GLuint texture
, GLint level
)
2600 GET_CURRENT_CONTEXT(ctx
);
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glFramebufferTextureARB "
2603 "not implemented!");
2607 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2608 GLuint texture
, GLint level
, GLenum face
)
2610 GET_CURRENT_CONTEXT(ctx
);
2611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2612 "glFramebufferTextureFaceARB "
2613 "not implemented!");
2615 #endif /* FEATURE_ARB_geometry_shader4 */