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 (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
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
);
389 _mesa_remove_attachment(ctx
, att
);
392 invalidate_framebuffer(fb
);
394 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
399 * Fallback for ctx->Driver.ValidateFramebuffer()
400 * Check if the renderbuffer's formats are supported by the software
402 * Drivers should probably override this.
405 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
408 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
409 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
411 switch (rb
->_BaseFormat
) {
413 case GL_LUMINANCE_ALPHA
:
418 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
421 /* render buffer format is supported by software rendering */
433 att_incomplete(const char *msg
)
436 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
447 fbo_incomplete(const char *msg
, int index
)
450 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
459 * Is the given base format a legal format for a color renderbuffer?
462 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
464 switch (baseFormat
) {
469 case GL_LUMINANCE_ALPHA
:
472 return ctx
->Extensions
.ARB_framebuffer_object
;
475 return ctx
->Extensions
.ARB_texture_rg
;
483 * Is the given base format a legal format for a depth/stencil renderbuffer?
486 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
488 switch (baseFormat
) {
489 case GL_DEPTH_COMPONENT
:
490 case GL_DEPTH_STENCIL_EXT
:
499 * Test if an attachment point is complete and update its Complete field.
500 * \param format if GL_COLOR, this is a color attachment point,
501 * if GL_DEPTH, this is a depth component attachment point,
502 * if GL_STENCIL, this is a stencil component attachment point.
505 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
506 struct gl_renderbuffer_attachment
*att
)
508 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
510 /* assume complete */
511 att
->Complete
= GL_TRUE
;
513 /* Look for reasons why the attachment might be incomplete */
514 if (att
->Type
== GL_TEXTURE
) {
515 const struct gl_texture_object
*texObj
= att
->Texture
;
516 struct gl_texture_image
*texImage
;
520 att_incomplete("no texobj");
521 att
->Complete
= GL_FALSE
;
525 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
527 att_incomplete("no teximage");
528 att
->Complete
= GL_FALSE
;
531 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
532 att_incomplete("teximage width/height=0");
533 printf("texobj = %u\n", texObj
->Name
);
534 printf("level = %d\n", att
->TextureLevel
);
535 att
->Complete
= GL_FALSE
;
538 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
539 att_incomplete("bad z offset");
540 att
->Complete
= GL_FALSE
;
544 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
546 if (format
== GL_COLOR
) {
547 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
548 att_incomplete("bad format");
549 att
->Complete
= GL_FALSE
;
552 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
553 att_incomplete("compressed internalformat");
554 att
->Complete
= GL_FALSE
;
558 else if (format
== GL_DEPTH
) {
559 if (baseFormat
== GL_DEPTH_COMPONENT
) {
562 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
563 ctx
->Extensions
.ARB_depth_texture
&&
564 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
568 att
->Complete
= GL_FALSE
;
569 att_incomplete("bad depth format");
574 ASSERT(format
== GL_STENCIL
);
575 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
576 ctx
->Extensions
.ARB_depth_texture
&&
577 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
581 /* no such thing as stencil-only textures */
582 att_incomplete("illegal stencil texture");
583 att
->Complete
= GL_FALSE
;
588 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
589 const GLenum baseFormat
=
590 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
592 ASSERT(att
->Renderbuffer
);
593 if (!att
->Renderbuffer
->InternalFormat
||
594 att
->Renderbuffer
->Width
< 1 ||
595 att
->Renderbuffer
->Height
< 1) {
596 att_incomplete("0x0 renderbuffer");
597 att
->Complete
= GL_FALSE
;
600 if (format
== GL_COLOR
) {
601 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
602 att_incomplete("bad renderbuffer color format");
603 att
->Complete
= GL_FALSE
;
607 else if (format
== GL_DEPTH
) {
608 if (baseFormat
== GL_DEPTH_COMPONENT
) {
611 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
612 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
616 att_incomplete("bad renderbuffer depth format");
617 att
->Complete
= GL_FALSE
;
622 assert(format
== GL_STENCIL
);
623 if (baseFormat
== GL_STENCIL_INDEX
) {
626 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
627 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
631 att
->Complete
= GL_FALSE
;
632 att_incomplete("bad renderbuffer stencil format");
638 ASSERT(att
->Type
== GL_NONE
);
646 * Test if the given framebuffer object is complete and update its
647 * Status field with the results.
648 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
649 * driver to make hardware-specific validation/completeness checks.
650 * Also update the framebuffer's Width and Height fields if the
651 * framebuffer is complete.
654 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
655 struct gl_framebuffer
*fb
)
658 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
659 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
660 GLint numSamples
= -1;
664 assert(fb
->Name
!= 0);
670 /* Start at -2 to more easily loop over all attachment points.
675 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
676 struct gl_renderbuffer_attachment
*att
;
681 * XXX for ARB_fbo, only check color buffers that are named by
682 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
685 /* check for attachment completeness
688 att
= &fb
->Attachment
[BUFFER_DEPTH
];
689 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
690 if (!att
->Complete
) {
691 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
692 fbo_incomplete("depth attachment incomplete", -1);
697 att
= &fb
->Attachment
[BUFFER_STENCIL
];
698 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
699 if (!att
->Complete
) {
700 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
701 fbo_incomplete("stencil attachment incomplete", -1);
706 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
707 test_attachment_completeness(ctx
, GL_COLOR
, att
);
708 if (!att
->Complete
) {
709 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
710 fbo_incomplete("color attachment incomplete", i
);
715 /* get width, height, format of the renderbuffer/texture
717 if (att
->Type
== GL_TEXTURE
) {
718 const struct gl_texture_image
*texImg
719 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
720 minWidth
= MIN2(minWidth
, texImg
->Width
);
721 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
722 minHeight
= MIN2(minHeight
, texImg
->Height
);
723 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
724 f
= texImg
->_BaseFormat
;
725 attFormat
= texImg
->TexFormat
;
727 if (!_mesa_is_legal_color_format(ctx
, f
) &&
728 !is_legal_depth_format(ctx
, f
)) {
729 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
730 fbo_incomplete("texture attachment incomplete", -1);
734 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
735 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
736 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
737 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
738 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
739 f
= att
->Renderbuffer
->InternalFormat
;
740 attFormat
= att
->Renderbuffer
->Format
;
744 assert(att
->Type
== GL_NONE
);
748 if (numSamples
< 0) {
750 numSamples
= att
->Renderbuffer
->NumSamples
;
753 /* check if integer color */
754 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
756 /* Error-check width, height, format, samples
758 if (numImages
== 1) {
759 /* save format, num samples */
765 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
766 /* check that width, height, format are same */
767 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
768 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
769 fbo_incomplete("width or height mismatch", -1);
772 /* check that all color buffer have same format */
773 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
774 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
775 fbo_incomplete("format mismatch", -1);
779 if (att
->Renderbuffer
&&
780 att
->Renderbuffer
->NumSamples
!= numSamples
) {
781 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
782 fbo_incomplete("inconsistant number of samples", i
);
790 if (ctx
->API
== API_OPENGL
) {
791 /* Check that all DrawBuffers are present */
792 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
793 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
794 const struct gl_renderbuffer_attachment
*att
795 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
797 if (att
->Type
== GL_NONE
) {
798 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
799 fbo_incomplete("missing drawbuffer", j
);
805 /* Check that the ReadBuffer is present */
806 if (fb
->ColorReadBuffer
!= GL_NONE
) {
807 const struct gl_renderbuffer_attachment
*att
808 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
810 if (att
->Type
== GL_NONE
) {
811 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
812 fbo_incomplete("missing readbuffer", -1);
821 if (numImages
== 0) {
822 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
823 fbo_incomplete("no attachments", -1);
827 /* Provisionally set status = COMPLETE ... */
828 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
830 /* ... but the driver may say the FB is incomplete.
831 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
834 if (ctx
->Driver
.ValidateFramebuffer
) {
835 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
836 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
837 fbo_incomplete("driver marked FBO as incomplete", -1);
841 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
843 * Note that if ARB_framebuffer_object is supported and the attached
844 * renderbuffers/textures are different sizes, the framebuffer
845 * width/height will be set to the smallest width/height.
847 fb
->Width
= minWidth
;
848 fb
->Height
= minHeight
;
850 /* finally, update the visual info for the framebuffer */
851 _mesa_update_framebuffer_visual(ctx
, fb
);
857 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
859 GET_CURRENT_CONTEXT(ctx
);
860 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
862 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
863 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
871 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
873 struct gl_renderbuffer
*newRb
;
874 GET_CURRENT_CONTEXT(ctx
);
876 ASSERT_OUTSIDE_BEGIN_END(ctx
);
878 if (target
!= GL_RENDERBUFFER_EXT
) {
879 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
883 /* No need to flush here since the render buffer binding has no
884 * effect on rendering state.
888 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
889 if (newRb
== &DummyRenderbuffer
) {
890 /* ID was reserved, but no real renderbuffer object made yet */
893 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
894 /* All RB IDs must be Gen'd */
895 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
900 /* create new renderbuffer object */
901 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
903 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
906 ASSERT(newRb
->AllocStorage
);
907 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
908 newRb
->RefCount
= 1; /* referenced by hash table */
915 ASSERT(newRb
!= &DummyRenderbuffer
);
917 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
922 * If the given renderbuffer is anywhere attached to the framebuffer, detach
924 * This is used when a renderbuffer object is deleted.
925 * The spec calls for unbinding.
928 detach_renderbuffer(struct gl_context
*ctx
,
929 struct gl_framebuffer
*fb
,
930 struct gl_renderbuffer
*rb
)
933 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
934 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
935 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
938 invalidate_framebuffer(fb
);
943 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
946 GET_CURRENT_CONTEXT(ctx
);
948 ASSERT_OUTSIDE_BEGIN_END(ctx
);
949 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
951 for (i
= 0; i
< n
; i
++) {
952 if (renderbuffers
[i
] > 0) {
953 struct gl_renderbuffer
*rb
;
954 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
956 /* check if deleting currently bound renderbuffer object */
957 if (rb
== ctx
->CurrentRenderbuffer
) {
959 ASSERT(rb
->RefCount
>= 2);
960 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
963 if (ctx
->DrawBuffer
->Name
) {
964 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
966 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
967 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
970 /* Remove from hash table immediately, to free the ID.
971 * But the object will not be freed until it's no longer
972 * referenced anywhere else.
974 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
976 if (rb
!= &DummyRenderbuffer
) {
977 /* no longer referenced by hash table */
978 _mesa_reference_renderbuffer(&rb
, NULL
);
987 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
989 GET_CURRENT_CONTEXT(ctx
);
993 ASSERT_OUTSIDE_BEGIN_END(ctx
);
996 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1003 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1005 for (i
= 0; i
< n
; i
++) {
1006 GLuint name
= first
+ i
;
1007 renderbuffers
[i
] = name
;
1008 /* insert dummy placeholder into hash table */
1009 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1010 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1011 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1017 * Given an internal format token for a render buffer, return the
1018 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1019 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1020 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1022 * This is similar to _mesa_base_tex_format() but the set of valid
1023 * internal formats is different.
1025 * Note that even if a format is determined to be legal here, validation
1026 * of the FBO may fail if the format is not supported by the driver/GPU.
1028 * \param internalFormat as passed to glRenderbufferStorage()
1029 * \return the base internal format, or 0 if internalFormat is illegal
1032 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1035 * Notes: some formats such as alpha, luminance, etc. were added
1036 * with GL_ARB_framebuffer_object.
1038 switch (internalFormat
) {
1044 return ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1048 case GL_LUMINANCE12
:
1049 case GL_LUMINANCE16
:
1050 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1051 case GL_LUMINANCE_ALPHA
:
1052 case GL_LUMINANCE4_ALPHA4
:
1053 case GL_LUMINANCE6_ALPHA2
:
1054 case GL_LUMINANCE8_ALPHA8
:
1055 case GL_LUMINANCE12_ALPHA4
:
1056 case GL_LUMINANCE12_ALPHA12
:
1057 case GL_LUMINANCE16_ALPHA16
:
1058 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1062 case GL_INTENSITY12
:
1063 case GL_INTENSITY16
:
1064 return ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1083 case GL_RGBA16_SNORM
:
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 /* XXX add floating point and integer formats eventually */
1118 /** sentinal value, see below */
1119 #define NO_SAMPLES 1000
1123 * Helper function used by _mesa_RenderbufferStorageEXT() and
1124 * _mesa_RenderbufferStorageMultisample().
1125 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1128 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1129 GLsizei width
, GLsizei height
, GLsizei samples
)
1131 const char *func
= samples
== NO_SAMPLES
?
1132 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1133 struct gl_renderbuffer
*rb
;
1135 GET_CURRENT_CONTEXT(ctx
);
1137 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1139 if (target
!= GL_RENDERBUFFER_EXT
) {
1140 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1144 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1145 if (baseFormat
== 0) {
1146 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1150 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1151 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1155 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1156 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1160 if (samples
== NO_SAMPLES
) {
1161 /* NumSamples == 0 indicates non-multisampling */
1164 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1165 /* note: driver may choose to use more samples than what's requested */
1166 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1170 rb
= ctx
->CurrentRenderbuffer
;
1172 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1176 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1178 if (rb
->InternalFormat
== internalFormat
&&
1179 rb
->Width
== (GLuint
) width
&&
1180 rb
->Height
== (GLuint
) height
) {
1181 /* no change in allocation needed */
1185 /* These MUST get set by the AllocStorage func */
1186 rb
->Format
= MESA_FORMAT_NONE
;
1187 rb
->NumSamples
= samples
;
1189 /* Now allocate the storage */
1190 ASSERT(rb
->AllocStorage
);
1191 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1192 /* No error - check/set fields now */
1193 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1194 assert(rb
->Width
== (GLuint
) width
);
1195 assert(rb
->Height
== (GLuint
) height
);
1196 rb
->InternalFormat
= internalFormat
;
1197 rb
->_BaseFormat
= baseFormat
;
1198 assert(rb
->_BaseFormat
!= 0);
1201 /* Probably ran out of memory - clear the fields */
1204 rb
->Format
= MESA_FORMAT_NONE
;
1205 rb
->InternalFormat
= GL_NONE
;
1206 rb
->_BaseFormat
= GL_NONE
;
1211 test_framebuffer_completeness(ctx, fb);
1213 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1219 #if FEATURE_OES_EGL_image
1221 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1223 struct gl_renderbuffer
*rb
;
1224 GET_CURRENT_CONTEXT(ctx
);
1225 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1227 if (!ctx
->Extensions
.OES_EGL_image
) {
1228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1229 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1233 if (target
!= GL_RENDERBUFFER
) {
1234 _mesa_error(ctx
, GL_INVALID_ENUM
,
1235 "EGLImageTargetRenderbufferStorageOES");
1239 rb
= ctx
->CurrentRenderbuffer
;
1241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1242 "EGLImageTargetRenderbufferStorageOES");
1246 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1248 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1254 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1255 * _mesa_GetFramebufferAttachmentParameterivEXT()
1256 * We have to be careful to respect the base format. For example, if a
1257 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1258 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1259 * we need to return zero.
1262 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1265 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1266 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1267 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1268 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1269 return _mesa_get_format_bits(format
, pname
);
1272 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1273 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1274 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1275 return _mesa_get_format_bits(format
, pname
);
1278 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1279 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1280 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1281 return _mesa_get_format_bits(format
, pname
);
1284 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1285 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1286 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1287 baseFormat
== GL_LUMINANCE_ALPHA
)
1288 return _mesa_get_format_bits(format
, pname
);
1291 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1292 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1293 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1294 return _mesa_get_format_bits(format
, pname
);
1297 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1298 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1299 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1300 return _mesa_get_format_bits(format
, pname
);
1311 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1312 GLsizei width
, GLsizei height
)
1314 /* GL_ARB_fbo says calling this function is equivalent to calling
1315 * glRenderbufferStorageMultisample() with samples=0. We pass in
1316 * a token value here just for error reporting purposes.
1318 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1323 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1324 GLenum internalFormat
,
1325 GLsizei width
, GLsizei height
)
1327 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1332 * OpenGL ES version of glRenderBufferStorage.
1335 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1336 GLsizei width
, GLsizei height
)
1338 switch (internalFormat
) {
1340 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1341 /* choose a closest format */
1342 internalFormat
= GL_RGB5
;
1348 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1353 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1355 struct gl_renderbuffer
*rb
;
1356 GET_CURRENT_CONTEXT(ctx
);
1358 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1360 if (target
!= GL_RENDERBUFFER_EXT
) {
1361 _mesa_error(ctx
, GL_INVALID_ENUM
,
1362 "glGetRenderbufferParameterivEXT(target)");
1366 rb
= ctx
->CurrentRenderbuffer
;
1368 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1369 "glGetRenderbufferParameterivEXT");
1373 /* No need to flush here since we're just quering state which is
1374 * not effected by rendering.
1378 case GL_RENDERBUFFER_WIDTH_EXT
:
1379 *params
= rb
->Width
;
1381 case GL_RENDERBUFFER_HEIGHT_EXT
:
1382 *params
= rb
->Height
;
1384 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1385 *params
= rb
->InternalFormat
;
1387 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1388 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1389 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1390 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1391 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1392 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1393 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1395 case GL_RENDERBUFFER_SAMPLES
:
1396 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1397 *params
= rb
->NumSamples
;
1402 _mesa_error(ctx
, GL_INVALID_ENUM
,
1403 "glGetRenderbufferParameterivEXT(target)");
1409 GLboolean GLAPIENTRY
1410 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1412 GET_CURRENT_CONTEXT(ctx
);
1413 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1415 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1416 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1424 * Check if any of the attachments of the given framebuffer are textures
1425 * (render to texture). Call ctx->Driver.RenderTexture() for such
1429 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1432 ASSERT(ctx
->Driver
.RenderTexture
);
1435 return; /* can't render to texture with winsys framebuffers */
1437 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1438 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1439 struct gl_texture_object
*texObj
= att
->Texture
;
1441 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1442 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1449 * Examine all the framebuffer's attachments to see if any are textures.
1450 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1451 * notify the device driver that the texture image may have changed.
1454 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1457 return; /* can't render to texture with winsys framebuffers */
1459 if (ctx
->Driver
.FinishRenderTexture
) {
1461 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1462 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1463 if (att
->Texture
&& att
->Renderbuffer
) {
1464 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1472 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1474 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1475 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1476 GLboolean bindReadBuf
, bindDrawBuf
;
1477 GET_CURRENT_CONTEXT(ctx
);
1480 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1481 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1482 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1486 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1488 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1489 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1490 "glBindFramebufferEXT(unsupported)");
1495 #if FEATURE_EXT_framebuffer_blit
1496 case GL_DRAW_FRAMEBUFFER_EXT
:
1497 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1498 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1501 bindDrawBuf
= GL_TRUE
;
1502 bindReadBuf
= GL_FALSE
;
1504 case GL_READ_FRAMEBUFFER_EXT
:
1505 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1506 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1509 bindDrawBuf
= GL_FALSE
;
1510 bindReadBuf
= GL_TRUE
;
1513 case GL_FRAMEBUFFER_EXT
:
1514 bindDrawBuf
= GL_TRUE
;
1515 bindReadBuf
= GL_TRUE
;
1518 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1523 /* Binding a user-created framebuffer object */
1524 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1525 if (newDrawFb
== &DummyFramebuffer
) {
1526 /* ID was reserved, but no real framebuffer object made yet */
1529 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1530 /* All FBO IDs must be Gen'd */
1531 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1536 /* create new framebuffer object */
1537 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1539 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1542 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1544 newReadFb
= newDrawFb
;
1547 /* Binding the window system framebuffer (which was originally set
1548 * with MakeCurrent).
1550 newDrawFb
= ctx
->WinSysDrawBuffer
;
1551 newReadFb
= ctx
->WinSysReadBuffer
;
1555 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1557 /* save pointers to current/old framebuffers */
1558 oldDrawFb
= ctx
->DrawBuffer
;
1559 oldReadFb
= ctx
->ReadBuffer
;
1561 /* check if really changing bindings */
1562 if (oldDrawFb
== newDrawFb
)
1563 bindDrawBuf
= GL_FALSE
;
1564 if (oldReadFb
== newReadFb
)
1565 bindReadBuf
= GL_FALSE
;
1568 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1570 * We also check if we're beginning and/or ending render-to-texture.
1571 * When a framebuffer with texture attachments is unbound, call
1572 * ctx->Driver.FinishRenderTexture().
1573 * When a framebuffer with texture attachments is bound, call
1574 * ctx->Driver.RenderTexture().
1576 * Note that if the ReadBuffer has texture attachments we don't consider
1577 * that a render-to-texture case.
1580 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1582 /* check if old readbuffer was render-to-texture */
1583 check_end_texture_render(ctx
, oldReadFb
);
1585 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1589 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1591 /* check if old read/draw buffers were render-to-texture */
1593 check_end_texture_render(ctx
, oldReadFb
);
1595 if (oldDrawFb
!= oldReadFb
)
1596 check_end_texture_render(ctx
, oldDrawFb
);
1598 /* check if newly bound framebuffer has any texture attachments */
1599 check_begin_texture_render(ctx
, newDrawFb
);
1601 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1604 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1605 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1611 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1614 GET_CURRENT_CONTEXT(ctx
);
1616 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1617 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1619 for (i
= 0; i
< n
; i
++) {
1620 if (framebuffers
[i
] > 0) {
1621 struct gl_framebuffer
*fb
;
1622 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1624 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1626 /* check if deleting currently bound framebuffer object */
1627 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1628 /* separate draw/read binding points */
1629 if (fb
== ctx
->DrawBuffer
) {
1631 ASSERT(fb
->RefCount
>= 2);
1632 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1634 if (fb
== ctx
->ReadBuffer
) {
1636 ASSERT(fb
->RefCount
>= 2);
1637 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1641 /* only one binding point for read/draw buffers */
1642 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1644 ASSERT(fb
->RefCount
>= 2);
1645 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1649 /* remove from hash table immediately, to free the ID */
1650 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1652 if (fb
!= &DummyFramebuffer
) {
1653 /* But the object will not be freed until it's no longer
1654 * bound in any context.
1656 _mesa_reference_framebuffer(&fb
, NULL
);
1665 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1667 GET_CURRENT_CONTEXT(ctx
);
1671 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1674 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1681 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1683 for (i
= 0; i
< n
; i
++) {
1684 GLuint name
= first
+ i
;
1685 framebuffers
[i
] = name
;
1686 /* insert dummy placeholder into hash table */
1687 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1688 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1689 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1696 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1698 struct gl_framebuffer
*buffer
;
1699 GET_CURRENT_CONTEXT(ctx
);
1701 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1703 buffer
= get_framebuffer_target(ctx
, target
);
1705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1709 if (buffer
->Name
== 0) {
1710 /* The window system / default framebuffer is always complete */
1711 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1714 /* No need to flush here */
1716 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1717 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1720 return buffer
->_Status
;
1726 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1729 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1730 GLenum attachment
, GLenum textarget
, GLuint texture
,
1731 GLint level
, GLint zoffset
)
1733 struct gl_renderbuffer_attachment
*att
;
1734 struct gl_texture_object
*texObj
= NULL
;
1735 struct gl_framebuffer
*fb
;
1737 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1739 fb
= get_framebuffer_target(ctx
, target
);
1741 _mesa_error(ctx
, GL_INVALID_ENUM
,
1742 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1746 /* check framebuffer binding */
1747 if (fb
->Name
== 0) {
1748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1749 "glFramebufferTexture%sEXT", caller
);
1754 /* The textarget, level, and zoffset parameters are only validated if
1755 * texture is non-zero.
1758 GLboolean err
= GL_TRUE
;
1760 texObj
= _mesa_lookup_texture(ctx
, texture
);
1761 if (texObj
!= NULL
) {
1762 if (textarget
== 0) {
1763 /* XXX what's the purpose of this? */
1764 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1765 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1766 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1769 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1770 ? !IS_CUBE_FACE(textarget
)
1771 : (texObj
->Target
!= textarget
);
1775 /* can't render to a non-existant texture */
1776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1777 "glFramebufferTexture%sEXT(non existant texture)",
1783 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1784 "glFramebufferTexture%sEXT(texture target mismatch)",
1789 if (texObj
->Target
== GL_TEXTURE_3D
) {
1790 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1791 if (zoffset
< 0 || zoffset
>= maxSize
) {
1792 _mesa_error(ctx
, GL_INVALID_VALUE
,
1793 "glFramebufferTexture%sEXT(zoffset)", caller
);
1797 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1798 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1799 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1800 _mesa_error(ctx
, GL_INVALID_VALUE
,
1801 "glFramebufferTexture%sEXT(layer)", caller
);
1807 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
,
1809 "glFramebufferTexture%sEXT(level)", caller
);
1814 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1816 _mesa_error(ctx
, GL_INVALID_ENUM
,
1817 "glFramebufferTexture%sEXT(attachment)", caller
);
1821 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1823 _glthread_LOCK_MUTEX(fb
->Mutex
);
1825 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1827 /* Set the render-to-texture flag. We'll check this flag in
1828 * glTexImage() and friends to determine if we need to revalidate
1829 * any FBOs that might be rendering into this texture.
1830 * This flag never gets cleared since it's non-trivial to determine
1831 * when all FBOs might be done rendering to this texture. That's OK
1832 * though since it's uncommon to render to a texture then repeatedly
1833 * call glTexImage() to change images in the texture.
1835 texObj
->_RenderToTexture
= GL_TRUE
;
1838 _mesa_remove_attachment(ctx
, att
);
1841 invalidate_framebuffer(fb
);
1843 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1849 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1850 GLenum textarget
, GLuint texture
, GLint level
)
1852 GET_CURRENT_CONTEXT(ctx
);
1854 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1855 _mesa_error(ctx
, GL_INVALID_ENUM
,
1856 "glFramebufferTexture1DEXT(textarget)");
1860 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1866 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1867 GLenum textarget
, GLuint texture
, GLint level
)
1869 GET_CURRENT_CONTEXT(ctx
);
1871 if ((texture
!= 0) &&
1872 (textarget
!= GL_TEXTURE_2D
) &&
1873 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1874 (!IS_CUBE_FACE(textarget
))) {
1875 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1876 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1880 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1886 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1887 GLenum textarget
, GLuint texture
,
1888 GLint level
, GLint zoffset
)
1890 GET_CURRENT_CONTEXT(ctx
);
1892 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1893 _mesa_error(ctx
, GL_INVALID_ENUM
,
1894 "glFramebufferTexture3DEXT(textarget)");
1898 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1904 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1905 GLuint texture
, GLint level
, GLint layer
)
1907 GET_CURRENT_CONTEXT(ctx
);
1909 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1915 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1916 GLenum renderbufferTarget
,
1917 GLuint renderbuffer
)
1919 struct gl_renderbuffer_attachment
*att
;
1920 struct gl_framebuffer
*fb
;
1921 struct gl_renderbuffer
*rb
;
1922 GET_CURRENT_CONTEXT(ctx
);
1924 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1926 fb
= get_framebuffer_target(ctx
, target
);
1928 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
1932 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1933 _mesa_error(ctx
, GL_INVALID_ENUM
,
1934 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1938 if (fb
->Name
== 0) {
1939 /* Can't attach new renderbuffers to a window system framebuffer */
1940 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1944 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1946 _mesa_error(ctx
, GL_INVALID_ENUM
,
1947 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1948 _mesa_lookup_enum_by_nr(attachment
));
1953 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1955 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1956 "glFramebufferRenderbufferEXT(non-existant"
1957 " renderbuffer %u)", renderbuffer
);
1960 else if (rb
== &DummyRenderbuffer
) {
1961 /* This is what NVIDIA does */
1962 _mesa_error(ctx
, GL_INVALID_VALUE
,
1963 "glFramebufferRenderbufferEXT(renderbuffer %u)",
1969 /* remove renderbuffer attachment */
1973 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1974 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1975 /* make sure the renderbuffer is a depth/stencil format */
1976 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1977 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1979 "glFramebufferRenderbufferEXT(renderbuffer"
1980 " is not DEPTH_STENCIL format)");
1986 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1988 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1989 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1991 /* Some subsequent GL commands may depend on the framebuffer's visual
1992 * after the binding is updated. Update visual info now.
1994 _mesa_update_framebuffer_visual(ctx
, fb
);
1999 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2000 GLenum pname
, GLint
*params
)
2002 const struct gl_renderbuffer_attachment
*att
;
2003 struct gl_framebuffer
*buffer
;
2004 GET_CURRENT_CONTEXT(ctx
);
2006 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2008 buffer
= get_framebuffer_target(ctx
, target
);
2010 _mesa_error(ctx
, GL_INVALID_ENUM
,
2011 "glGetFramebufferAttachmentParameterivEXT(target)");
2015 if (buffer
->Name
== 0) {
2016 /* the default / window-system FBO */
2017 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2020 /* user-created framebuffer FBO */
2021 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2025 _mesa_error(ctx
, GL_INVALID_ENUM
,
2026 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2030 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2031 /* the depth and stencil attachments must point to the same buffer */
2032 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2033 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2034 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2035 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2036 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2037 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2038 " attachments differ)");
2043 /* No need to flush here */
2046 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2047 *params
= buffer
->Name
== 0 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2049 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2050 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2051 *params
= att
->Renderbuffer
->Name
;
2053 else if (att
->Type
== GL_TEXTURE
) {
2054 *params
= att
->Texture
->Name
;
2057 assert(att
->Type
== GL_NONE
);
2061 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2062 if (att
->Type
== GL_TEXTURE
) {
2063 *params
= att
->TextureLevel
;
2066 _mesa_error(ctx
, GL_INVALID_ENUM
,
2067 "glGetFramebufferAttachmentParameterivEXT(pname)");
2070 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2071 if (att
->Type
== GL_TEXTURE
) {
2072 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2073 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2080 _mesa_error(ctx
, GL_INVALID_ENUM
,
2081 "glGetFramebufferAttachmentParameterivEXT(pname)");
2084 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2085 if (att
->Type
== GL_TEXTURE
) {
2086 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2087 *params
= att
->Zoffset
;
2094 _mesa_error(ctx
, GL_INVALID_ENUM
,
2095 "glGetFramebufferAttachmentParameterivEXT(pname)");
2098 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2099 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2100 _mesa_error(ctx
, GL_INVALID_ENUM
,
2101 "glGetFramebufferAttachmentParameterivEXT(pname)");
2104 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&& ctx
->Const
.sRGBCapable
) {
2105 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2108 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2109 * if the sRGB conversion is unsupported. */
2110 *params
= GL_LINEAR
;
2114 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2115 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2116 _mesa_error(ctx
, GL_INVALID_ENUM
,
2117 "glGetFramebufferAttachmentParameterivEXT(pname)");
2121 gl_format format
= att
->Renderbuffer
->Format
;
2122 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2127 *params
= _mesa_get_format_datatype(format
);
2131 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2132 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2133 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2134 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2135 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2136 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2137 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2138 _mesa_error(ctx
, GL_INVALID_ENUM
,
2139 "glGetFramebufferAttachmentParameterivEXT(pname)");
2141 else if (att
->Texture
) {
2142 const struct gl_texture_image
*texImage
=
2143 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2146 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2147 texImage
->TexFormat
);
2153 else if (att
->Renderbuffer
) {
2154 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2155 att
->Renderbuffer
->Format
);
2162 _mesa_error(ctx
, GL_INVALID_ENUM
,
2163 "glGetFramebufferAttachmentParameterivEXT(pname)");
2170 _mesa_GenerateMipmapEXT(GLenum target
)
2172 struct gl_texture_object
*texObj
;
2173 GET_CURRENT_CONTEXT(ctx
);
2175 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2176 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2182 case GL_TEXTURE_CUBE_MAP
:
2183 /* OK, legal value */
2186 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2187 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2191 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2193 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2198 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2199 !_mesa_cube_complete(texObj
)) {
2200 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2201 "glGenerateMipmap(incomplete cube map)");
2205 _mesa_lock_texture(ctx
, texObj
);
2206 if (target
== GL_TEXTURE_CUBE_MAP
) {
2208 for (face
= 0; face
< 6; face
++)
2209 ctx
->Driver
.GenerateMipmap(ctx
,
2210 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2214 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2216 _mesa_unlock_texture(ctx
, texObj
);
2220 #if FEATURE_EXT_framebuffer_blit
2222 static const struct gl_renderbuffer_attachment
*
2223 find_attachment(const struct gl_framebuffer
*fb
,
2224 const struct gl_renderbuffer
*rb
)
2227 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2228 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2229 return &fb
->Attachment
[i
];
2237 * Blit rectangular region, optionally from one framebuffer to another.
2239 * Note, if the src buffer is multisampled and the dest is not, this is
2240 * when the samples must be resolved to a single color.
2243 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2244 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2245 GLbitfield mask
, GLenum filter
)
2247 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2248 GL_DEPTH_BUFFER_BIT
|
2249 GL_STENCIL_BUFFER_BIT
);
2250 const struct gl_framebuffer
*readFb
, *drawFb
;
2251 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2252 GET_CURRENT_CONTEXT(ctx
);
2254 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2255 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2257 if (MESA_VERBOSE
& VERBOSE_API
)
2259 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2260 srcX0
, srcY0
, srcX1
, srcY1
,
2261 dstX0
, dstY0
, dstX1
, dstY1
,
2262 mask
, _mesa_lookup_enum_by_nr(filter
));
2264 if (ctx
->NewState
) {
2265 _mesa_update_state(ctx
);
2268 readFb
= ctx
->ReadBuffer
;
2269 drawFb
= ctx
->DrawBuffer
;
2271 if (!readFb
|| !drawFb
) {
2272 /* This will normally never happen but someday we may want to
2273 * support MakeCurrent() with no drawables.
2278 /* check for complete framebuffers */
2279 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2280 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2281 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2282 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2286 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2287 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2291 if (mask
& ~legalMaskBits
) {
2292 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2296 /* depth/stencil must be blitted with nearest filtering */
2297 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2298 && filter
!= GL_NEAREST
) {
2299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2300 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2304 /* get color read/draw renderbuffers */
2305 if (mask
& GL_COLOR_BUFFER_BIT
) {
2306 colorReadRb
= readFb
->_ColorReadBuffer
;
2307 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2310 colorReadRb
= colorDrawRb
= NULL
;
2313 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2314 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2315 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2318 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2319 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2320 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2321 "glBlitFramebufferEXT(stencil buffer size mismatch");
2326 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2327 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2328 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2331 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2332 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2333 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2334 "glBlitFramebufferEXT(depth buffer size mismatch");
2339 if (readFb
->Visual
.samples
> 0 &&
2340 drawFb
->Visual
.samples
> 0 &&
2341 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2343 "glBlitFramebufferEXT(mismatched samples");
2347 /* extra checks for multisample copies... */
2348 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2349 /* src and dest region sizes must be the same */
2350 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2351 srcY1
- srcY0
!= dstY1
- dstY0
) {
2352 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2353 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2357 /* color formats must match */
2360 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2362 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2367 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2368 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2374 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2376 srcX0
, srcY0
, srcX1
, srcY1
,
2377 dstX0
, dstY0
, dstX1
, dstY1
,
2380 const struct gl_renderbuffer_attachment
*att
;
2382 att
= find_attachment(readFb
, colorReadRb
);
2383 printf(" Src FBO %u RB %u (%dx%d) ",
2384 readFb
->Name
, colorReadRb
->Name
,
2385 colorReadRb
->Width
, colorReadRb
->Height
);
2386 if (att
&& att
->Texture
) {
2387 printf("Tex %u tgt 0x%x level %u face %u",
2389 att
->Texture
->Target
,
2395 att
= find_attachment(drawFb
, colorDrawRb
);
2396 printf(" Dst FBO %u RB %u (%dx%d) ",
2397 drawFb
->Name
, colorDrawRb
->Name
,
2398 colorDrawRb
->Width
, colorDrawRb
->Height
);
2399 if (att
&& att
->Texture
) {
2400 printf("Tex %u tgt 0x%x level %u face %u",
2402 att
->Texture
->Target
,
2410 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2411 ctx
->Driver
.BlitFramebuffer(ctx
,
2412 srcX0
, srcY0
, srcX1
, srcY1
,
2413 dstX0
, dstY0
, dstX1
, dstY1
,
2416 #endif /* FEATURE_EXT_framebuffer_blit */
2418 #if FEATURE_ARB_geometry_shader4
2420 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2421 GLuint texture
, GLint level
)
2423 GET_CURRENT_CONTEXT(ctx
);
2424 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2425 "glFramebufferTextureARB "
2426 "not implemented!");
2430 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2431 GLuint texture
, GLint level
, GLenum face
)
2433 GET_CURRENT_CONTEXT(ctx
);
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "glFramebufferTextureFaceARB "
2436 "not implemented!");
2438 #endif /* FEATURE_ARB_geometry_shader4 */