2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
40 #include "framebuffer.h"
43 #include "mfeatures.h"
45 #include "renderbuffer.h"
51 /** Set this to 1 to help debug FBO incompleteness problems */
54 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
61 * None of the GL_EXT_framebuffer_object functions are compiled into
68 * When glGenRender/FramebuffersEXT() is called we insert pointers to
69 * these placeholder objects into the hash table.
70 * Later, when the object ID is first bound, we replace the placeholder
71 * with the real frame/renderbuffer.
73 static struct gl_framebuffer DummyFramebuffer
;
74 static struct gl_renderbuffer DummyRenderbuffer
;
76 /* We bind this framebuffer when applications pass a NULL
77 * drawable/surface in make current. */
78 static struct gl_framebuffer IncompleteFramebuffer
;
81 #define IS_CUBE_FACE(TARGET) \
82 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
83 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
87 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
93 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
100 _mesa_init_fbobjects(struct gl_context
*ctx
)
102 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
103 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
104 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
105 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
106 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
107 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
110 struct gl_framebuffer
*
111 _mesa_get_incomplete_framebuffer(void)
113 return &IncompleteFramebuffer
;
117 * Helper routine for getting a gl_renderbuffer.
119 struct gl_renderbuffer
*
120 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
122 struct gl_renderbuffer
*rb
;
127 rb
= (struct gl_renderbuffer
*)
128 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
134 * Helper routine for getting a gl_framebuffer.
136 struct gl_framebuffer
*
137 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
139 struct gl_framebuffer
*fb
;
144 fb
= (struct gl_framebuffer
*)
145 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
151 * Mark the given framebuffer as invalid. This will force the
152 * test for framebuffer completeness to be done before the framebuffer
156 invalidate_framebuffer(struct gl_framebuffer
*fb
)
158 fb
->_Status
= 0; /* "indeterminate" */
163 * Return the gl_framebuffer object which corresponds to the given
164 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
165 * Check support for GL_EXT_framebuffer_blit to determine if certain
167 * \return gl_framebuffer pointer or NULL if target is illegal
169 static struct gl_framebuffer
*
170 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
173 case GL_DRAW_FRAMEBUFFER
:
174 return ctx
->Extensions
.EXT_framebuffer_blit
? ctx
->DrawBuffer
: NULL
;
175 case GL_READ_FRAMEBUFFER
:
176 return ctx
->Extensions
.EXT_framebuffer_blit
? ctx
->ReadBuffer
: NULL
;
177 case GL_FRAMEBUFFER_EXT
:
178 return ctx
->DrawBuffer
;
186 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
187 * gl_renderbuffer_attachment object.
188 * This function is only used for user-created FB objects, not the
189 * default / window-system FB object.
190 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
191 * the depth buffer attachment point.
193 struct gl_renderbuffer_attachment
*
194 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
199 assert(fb
->Name
> 0);
201 switch (attachment
) {
202 case GL_COLOR_ATTACHMENT0_EXT
:
203 case GL_COLOR_ATTACHMENT1_EXT
:
204 case GL_COLOR_ATTACHMENT2_EXT
:
205 case GL_COLOR_ATTACHMENT3_EXT
:
206 case GL_COLOR_ATTACHMENT4_EXT
:
207 case GL_COLOR_ATTACHMENT5_EXT
:
208 case GL_COLOR_ATTACHMENT6_EXT
:
209 case GL_COLOR_ATTACHMENT7_EXT
:
210 case GL_COLOR_ATTACHMENT8_EXT
:
211 case GL_COLOR_ATTACHMENT9_EXT
:
212 case GL_COLOR_ATTACHMENT10_EXT
:
213 case GL_COLOR_ATTACHMENT11_EXT
:
214 case GL_COLOR_ATTACHMENT12_EXT
:
215 case GL_COLOR_ATTACHMENT13_EXT
:
216 case GL_COLOR_ATTACHMENT14_EXT
:
217 case GL_COLOR_ATTACHMENT15_EXT
:
218 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
219 if (i
>= ctx
->Const
.MaxColorAttachments
) {
222 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
223 case GL_DEPTH_STENCIL_ATTACHMENT
:
225 case GL_DEPTH_BUFFER
:
226 /* fall-through / new in GL 3.0 */
227 case GL_DEPTH_ATTACHMENT_EXT
:
228 return &fb
->Attachment
[BUFFER_DEPTH
];
229 case GL_STENCIL_BUFFER
:
230 /* fall-through / new in GL 3.0 */
231 case GL_STENCIL_ATTACHMENT_EXT
:
232 return &fb
->Attachment
[BUFFER_STENCIL
];
240 * As above, but only used for getting attachments of the default /
241 * window-system framebuffer (not user-created framebuffer objects).
243 static struct gl_renderbuffer_attachment
*
244 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
247 assert(fb
->Name
== 0);
249 switch (attachment
) {
251 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
253 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
255 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
257 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
259 if (fb
->Visual
.numAuxBuffers
== 1) {
260 return &fb
->Attachment
[BUFFER_AUX0
];
263 case GL_DEPTH_BUFFER
:
264 /* fall-through / new in GL 3.0 */
265 case GL_DEPTH_ATTACHMENT_EXT
:
266 return &fb
->Attachment
[BUFFER_DEPTH
];
267 case GL_STENCIL_BUFFER
:
268 /* fall-through / new in GL 3.0 */
269 case GL_STENCIL_ATTACHMENT_EXT
:
270 return &fb
->Attachment
[BUFFER_STENCIL
];
279 * Remove any texture or renderbuffer attached to the given attachment
280 * point. Update reference counts, etc.
283 _mesa_remove_attachment(struct gl_context
*ctx
,
284 struct gl_renderbuffer_attachment
*att
)
286 if (att
->Type
== GL_TEXTURE
) {
287 ASSERT(att
->Texture
);
288 if (ctx
->Driver
.FinishRenderTexture
) {
289 /* tell driver that we're done rendering to this texture. */
290 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
292 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
293 ASSERT(!att
->Texture
);
295 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
296 ASSERT(!att
->Texture
);
297 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
298 ASSERT(!att
->Renderbuffer
);
301 att
->Complete
= GL_TRUE
;
306 * Bind a texture object to an attachment point.
307 * The previous binding, if any, will be removed first.
310 _mesa_set_texture_attachment(struct gl_context
*ctx
,
311 struct gl_framebuffer
*fb
,
312 struct gl_renderbuffer_attachment
*att
,
313 struct gl_texture_object
*texObj
,
314 GLenum texTarget
, GLuint level
, GLuint zoffset
)
316 if (att
->Texture
== texObj
) {
317 /* re-attaching same texture */
318 ASSERT(att
->Type
== GL_TEXTURE
);
319 if (ctx
->Driver
.FinishRenderTexture
)
320 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
324 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
325 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
326 _mesa_remove_attachment(ctx
, att
);
327 att
->Type
= GL_TEXTURE
;
328 assert(!att
->Texture
);
329 _mesa_reference_texobj(&att
->Texture
, texObj
);
332 /* always update these fields */
333 att
->TextureLevel
= level
;
334 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
335 att
->Zoffset
= zoffset
;
336 att
->Complete
= GL_FALSE
;
338 if (_mesa_get_attachment_teximage(att
)) {
339 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
342 invalidate_framebuffer(fb
);
347 * Bind a renderbuffer to an attachment point.
348 * The previous binding, if any, will be removed first.
351 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
352 struct gl_renderbuffer_attachment
*att
,
353 struct gl_renderbuffer
*rb
)
355 /* XXX check if re-doing same attachment, exit early */
356 _mesa_remove_attachment(ctx
, att
);
357 att
->Type
= GL_RENDERBUFFER_EXT
;
358 att
->Texture
= NULL
; /* just to be safe */
359 att
->Complete
= GL_FALSE
;
360 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
365 * Fallback for ctx->Driver.FramebufferRenderbuffer()
366 * Attach a renderbuffer object to a framebuffer object.
369 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
370 struct gl_framebuffer
*fb
,
371 GLenum attachment
, struct gl_renderbuffer
*rb
)
373 struct gl_renderbuffer_attachment
*att
;
375 _glthread_LOCK_MUTEX(fb
->Mutex
);
377 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
380 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
381 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
382 /* do stencil attachment here (depth already done above) */
383 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
385 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
387 rb
->AttachedAnytime
= GL_TRUE
;
390 _mesa_remove_attachment(ctx
, att
);
393 invalidate_framebuffer(fb
);
395 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
400 * Fallback for ctx->Driver.ValidateFramebuffer()
401 * Check if the renderbuffer's formats are supported by the software
403 * Drivers should probably override this.
406 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
409 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
410 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
412 switch (rb
->_BaseFormat
) {
414 case GL_LUMINANCE_ALPHA
:
419 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
422 /* render buffer format is supported by software rendering */
434 att_incomplete(const char *msg
)
437 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
448 fbo_incomplete(const char *msg
, int index
)
451 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
460 * Is the given base format a legal format for a color renderbuffer?
463 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
465 switch (baseFormat
) {
470 case GL_LUMINANCE_ALPHA
:
473 return ctx
->Extensions
.ARB_framebuffer_object
;
476 return ctx
->Extensions
.ARB_texture_rg
;
484 * Is the given base format a legal format for a depth/stencil renderbuffer?
487 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
489 switch (baseFormat
) {
490 case GL_DEPTH_COMPONENT
:
491 case GL_DEPTH_STENCIL_EXT
:
500 * Test if an attachment point is complete and update its Complete field.
501 * \param format if GL_COLOR, this is a color attachment point,
502 * if GL_DEPTH, this is a depth component attachment point,
503 * if GL_STENCIL, this is a stencil component attachment point.
506 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
507 struct gl_renderbuffer_attachment
*att
)
509 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
511 /* assume complete */
512 att
->Complete
= GL_TRUE
;
514 /* Look for reasons why the attachment might be incomplete */
515 if (att
->Type
== GL_TEXTURE
) {
516 const struct gl_texture_object
*texObj
= att
->Texture
;
517 struct gl_texture_image
*texImage
;
521 att_incomplete("no texobj");
522 att
->Complete
= GL_FALSE
;
526 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
528 att_incomplete("no teximage");
529 att
->Complete
= GL_FALSE
;
532 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
533 att_incomplete("teximage width/height=0");
534 printf("texobj = %u\n", texObj
->Name
);
535 printf("level = %d\n", att
->TextureLevel
);
536 att
->Complete
= GL_FALSE
;
539 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
540 att_incomplete("bad z offset");
541 att
->Complete
= GL_FALSE
;
545 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
547 if (format
== GL_COLOR
) {
548 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
549 att_incomplete("bad format");
550 att
->Complete
= GL_FALSE
;
553 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
554 att_incomplete("compressed internalformat");
555 att
->Complete
= GL_FALSE
;
559 else if (format
== GL_DEPTH
) {
560 if (baseFormat
== GL_DEPTH_COMPONENT
) {
563 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
564 ctx
->Extensions
.ARB_depth_texture
&&
565 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
569 att
->Complete
= GL_FALSE
;
570 att_incomplete("bad depth format");
575 ASSERT(format
== GL_STENCIL
);
576 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
577 ctx
->Extensions
.ARB_depth_texture
&&
578 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
582 /* no such thing as stencil-only textures */
583 att_incomplete("illegal stencil texture");
584 att
->Complete
= GL_FALSE
;
589 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
590 const GLenum baseFormat
=
591 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
593 ASSERT(att
->Renderbuffer
);
594 if (!att
->Renderbuffer
->InternalFormat
||
595 att
->Renderbuffer
->Width
< 1 ||
596 att
->Renderbuffer
->Height
< 1) {
597 att_incomplete("0x0 renderbuffer");
598 att
->Complete
= GL_FALSE
;
601 if (format
== GL_COLOR
) {
602 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
603 att_incomplete("bad renderbuffer color format");
604 att
->Complete
= GL_FALSE
;
608 else if (format
== GL_DEPTH
) {
609 if (baseFormat
== GL_DEPTH_COMPONENT
) {
612 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
613 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
617 att_incomplete("bad renderbuffer depth format");
618 att
->Complete
= GL_FALSE
;
623 assert(format
== GL_STENCIL
);
624 if (baseFormat
== GL_STENCIL_INDEX
) {
627 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
628 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
632 att
->Complete
= GL_FALSE
;
633 att_incomplete("bad renderbuffer stencil format");
639 ASSERT(att
->Type
== GL_NONE
);
647 * Test if the given framebuffer object is complete and update its
648 * Status field with the results.
649 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
650 * driver to make hardware-specific validation/completeness checks.
651 * Also update the framebuffer's Width and Height fields if the
652 * framebuffer is complete.
655 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
656 struct gl_framebuffer
*fb
)
659 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
660 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
661 GLint numSamples
= -1;
665 assert(fb
->Name
!= 0);
671 /* Start at -2 to more easily loop over all attachment points.
676 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
677 struct gl_renderbuffer_attachment
*att
;
682 * XXX for ARB_fbo, only check color buffers that are named by
683 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
686 /* check for attachment completeness
689 att
= &fb
->Attachment
[BUFFER_DEPTH
];
690 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
691 if (!att
->Complete
) {
692 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
693 fbo_incomplete("depth attachment incomplete", -1);
698 att
= &fb
->Attachment
[BUFFER_STENCIL
];
699 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
700 if (!att
->Complete
) {
701 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
702 fbo_incomplete("stencil attachment incomplete", -1);
707 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
708 test_attachment_completeness(ctx
, GL_COLOR
, att
);
709 if (!att
->Complete
) {
710 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
711 fbo_incomplete("color attachment incomplete", i
);
716 /* get width, height, format of the renderbuffer/texture
718 if (att
->Type
== GL_TEXTURE
) {
719 const struct gl_texture_image
*texImg
=
720 _mesa_get_attachment_teximage(att
);
721 minWidth
= MIN2(minWidth
, texImg
->Width
);
722 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
723 minHeight
= MIN2(minHeight
, texImg
->Height
);
724 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
725 f
= texImg
->_BaseFormat
;
726 attFormat
= texImg
->TexFormat
;
728 if (!_mesa_is_legal_color_format(ctx
, f
) &&
729 !is_legal_depth_format(ctx
, f
)) {
730 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
731 fbo_incomplete("texture attachment incomplete", -1);
735 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
736 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
737 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
738 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
739 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
740 f
= att
->Renderbuffer
->InternalFormat
;
741 attFormat
= att
->Renderbuffer
->Format
;
745 assert(att
->Type
== GL_NONE
);
749 if (att
->Renderbuffer
&& numSamples
< 0) {
751 numSamples
= att
->Renderbuffer
->NumSamples
;
754 /* check if integer color */
755 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
757 /* Error-check width, height, format, samples
759 if (numImages
== 1) {
760 /* save format, num samples */
766 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
767 /* check that width, height, format are same */
768 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
769 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
770 fbo_incomplete("width or height mismatch", -1);
773 /* check that all color buffer have same format */
774 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
775 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
776 fbo_incomplete("format mismatch", -1);
780 if (att
->Renderbuffer
&&
781 att
->Renderbuffer
->NumSamples
!= numSamples
) {
782 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
783 fbo_incomplete("inconsistant number of samples", i
);
791 if (ctx
->API
== API_OPENGL
) {
792 /* Check that all DrawBuffers are present */
793 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
794 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
795 const struct gl_renderbuffer_attachment
*att
796 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
798 if (att
->Type
== GL_NONE
) {
799 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
800 fbo_incomplete("missing drawbuffer", j
);
806 /* Check that the ReadBuffer is present */
807 if (fb
->ColorReadBuffer
!= GL_NONE
) {
808 const struct gl_renderbuffer_attachment
*att
809 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
811 if (att
->Type
== GL_NONE
) {
812 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
813 fbo_incomplete("missing readbuffer", -1);
822 if (numImages
== 0) {
823 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
824 fbo_incomplete("no attachments", -1);
828 /* Provisionally set status = COMPLETE ... */
829 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
831 /* ... but the driver may say the FB is incomplete.
832 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
835 if (ctx
->Driver
.ValidateFramebuffer
) {
836 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
837 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
838 fbo_incomplete("driver marked FBO as incomplete", -1);
842 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
844 * Note that if ARB_framebuffer_object is supported and the attached
845 * renderbuffers/textures are different sizes, the framebuffer
846 * width/height will be set to the smallest width/height.
848 fb
->Width
= minWidth
;
849 fb
->Height
= minHeight
;
851 /* finally, update the visual info for the framebuffer */
852 _mesa_update_framebuffer_visual(ctx
, fb
);
858 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
860 GET_CURRENT_CONTEXT(ctx
);
861 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
863 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
864 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
872 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
874 struct gl_renderbuffer
*newRb
;
875 GET_CURRENT_CONTEXT(ctx
);
877 ASSERT_OUTSIDE_BEGIN_END(ctx
);
879 if (target
!= GL_RENDERBUFFER_EXT
) {
880 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
884 /* No need to flush here since the render buffer binding has no
885 * effect on rendering state.
889 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
890 if (newRb
== &DummyRenderbuffer
) {
891 /* ID was reserved, but no real renderbuffer object made yet */
894 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
895 /* All RB IDs must be Gen'd */
896 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
901 /* create new renderbuffer object */
902 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
904 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
907 ASSERT(newRb
->AllocStorage
);
908 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
909 newRb
->RefCount
= 1; /* referenced by hash table */
916 ASSERT(newRb
!= &DummyRenderbuffer
);
918 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
923 * If the given renderbuffer is anywhere attached to the framebuffer, detach
925 * This is used when a renderbuffer object is deleted.
926 * The spec calls for unbinding.
929 detach_renderbuffer(struct gl_context
*ctx
,
930 struct gl_framebuffer
*fb
,
931 struct gl_renderbuffer
*rb
)
934 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
935 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
936 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
939 invalidate_framebuffer(fb
);
944 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
947 GET_CURRENT_CONTEXT(ctx
);
949 ASSERT_OUTSIDE_BEGIN_END(ctx
);
950 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
952 for (i
= 0; i
< n
; i
++) {
953 if (renderbuffers
[i
] > 0) {
954 struct gl_renderbuffer
*rb
;
955 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
957 /* check if deleting currently bound renderbuffer object */
958 if (rb
== ctx
->CurrentRenderbuffer
) {
960 ASSERT(rb
->RefCount
>= 2);
961 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
964 if (ctx
->DrawBuffer
->Name
) {
965 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
967 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
968 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
971 /* Remove from hash table immediately, to free the ID.
972 * But the object will not be freed until it's no longer
973 * referenced anywhere else.
975 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
977 if (rb
!= &DummyRenderbuffer
) {
978 /* no longer referenced by hash table */
979 _mesa_reference_renderbuffer(&rb
, NULL
);
988 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
990 GET_CURRENT_CONTEXT(ctx
);
994 ASSERT_OUTSIDE_BEGIN_END(ctx
);
997 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1004 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1006 for (i
= 0; i
< n
; i
++) {
1007 GLuint name
= first
+ i
;
1008 renderbuffers
[i
] = name
;
1009 /* insert dummy placeholder into hash table */
1010 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1011 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1012 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1018 * Given an internal format token for a render buffer, return the
1019 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1020 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1021 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1023 * This is similar to _mesa_base_tex_format() but the set of valid
1024 * internal formats is different.
1026 * Note that even if a format is determined to be legal here, validation
1027 * of the FBO may fail if the format is not supported by the driver/GPU.
1029 * \param internalFormat as passed to glRenderbufferStorage()
1030 * \return the base internal format, or 0 if internalFormat is illegal
1033 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1036 * Notes: some formats such as alpha, luminance, etc. were added
1037 * with GL_ARB_framebuffer_object.
1039 switch (internalFormat
) {
1045 return ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1049 case GL_LUMINANCE12
:
1050 case GL_LUMINANCE16
:
1051 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1052 case GL_LUMINANCE_ALPHA
:
1053 case GL_LUMINANCE4_ALPHA4
:
1054 case GL_LUMINANCE6_ALPHA2
:
1055 case GL_LUMINANCE8_ALPHA8
:
1056 case GL_LUMINANCE12_ALPHA4
:
1057 case GL_LUMINANCE12_ALPHA12
:
1058 case GL_LUMINANCE16_ALPHA16
:
1059 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1063 case GL_INTENSITY12
:
1064 case GL_INTENSITY16
:
1065 return ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1084 case GL_SRGB8_ALPHA8_EXT
:
1086 case GL_STENCIL_INDEX
:
1087 case GL_STENCIL_INDEX1_EXT
:
1088 case GL_STENCIL_INDEX4_EXT
:
1089 case GL_STENCIL_INDEX8_EXT
:
1090 case GL_STENCIL_INDEX16_EXT
:
1091 return GL_STENCIL_INDEX
;
1092 case GL_DEPTH_COMPONENT
:
1093 case GL_DEPTH_COMPONENT16
:
1094 case GL_DEPTH_COMPONENT24
:
1095 case GL_DEPTH_COMPONENT32
:
1096 return GL_DEPTH_COMPONENT
;
1097 case GL_DEPTH_STENCIL_EXT
:
1098 case GL_DEPTH24_STENCIL8_EXT
:
1099 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
1100 return GL_DEPTH_STENCIL_EXT
;
1106 return ctx
->Extensions
.ARB_texture_rg
? GL_RED
: 0;
1110 return ctx
->Extensions
.ARB_texture_rg
? GL_RG
: 0;
1111 /* signed normalized texture formats */
1115 return ctx
->Extensions
.EXT_texture_snorm
? GL_RED
: 0;
1119 return ctx
->Extensions
.EXT_texture_snorm
? GL_RG
: 0;
1122 case GL_RGB16_SNORM
:
1123 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGB
: 0;
1125 case GL_RGBA8_SNORM
:
1126 case GL_RGBA16_SNORM
:
1127 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGBA
: 0;
1128 case GL_ALPHA_SNORM
:
1129 case GL_ALPHA8_SNORM
:
1130 case GL_ALPHA16_SNORM
:
1131 return ctx
->Extensions
.EXT_texture_snorm
&&
1132 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1133 case GL_LUMINANCE_SNORM
:
1134 case GL_LUMINANCE8_SNORM
:
1135 case GL_LUMINANCE16_SNORM
:
1136 return ctx
->Extensions
.EXT_texture_snorm
&&
1137 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1138 case GL_LUMINANCE_ALPHA_SNORM
:
1139 case GL_LUMINANCE8_ALPHA8_SNORM
:
1140 case GL_LUMINANCE16_ALPHA16_SNORM
:
1141 return ctx
->Extensions
.EXT_texture_snorm
&&
1142 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1143 case GL_INTENSITY_SNORM
:
1144 case GL_INTENSITY8_SNORM
:
1145 case GL_INTENSITY16_SNORM
:
1146 return ctx
->Extensions
.EXT_texture_snorm
&&
1147 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1148 /* XXX add floating point and integer formats eventually */
1156 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1159 invalidate_rb(GLuint key
, void *data
, void *userData
)
1161 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1162 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1164 /* If this is a user-created FBO */
1167 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1168 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1169 if (att
->Type
== GL_RENDERBUFFER
&&
1170 att
->Renderbuffer
== rb
) {
1171 /* Mark fb status as indeterminate to force re-validation */
1180 /** sentinal value, see below */
1181 #define NO_SAMPLES 1000
1185 * Helper function used by _mesa_RenderbufferStorageEXT() and
1186 * _mesa_RenderbufferStorageMultisample().
1187 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1190 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1191 GLsizei width
, GLsizei height
, GLsizei samples
)
1193 const char *func
= samples
== NO_SAMPLES
?
1194 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1195 struct gl_renderbuffer
*rb
;
1197 GET_CURRENT_CONTEXT(ctx
);
1199 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1201 if (target
!= GL_RENDERBUFFER_EXT
) {
1202 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1206 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1207 if (baseFormat
== 0) {
1208 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1212 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1213 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1217 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1218 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1222 if (samples
== NO_SAMPLES
) {
1223 /* NumSamples == 0 indicates non-multisampling */
1226 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1227 /* note: driver may choose to use more samples than what's requested */
1228 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1232 rb
= ctx
->CurrentRenderbuffer
;
1234 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1238 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1240 if (rb
->InternalFormat
== internalFormat
&&
1241 rb
->Width
== (GLuint
) width
&&
1242 rb
->Height
== (GLuint
) height
) {
1243 /* no change in allocation needed */
1247 /* These MUST get set by the AllocStorage func */
1248 rb
->Format
= MESA_FORMAT_NONE
;
1249 rb
->NumSamples
= samples
;
1251 /* Now allocate the storage */
1252 ASSERT(rb
->AllocStorage
);
1253 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1254 /* No error - check/set fields now */
1255 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1256 assert(rb
->Width
== (GLuint
) width
);
1257 assert(rb
->Height
== (GLuint
) height
);
1258 rb
->InternalFormat
= internalFormat
;
1259 rb
->_BaseFormat
= baseFormat
;
1260 assert(rb
->_BaseFormat
!= 0);
1263 /* Probably ran out of memory - clear the fields */
1266 rb
->Format
= MESA_FORMAT_NONE
;
1267 rb
->InternalFormat
= GL_NONE
;
1268 rb
->_BaseFormat
= GL_NONE
;
1272 /* Invalidate the framebuffers the renderbuffer is attached in. */
1273 if (rb
->AttachedAnytime
) {
1274 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1279 #if FEATURE_OES_EGL_image
1281 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1283 struct gl_renderbuffer
*rb
;
1284 GET_CURRENT_CONTEXT(ctx
);
1285 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1287 if (!ctx
->Extensions
.OES_EGL_image
) {
1288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1289 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1293 if (target
!= GL_RENDERBUFFER
) {
1294 _mesa_error(ctx
, GL_INVALID_ENUM
,
1295 "EGLImageTargetRenderbufferStorageOES");
1299 rb
= ctx
->CurrentRenderbuffer
;
1301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1302 "EGLImageTargetRenderbufferStorageOES");
1306 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1308 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1314 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1315 * _mesa_GetFramebufferAttachmentParameterivEXT()
1316 * We have to be careful to respect the base format. For example, if a
1317 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1318 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1319 * we need to return zero.
1322 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1325 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1326 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1327 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1328 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1329 return _mesa_get_format_bits(format
, pname
);
1332 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1333 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1334 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1335 return _mesa_get_format_bits(format
, pname
);
1338 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1339 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1340 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1341 return _mesa_get_format_bits(format
, pname
);
1344 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1345 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1346 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1347 baseFormat
== GL_LUMINANCE_ALPHA
)
1348 return _mesa_get_format_bits(format
, pname
);
1351 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1352 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1353 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1354 return _mesa_get_format_bits(format
, pname
);
1357 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1358 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1359 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1360 return _mesa_get_format_bits(format
, pname
);
1371 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1372 GLsizei width
, GLsizei height
)
1374 /* GL_ARB_fbo says calling this function is equivalent to calling
1375 * glRenderbufferStorageMultisample() with samples=0. We pass in
1376 * a token value here just for error reporting purposes.
1378 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1383 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1384 GLenum internalFormat
,
1385 GLsizei width
, GLsizei height
)
1387 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1392 * OpenGL ES version of glRenderBufferStorage.
1395 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1396 GLsizei width
, GLsizei height
)
1398 switch (internalFormat
) {
1400 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1401 /* choose a closest format */
1402 internalFormat
= GL_RGB5
;
1408 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1413 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1415 struct gl_renderbuffer
*rb
;
1416 GET_CURRENT_CONTEXT(ctx
);
1418 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1420 if (target
!= GL_RENDERBUFFER_EXT
) {
1421 _mesa_error(ctx
, GL_INVALID_ENUM
,
1422 "glGetRenderbufferParameterivEXT(target)");
1426 rb
= ctx
->CurrentRenderbuffer
;
1428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1429 "glGetRenderbufferParameterivEXT");
1433 /* No need to flush here since we're just quering state which is
1434 * not effected by rendering.
1438 case GL_RENDERBUFFER_WIDTH_EXT
:
1439 *params
= rb
->Width
;
1441 case GL_RENDERBUFFER_HEIGHT_EXT
:
1442 *params
= rb
->Height
;
1444 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1445 *params
= rb
->InternalFormat
;
1447 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1448 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1449 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1450 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1451 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1452 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1453 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1455 case GL_RENDERBUFFER_SAMPLES
:
1456 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1457 *params
= rb
->NumSamples
;
1462 _mesa_error(ctx
, GL_INVALID_ENUM
,
1463 "glGetRenderbufferParameterivEXT(target)");
1469 GLboolean GLAPIENTRY
1470 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1472 GET_CURRENT_CONTEXT(ctx
);
1473 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1475 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1476 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1484 * Check if any of the attachments of the given framebuffer are textures
1485 * (render to texture). Call ctx->Driver.RenderTexture() for such
1489 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1492 ASSERT(ctx
->Driver
.RenderTexture
);
1495 return; /* can't render to texture with winsys framebuffers */
1497 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1498 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1499 if (att
->Texture
&& _mesa_get_attachment_teximage(att
)) {
1500 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1507 * Examine all the framebuffer's attachments to see if any are textures.
1508 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1509 * notify the device driver that the texture image may have changed.
1512 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1515 return; /* can't render to texture with winsys framebuffers */
1517 if (ctx
->Driver
.FinishRenderTexture
) {
1519 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1520 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1521 if (att
->Texture
&& att
->Renderbuffer
) {
1522 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1530 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1532 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1533 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1534 GLboolean bindReadBuf
, bindDrawBuf
;
1535 GET_CURRENT_CONTEXT(ctx
);
1538 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1539 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1540 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1544 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1546 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1548 "glBindFramebufferEXT(unsupported)");
1553 #if FEATURE_EXT_framebuffer_blit
1554 case GL_DRAW_FRAMEBUFFER_EXT
:
1555 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1556 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1559 bindDrawBuf
= GL_TRUE
;
1560 bindReadBuf
= GL_FALSE
;
1562 case GL_READ_FRAMEBUFFER_EXT
:
1563 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1564 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1567 bindDrawBuf
= GL_FALSE
;
1568 bindReadBuf
= GL_TRUE
;
1571 case GL_FRAMEBUFFER_EXT
:
1572 bindDrawBuf
= GL_TRUE
;
1573 bindReadBuf
= GL_TRUE
;
1576 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1581 /* Binding a user-created framebuffer object */
1582 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1583 if (newDrawFb
== &DummyFramebuffer
) {
1584 /* ID was reserved, but no real framebuffer object made yet */
1587 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1588 /* All FBO IDs must be Gen'd */
1589 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1594 /* create new framebuffer object */
1595 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1597 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1600 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1602 newReadFb
= newDrawFb
;
1605 /* Binding the window system framebuffer (which was originally set
1606 * with MakeCurrent).
1608 newDrawFb
= ctx
->WinSysDrawBuffer
;
1609 newReadFb
= ctx
->WinSysReadBuffer
;
1613 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1615 /* save pointers to current/old framebuffers */
1616 oldDrawFb
= ctx
->DrawBuffer
;
1617 oldReadFb
= ctx
->ReadBuffer
;
1619 /* check if really changing bindings */
1620 if (oldDrawFb
== newDrawFb
)
1621 bindDrawBuf
= GL_FALSE
;
1622 if (oldReadFb
== newReadFb
)
1623 bindReadBuf
= GL_FALSE
;
1626 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1628 * We also check if we're beginning and/or ending render-to-texture.
1629 * When a framebuffer with texture attachments is unbound, call
1630 * ctx->Driver.FinishRenderTexture().
1631 * When a framebuffer with texture attachments is bound, call
1632 * ctx->Driver.RenderTexture().
1634 * Note that if the ReadBuffer has texture attachments we don't consider
1635 * that a render-to-texture case.
1638 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1640 /* check if old readbuffer was render-to-texture */
1641 check_end_texture_render(ctx
, oldReadFb
);
1643 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1647 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1649 /* check if old read/draw buffers were render-to-texture */
1651 check_end_texture_render(ctx
, oldReadFb
);
1653 if (oldDrawFb
!= oldReadFb
)
1654 check_end_texture_render(ctx
, oldDrawFb
);
1656 /* check if newly bound framebuffer has any texture attachments */
1657 check_begin_texture_render(ctx
, newDrawFb
);
1659 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1662 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1663 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1669 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1672 GET_CURRENT_CONTEXT(ctx
);
1674 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1675 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1677 for (i
= 0; i
< n
; i
++) {
1678 if (framebuffers
[i
] > 0) {
1679 struct gl_framebuffer
*fb
;
1680 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1682 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1684 /* check if deleting currently bound framebuffer object */
1685 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1686 /* separate draw/read binding points */
1687 if (fb
== ctx
->DrawBuffer
) {
1689 ASSERT(fb
->RefCount
>= 2);
1690 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1692 if (fb
== ctx
->ReadBuffer
) {
1694 ASSERT(fb
->RefCount
>= 2);
1695 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1699 /* only one binding point for read/draw buffers */
1700 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1702 ASSERT(fb
->RefCount
>= 2);
1703 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1707 /* remove from hash table immediately, to free the ID */
1708 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1710 if (fb
!= &DummyFramebuffer
) {
1711 /* But the object will not be freed until it's no longer
1712 * bound in any context.
1714 _mesa_reference_framebuffer(&fb
, NULL
);
1723 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1725 GET_CURRENT_CONTEXT(ctx
);
1729 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1732 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1739 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1741 for (i
= 0; i
< n
; i
++) {
1742 GLuint name
= first
+ i
;
1743 framebuffers
[i
] = name
;
1744 /* insert dummy placeholder into hash table */
1745 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1746 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1747 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1754 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1756 struct gl_framebuffer
*buffer
;
1757 GET_CURRENT_CONTEXT(ctx
);
1759 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1761 buffer
= get_framebuffer_target(ctx
, target
);
1763 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1767 if (buffer
->Name
== 0) {
1768 /* The window system / default framebuffer is always complete */
1769 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1772 /* No need to flush here */
1774 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1775 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1778 return buffer
->_Status
;
1784 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1787 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1788 GLenum attachment
, GLenum textarget
, GLuint texture
,
1789 GLint level
, GLint zoffset
)
1791 struct gl_renderbuffer_attachment
*att
;
1792 struct gl_texture_object
*texObj
= NULL
;
1793 struct gl_framebuffer
*fb
;
1795 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1797 fb
= get_framebuffer_target(ctx
, target
);
1799 _mesa_error(ctx
, GL_INVALID_ENUM
,
1800 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1804 /* check framebuffer binding */
1805 if (fb
->Name
== 0) {
1806 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1807 "glFramebufferTexture%sEXT", caller
);
1812 /* The textarget, level, and zoffset parameters are only validated if
1813 * texture is non-zero.
1816 GLboolean err
= GL_TRUE
;
1818 texObj
= _mesa_lookup_texture(ctx
, texture
);
1819 if (texObj
!= NULL
) {
1820 if (textarget
== 0) {
1821 /* XXX what's the purpose of this? */
1822 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1823 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1824 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1827 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1828 ? !IS_CUBE_FACE(textarget
)
1829 : (texObj
->Target
!= textarget
);
1833 /* can't render to a non-existant texture */
1834 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1835 "glFramebufferTexture%sEXT(non existant texture)",
1841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1842 "glFramebufferTexture%sEXT(texture target mismatch)",
1847 if (texObj
->Target
== GL_TEXTURE_3D
) {
1848 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1849 if (zoffset
< 0 || zoffset
>= maxSize
) {
1850 _mesa_error(ctx
, GL_INVALID_VALUE
,
1851 "glFramebufferTexture%sEXT(zoffset)", caller
);
1855 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1856 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1857 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1858 _mesa_error(ctx
, GL_INVALID_VALUE
,
1859 "glFramebufferTexture%sEXT(layer)", caller
);
1865 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1866 _mesa_error(ctx
, GL_INVALID_VALUE
,
1867 "glFramebufferTexture%sEXT(level)", caller
);
1872 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1874 _mesa_error(ctx
, GL_INVALID_ENUM
,
1875 "glFramebufferTexture%sEXT(attachment)", caller
);
1879 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1881 _glthread_LOCK_MUTEX(fb
->Mutex
);
1883 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1885 /* Set the render-to-texture flag. We'll check this flag in
1886 * glTexImage() and friends to determine if we need to revalidate
1887 * any FBOs that might be rendering into this texture.
1888 * This flag never gets cleared since it's non-trivial to determine
1889 * when all FBOs might be done rendering to this texture. That's OK
1890 * though since it's uncommon to render to a texture then repeatedly
1891 * call glTexImage() to change images in the texture.
1893 texObj
->_RenderToTexture
= GL_TRUE
;
1896 _mesa_remove_attachment(ctx
, att
);
1899 invalidate_framebuffer(fb
);
1901 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1907 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1908 GLenum textarget
, GLuint texture
, GLint level
)
1910 GET_CURRENT_CONTEXT(ctx
);
1912 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1913 _mesa_error(ctx
, GL_INVALID_ENUM
,
1914 "glFramebufferTexture1DEXT(textarget)");
1918 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1924 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1925 GLenum textarget
, GLuint texture
, GLint level
)
1927 GET_CURRENT_CONTEXT(ctx
);
1929 if ((texture
!= 0) &&
1930 (textarget
!= GL_TEXTURE_2D
) &&
1931 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1932 (!IS_CUBE_FACE(textarget
))) {
1933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1934 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1938 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1944 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1945 GLenum textarget
, GLuint texture
,
1946 GLint level
, GLint zoffset
)
1948 GET_CURRENT_CONTEXT(ctx
);
1950 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1951 _mesa_error(ctx
, GL_INVALID_ENUM
,
1952 "glFramebufferTexture3DEXT(textarget)");
1956 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1962 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1963 GLuint texture
, GLint level
, GLint layer
)
1965 GET_CURRENT_CONTEXT(ctx
);
1967 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1973 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1974 GLenum renderbufferTarget
,
1975 GLuint renderbuffer
)
1977 struct gl_renderbuffer_attachment
*att
;
1978 struct gl_framebuffer
*fb
;
1979 struct gl_renderbuffer
*rb
;
1980 GET_CURRENT_CONTEXT(ctx
);
1982 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1984 fb
= get_framebuffer_target(ctx
, target
);
1986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
1990 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1991 _mesa_error(ctx
, GL_INVALID_ENUM
,
1992 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1996 if (fb
->Name
== 0) {
1997 /* Can't attach new renderbuffers to a window system framebuffer */
1998 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2002 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2004 _mesa_error(ctx
, GL_INVALID_ENUM
,
2005 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2006 _mesa_lookup_enum_by_nr(attachment
));
2011 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2014 "glFramebufferRenderbufferEXT(non-existant"
2015 " renderbuffer %u)", renderbuffer
);
2018 else if (rb
== &DummyRenderbuffer
) {
2019 /* This is what NVIDIA does */
2020 _mesa_error(ctx
, GL_INVALID_VALUE
,
2021 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2027 /* remove renderbuffer attachment */
2031 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2032 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2033 /* make sure the renderbuffer is a depth/stencil format */
2034 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2035 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2036 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2037 "glFramebufferRenderbufferEXT(renderbuffer"
2038 " is not DEPTH_STENCIL format)");
2044 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2046 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2047 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2049 /* Some subsequent GL commands may depend on the framebuffer's visual
2050 * after the binding is updated. Update visual info now.
2052 _mesa_update_framebuffer_visual(ctx
, fb
);
2057 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2058 GLenum pname
, GLint
*params
)
2060 const struct gl_renderbuffer_attachment
*att
;
2061 struct gl_framebuffer
*buffer
;
2062 GET_CURRENT_CONTEXT(ctx
);
2064 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2066 buffer
= get_framebuffer_target(ctx
, target
);
2068 _mesa_error(ctx
, GL_INVALID_ENUM
,
2069 "glGetFramebufferAttachmentParameterivEXT(target)");
2073 if (buffer
->Name
== 0) {
2074 /* the default / window-system FBO */
2075 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2078 /* user-created framebuffer FBO */
2079 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2083 _mesa_error(ctx
, GL_INVALID_ENUM
,
2084 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2088 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2089 /* the depth and stencil attachments must point to the same buffer */
2090 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2091 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2092 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2093 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2094 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2095 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2096 " attachments differ)");
2101 /* No need to flush here */
2104 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2105 *params
= buffer
->Name
== 0 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2107 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2108 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2109 *params
= att
->Renderbuffer
->Name
;
2111 else if (att
->Type
== GL_TEXTURE
) {
2112 *params
= att
->Texture
->Name
;
2115 assert(att
->Type
== GL_NONE
);
2119 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2120 if (att
->Type
== GL_TEXTURE
) {
2121 *params
= att
->TextureLevel
;
2124 _mesa_error(ctx
, GL_INVALID_ENUM
,
2125 "glGetFramebufferAttachmentParameterivEXT(pname)");
2128 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2129 if (att
->Type
== GL_TEXTURE
) {
2130 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2131 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2138 _mesa_error(ctx
, GL_INVALID_ENUM
,
2139 "glGetFramebufferAttachmentParameterivEXT(pname)");
2142 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2143 if (att
->Type
== GL_TEXTURE
) {
2144 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2145 *params
= att
->Zoffset
;
2152 _mesa_error(ctx
, GL_INVALID_ENUM
,
2153 "glGetFramebufferAttachmentParameterivEXT(pname)");
2156 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2157 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2158 _mesa_error(ctx
, GL_INVALID_ENUM
,
2159 "glGetFramebufferAttachmentParameterivEXT(pname)");
2162 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&& ctx
->Const
.sRGBCapable
) {
2163 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2166 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2167 * if the sRGB conversion is unsupported. */
2168 *params
= GL_LINEAR
;
2172 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2173 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2174 _mesa_error(ctx
, GL_INVALID_ENUM
,
2175 "glGetFramebufferAttachmentParameterivEXT(pname)");
2179 gl_format format
= att
->Renderbuffer
->Format
;
2180 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2185 *params
= _mesa_get_format_datatype(format
);
2189 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2190 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2191 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2192 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2193 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2194 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2195 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2196 _mesa_error(ctx
, GL_INVALID_ENUM
,
2197 "glGetFramebufferAttachmentParameterivEXT(pname)");
2199 else if (att
->Texture
) {
2200 const struct gl_texture_image
*texImage
=
2201 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2204 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2205 texImage
->TexFormat
);
2211 else if (att
->Renderbuffer
) {
2212 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2213 att
->Renderbuffer
->Format
);
2220 _mesa_error(ctx
, GL_INVALID_ENUM
,
2221 "glGetFramebufferAttachmentParameterivEXT(pname)");
2228 _mesa_GenerateMipmapEXT(GLenum target
)
2230 struct gl_texture_object
*texObj
;
2231 GET_CURRENT_CONTEXT(ctx
);
2233 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2234 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2240 case GL_TEXTURE_CUBE_MAP
:
2241 /* OK, legal value */
2244 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2245 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2249 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2251 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2256 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2257 !_mesa_cube_complete(texObj
)) {
2258 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2259 "glGenerateMipmap(incomplete cube map)");
2263 _mesa_lock_texture(ctx
, texObj
);
2264 if (target
== GL_TEXTURE_CUBE_MAP
) {
2266 for (face
= 0; face
< 6; face
++)
2267 ctx
->Driver
.GenerateMipmap(ctx
,
2268 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2272 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2274 _mesa_unlock_texture(ctx
, texObj
);
2278 #if FEATURE_EXT_framebuffer_blit
2280 static const struct gl_renderbuffer_attachment
*
2281 find_attachment(const struct gl_framebuffer
*fb
,
2282 const struct gl_renderbuffer
*rb
)
2285 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2286 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2287 return &fb
->Attachment
[i
];
2295 * Blit rectangular region, optionally from one framebuffer to another.
2297 * Note, if the src buffer is multisampled and the dest is not, this is
2298 * when the samples must be resolved to a single color.
2301 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2302 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2303 GLbitfield mask
, GLenum filter
)
2305 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2306 GL_DEPTH_BUFFER_BIT
|
2307 GL_STENCIL_BUFFER_BIT
);
2308 const struct gl_framebuffer
*readFb
, *drawFb
;
2309 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2310 GET_CURRENT_CONTEXT(ctx
);
2312 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2313 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2315 if (MESA_VERBOSE
& VERBOSE_API
)
2317 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2318 srcX0
, srcY0
, srcX1
, srcY1
,
2319 dstX0
, dstY0
, dstX1
, dstY1
,
2320 mask
, _mesa_lookup_enum_by_nr(filter
));
2322 if (ctx
->NewState
) {
2323 _mesa_update_state(ctx
);
2326 readFb
= ctx
->ReadBuffer
;
2327 drawFb
= ctx
->DrawBuffer
;
2329 if (!readFb
|| !drawFb
) {
2330 /* This will normally never happen but someday we may want to
2331 * support MakeCurrent() with no drawables.
2336 /* check for complete framebuffers */
2337 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2338 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2339 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2340 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2344 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2345 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2349 if (mask
& ~legalMaskBits
) {
2350 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2354 /* depth/stencil must be blitted with nearest filtering */
2355 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2356 && filter
!= GL_NEAREST
) {
2357 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2358 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2362 /* get color read/draw renderbuffers */
2363 if (mask
& GL_COLOR_BUFFER_BIT
) {
2364 colorReadRb
= readFb
->_ColorReadBuffer
;
2365 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2368 colorReadRb
= colorDrawRb
= NULL
;
2371 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2372 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2373 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2376 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2377 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2379 "glBlitFramebufferEXT(stencil buffer size mismatch)");
2384 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2385 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2386 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2389 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2390 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2391 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2392 "glBlitFramebufferEXT(depth buffer size mismatch)");
2397 if (readFb
->Visual
.samples
> 0 &&
2398 drawFb
->Visual
.samples
> 0 &&
2399 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2400 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2401 "glBlitFramebufferEXT(mismatched samples");
2405 /* extra checks for multisample copies... */
2406 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2407 /* src and dest region sizes must be the same */
2408 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2409 srcY1
- srcY0
!= dstY1
- dstY0
) {
2410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2411 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
2415 /* color formats must match */
2418 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
2425 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2426 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2432 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2434 srcX0
, srcY0
, srcX1
, srcY1
,
2435 dstX0
, dstY0
, dstX1
, dstY1
,
2438 const struct gl_renderbuffer_attachment
*att
;
2440 att
= find_attachment(readFb
, colorReadRb
);
2441 printf(" Src FBO %u RB %u (%dx%d) ",
2442 readFb
->Name
, colorReadRb
->Name
,
2443 colorReadRb
->Width
, colorReadRb
->Height
);
2444 if (att
&& att
->Texture
) {
2445 printf("Tex %u tgt 0x%x level %u face %u",
2447 att
->Texture
->Target
,
2453 att
= find_attachment(drawFb
, colorDrawRb
);
2454 printf(" Dst FBO %u RB %u (%dx%d) ",
2455 drawFb
->Name
, colorDrawRb
->Name
,
2456 colorDrawRb
->Width
, colorDrawRb
->Height
);
2457 if (att
&& att
->Texture
) {
2458 printf("Tex %u tgt 0x%x level %u face %u",
2460 att
->Texture
->Target
,
2468 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2469 ctx
->Driver
.BlitFramebuffer(ctx
,
2470 srcX0
, srcY0
, srcX1
, srcY1
,
2471 dstX0
, dstY0
, dstX1
, dstY1
,
2474 #endif /* FEATURE_EXT_framebuffer_blit */
2476 #if FEATURE_ARB_geometry_shader4
2478 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2479 GLuint texture
, GLint level
)
2481 GET_CURRENT_CONTEXT(ctx
);
2482 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2483 "glFramebufferTextureARB "
2484 "not implemented!");
2488 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2489 GLuint texture
, GLint level
, GLenum face
)
2491 GET_CURRENT_CONTEXT(ctx
);
2492 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2493 "glFramebufferTextureFaceARB "
2494 "not implemented!");
2496 #endif /* FEATURE_ARB_geometry_shader4 */