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
;
423 switch (rb
->Format
) {
424 /* XXX This list is likely incomplete. */
425 case MESA_FORMAT_RGB9_E5_FLOAT
:
426 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
429 /* render buffer format is supported by software rendering */
441 att_incomplete(const char *msg
)
444 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
455 fbo_incomplete(const char *msg
, int index
)
458 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
467 * Is the given base format a legal format for a color renderbuffer?
470 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
472 switch (baseFormat
) {
477 case GL_LUMINANCE_ALPHA
:
480 return ctx
->Extensions
.ARB_framebuffer_object
;
483 return ctx
->Extensions
.ARB_texture_rg
;
491 * Is the given base format a legal format for a depth/stencil renderbuffer?
494 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
496 switch (baseFormat
) {
497 case GL_DEPTH_COMPONENT
:
498 case GL_DEPTH_STENCIL_EXT
:
507 * Test if an attachment point is complete and update its Complete field.
508 * \param format if GL_COLOR, this is a color attachment point,
509 * if GL_DEPTH, this is a depth component attachment point,
510 * if GL_STENCIL, this is a stencil component attachment point.
513 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
514 struct gl_renderbuffer_attachment
*att
)
516 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
518 /* assume complete */
519 att
->Complete
= GL_TRUE
;
521 /* Look for reasons why the attachment might be incomplete */
522 if (att
->Type
== GL_TEXTURE
) {
523 const struct gl_texture_object
*texObj
= att
->Texture
;
524 struct gl_texture_image
*texImage
;
528 att_incomplete("no texobj");
529 att
->Complete
= GL_FALSE
;
533 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
535 att_incomplete("no teximage");
536 att
->Complete
= GL_FALSE
;
539 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
540 att_incomplete("teximage width/height=0");
541 printf("texobj = %u\n", texObj
->Name
);
542 printf("level = %d\n", att
->TextureLevel
);
543 att
->Complete
= GL_FALSE
;
546 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
547 att_incomplete("bad z offset");
548 att
->Complete
= GL_FALSE
;
552 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
554 if (format
== GL_COLOR
) {
555 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
556 att_incomplete("bad format");
557 att
->Complete
= GL_FALSE
;
560 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
561 att_incomplete("compressed internalformat");
562 att
->Complete
= GL_FALSE
;
566 else if (format
== GL_DEPTH
) {
567 if (baseFormat
== GL_DEPTH_COMPONENT
) {
570 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
571 ctx
->Extensions
.ARB_depth_texture
&&
572 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
576 att
->Complete
= GL_FALSE
;
577 att_incomplete("bad depth format");
582 ASSERT(format
== GL_STENCIL
);
583 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
584 ctx
->Extensions
.ARB_depth_texture
&&
585 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
589 /* no such thing as stencil-only textures */
590 att_incomplete("illegal stencil texture");
591 att
->Complete
= GL_FALSE
;
596 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
597 const GLenum baseFormat
=
598 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
600 ASSERT(att
->Renderbuffer
);
601 if (!att
->Renderbuffer
->InternalFormat
||
602 att
->Renderbuffer
->Width
< 1 ||
603 att
->Renderbuffer
->Height
< 1) {
604 att_incomplete("0x0 renderbuffer");
605 att
->Complete
= GL_FALSE
;
608 if (format
== GL_COLOR
) {
609 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
610 att_incomplete("bad renderbuffer color format");
611 att
->Complete
= GL_FALSE
;
615 else if (format
== GL_DEPTH
) {
616 if (baseFormat
== GL_DEPTH_COMPONENT
) {
619 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
620 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
624 att_incomplete("bad renderbuffer depth format");
625 att
->Complete
= GL_FALSE
;
630 assert(format
== GL_STENCIL
);
631 if (baseFormat
== GL_STENCIL_INDEX
) {
634 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
635 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
639 att
->Complete
= GL_FALSE
;
640 att_incomplete("bad renderbuffer stencil format");
646 ASSERT(att
->Type
== GL_NONE
);
654 * Test if the given framebuffer object is complete and update its
655 * Status field with the results.
656 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
657 * driver to make hardware-specific validation/completeness checks.
658 * Also update the framebuffer's Width and Height fields if the
659 * framebuffer is complete.
662 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
663 struct gl_framebuffer
*fb
)
666 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
667 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
668 GLint numSamples
= -1;
672 assert(fb
->Name
!= 0);
678 /* Start at -2 to more easily loop over all attachment points.
683 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
684 struct gl_renderbuffer_attachment
*att
;
689 * XXX for ARB_fbo, only check color buffers that are named by
690 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
693 /* check for attachment completeness
696 att
= &fb
->Attachment
[BUFFER_DEPTH
];
697 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
698 if (!att
->Complete
) {
699 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
700 fbo_incomplete("depth attachment incomplete", -1);
705 att
= &fb
->Attachment
[BUFFER_STENCIL
];
706 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
707 if (!att
->Complete
) {
708 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
709 fbo_incomplete("stencil attachment incomplete", -1);
714 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
715 test_attachment_completeness(ctx
, GL_COLOR
, att
);
716 if (!att
->Complete
) {
717 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
718 fbo_incomplete("color attachment incomplete", i
);
723 /* get width, height, format of the renderbuffer/texture
725 if (att
->Type
== GL_TEXTURE
) {
726 const struct gl_texture_image
*texImg
=
727 _mesa_get_attachment_teximage(att
);
728 minWidth
= MIN2(minWidth
, texImg
->Width
);
729 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
730 minHeight
= MIN2(minHeight
, texImg
->Height
);
731 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
732 f
= texImg
->_BaseFormat
;
733 attFormat
= texImg
->TexFormat
;
735 if (!_mesa_is_legal_color_format(ctx
, f
) &&
736 !is_legal_depth_format(ctx
, f
)) {
737 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
738 fbo_incomplete("texture attachment incomplete", -1);
742 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
743 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
744 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
745 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
746 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
747 f
= att
->Renderbuffer
->InternalFormat
;
748 attFormat
= att
->Renderbuffer
->Format
;
752 assert(att
->Type
== GL_NONE
);
756 if (att
->Renderbuffer
&& numSamples
< 0) {
758 numSamples
= att
->Renderbuffer
->NumSamples
;
761 /* check if integer color */
762 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
764 /* Error-check width, height, format, samples
766 if (numImages
== 1) {
767 /* save format, num samples */
773 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
774 /* check that width, height, format are same */
775 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
776 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
777 fbo_incomplete("width or height mismatch", -1);
780 /* check that all color buffer have same format */
781 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
782 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
783 fbo_incomplete("format mismatch", -1);
787 if (att
->Renderbuffer
&&
788 att
->Renderbuffer
->NumSamples
!= numSamples
) {
789 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
790 fbo_incomplete("inconsistant number of samples", i
);
798 if (ctx
->API
== API_OPENGL
) {
799 /* Check that all DrawBuffers are present */
800 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
801 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
802 const struct gl_renderbuffer_attachment
*att
803 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
805 if (att
->Type
== GL_NONE
) {
806 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
807 fbo_incomplete("missing drawbuffer", j
);
813 /* Check that the ReadBuffer is present */
814 if (fb
->ColorReadBuffer
!= GL_NONE
) {
815 const struct gl_renderbuffer_attachment
*att
816 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
818 if (att
->Type
== GL_NONE
) {
819 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
820 fbo_incomplete("missing readbuffer", -1);
829 if (numImages
== 0) {
830 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
831 fbo_incomplete("no attachments", -1);
835 /* Provisionally set status = COMPLETE ... */
836 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
838 /* ... but the driver may say the FB is incomplete.
839 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
842 if (ctx
->Driver
.ValidateFramebuffer
) {
843 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
844 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
845 fbo_incomplete("driver marked FBO as incomplete", -1);
849 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
851 * Note that if ARB_framebuffer_object is supported and the attached
852 * renderbuffers/textures are different sizes, the framebuffer
853 * width/height will be set to the smallest width/height.
855 fb
->Width
= minWidth
;
856 fb
->Height
= minHeight
;
858 /* finally, update the visual info for the framebuffer */
859 _mesa_update_framebuffer_visual(ctx
, fb
);
865 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
867 GET_CURRENT_CONTEXT(ctx
);
868 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
870 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
871 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
879 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
881 struct gl_renderbuffer
*newRb
;
882 GET_CURRENT_CONTEXT(ctx
);
884 ASSERT_OUTSIDE_BEGIN_END(ctx
);
886 if (target
!= GL_RENDERBUFFER_EXT
) {
887 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
891 /* No need to flush here since the render buffer binding has no
892 * effect on rendering state.
896 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
897 if (newRb
== &DummyRenderbuffer
) {
898 /* ID was reserved, but no real renderbuffer object made yet */
901 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
902 /* All RB IDs must be Gen'd */
903 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
908 /* create new renderbuffer object */
909 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
911 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
914 ASSERT(newRb
->AllocStorage
);
915 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
916 newRb
->RefCount
= 1; /* referenced by hash table */
923 ASSERT(newRb
!= &DummyRenderbuffer
);
925 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
930 * If the given renderbuffer is anywhere attached to the framebuffer, detach
932 * This is used when a renderbuffer object is deleted.
933 * The spec calls for unbinding.
936 detach_renderbuffer(struct gl_context
*ctx
,
937 struct gl_framebuffer
*fb
,
938 struct gl_renderbuffer
*rb
)
941 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
942 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
943 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
946 invalidate_framebuffer(fb
);
951 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
954 GET_CURRENT_CONTEXT(ctx
);
956 ASSERT_OUTSIDE_BEGIN_END(ctx
);
957 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
959 for (i
= 0; i
< n
; i
++) {
960 if (renderbuffers
[i
] > 0) {
961 struct gl_renderbuffer
*rb
;
962 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
964 /* check if deleting currently bound renderbuffer object */
965 if (rb
== ctx
->CurrentRenderbuffer
) {
967 ASSERT(rb
->RefCount
>= 2);
968 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
971 if (ctx
->DrawBuffer
->Name
) {
972 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
974 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
975 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
978 /* Remove from hash table immediately, to free the ID.
979 * But the object will not be freed until it's no longer
980 * referenced anywhere else.
982 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
984 if (rb
!= &DummyRenderbuffer
) {
985 /* no longer referenced by hash table */
986 _mesa_reference_renderbuffer(&rb
, NULL
);
995 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
997 GET_CURRENT_CONTEXT(ctx
);
1001 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1004 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1011 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1013 for (i
= 0; i
< n
; i
++) {
1014 GLuint name
= first
+ i
;
1015 renderbuffers
[i
] = name
;
1016 /* insert dummy placeholder into hash table */
1017 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1018 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1019 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1025 * Given an internal format token for a render buffer, return the
1026 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1027 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1028 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1030 * This is similar to _mesa_base_tex_format() but the set of valid
1031 * internal formats is different.
1033 * Note that even if a format is determined to be legal here, validation
1034 * of the FBO may fail if the format is not supported by the driver/GPU.
1036 * \param internalFormat as passed to glRenderbufferStorage()
1037 * \return the base internal format, or 0 if internalFormat is illegal
1040 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1043 * Notes: some formats such as alpha, luminance, etc. were added
1044 * with GL_ARB_framebuffer_object.
1046 switch (internalFormat
) {
1052 return ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1056 case GL_LUMINANCE12
:
1057 case GL_LUMINANCE16
:
1058 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1059 case GL_LUMINANCE_ALPHA
:
1060 case GL_LUMINANCE4_ALPHA4
:
1061 case GL_LUMINANCE6_ALPHA2
:
1062 case GL_LUMINANCE8_ALPHA8
:
1063 case GL_LUMINANCE12_ALPHA4
:
1064 case GL_LUMINANCE12_ALPHA12
:
1065 case GL_LUMINANCE16_ALPHA16
:
1066 return ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1070 case GL_INTENSITY12
:
1071 case GL_INTENSITY16
:
1072 return ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1091 case GL_SRGB8_ALPHA8_EXT
:
1093 case GL_STENCIL_INDEX
:
1094 case GL_STENCIL_INDEX1_EXT
:
1095 case GL_STENCIL_INDEX4_EXT
:
1096 case GL_STENCIL_INDEX8_EXT
:
1097 case GL_STENCIL_INDEX16_EXT
:
1098 return GL_STENCIL_INDEX
;
1099 case GL_DEPTH_COMPONENT
:
1100 case GL_DEPTH_COMPONENT16
:
1101 case GL_DEPTH_COMPONENT24
:
1102 case GL_DEPTH_COMPONENT32
:
1103 return GL_DEPTH_COMPONENT
;
1104 case GL_DEPTH_STENCIL_EXT
:
1105 case GL_DEPTH24_STENCIL8_EXT
:
1106 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
1107 return GL_DEPTH_STENCIL_EXT
;
1113 return ctx
->Extensions
.ARB_texture_rg
? GL_RED
: 0;
1117 return ctx
->Extensions
.ARB_texture_rg
? GL_RG
: 0;
1118 /* signed normalized texture formats */
1122 return ctx
->Extensions
.EXT_texture_snorm
? GL_RED
: 0;
1126 return ctx
->Extensions
.EXT_texture_snorm
? GL_RG
: 0;
1129 case GL_RGB16_SNORM
:
1130 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGB
: 0;
1132 case GL_RGBA8_SNORM
:
1133 case GL_RGBA16_SNORM
:
1134 return ctx
->Extensions
.EXT_texture_snorm
? GL_RGBA
: 0;
1135 case GL_ALPHA_SNORM
:
1136 case GL_ALPHA8_SNORM
:
1137 case GL_ALPHA16_SNORM
:
1138 return ctx
->Extensions
.EXT_texture_snorm
&&
1139 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1140 case GL_LUMINANCE_SNORM
:
1141 case GL_LUMINANCE8_SNORM
:
1142 case GL_LUMINANCE16_SNORM
:
1143 return ctx
->Extensions
.EXT_texture_snorm
&&
1144 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1145 case GL_LUMINANCE_ALPHA_SNORM
:
1146 case GL_LUMINANCE8_ALPHA8_SNORM
:
1147 case GL_LUMINANCE16_ALPHA16_SNORM
:
1148 return ctx
->Extensions
.EXT_texture_snorm
&&
1149 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1150 case GL_INTENSITY_SNORM
:
1151 case GL_INTENSITY8_SNORM
:
1152 case GL_INTENSITY16_SNORM
:
1153 return ctx
->Extensions
.EXT_texture_snorm
&&
1154 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1157 return ctx
->Extensions
.ARB_texture_rg
&&
1158 ctx
->Extensions
.ARB_texture_float
? GL_RED
: 0;
1161 return ctx
->Extensions
.ARB_texture_rg
&&
1162 ctx
->Extensions
.ARB_texture_float
? GL_RG
: 0;
1165 return ctx
->Extensions
.ARB_texture_float
? GL_RGB
: 0;
1168 return ctx
->Extensions
.ARB_texture_float
? GL_RGBA
: 0;
1169 case GL_ALPHA16F_ARB
:
1170 case GL_ALPHA32F_ARB
:
1171 return ctx
->Extensions
.ARB_texture_float
&&
1172 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1173 case GL_LUMINANCE16F_ARB
:
1174 case GL_LUMINANCE32F_ARB
:
1175 return ctx
->Extensions
.ARB_texture_float
&&
1176 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1177 case GL_LUMINANCE_ALPHA16F_ARB
:
1178 case GL_LUMINANCE_ALPHA32F_ARB
:
1179 return ctx
->Extensions
.ARB_texture_float
&&
1180 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1181 case GL_INTENSITY16F_ARB
:
1182 case GL_INTENSITY32F_ARB
:
1183 return ctx
->Extensions
.ARB_texture_float
&&
1184 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1186 return ctx
->Extensions
.EXT_texture_shared_exponent
? GL_RGB
: 0;
1187 case GL_R11F_G11F_B10F
:
1188 return ctx
->Extensions
.EXT_packed_float
? GL_RGB
: 0;
1189 /* XXX add integer formats eventually */
1197 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1200 invalidate_rb(GLuint key
, void *data
, void *userData
)
1202 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1203 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1205 /* If this is a user-created FBO */
1208 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1209 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1210 if (att
->Type
== GL_RENDERBUFFER
&&
1211 att
->Renderbuffer
== rb
) {
1212 /* Mark fb status as indeterminate to force re-validation */
1221 /** sentinal value, see below */
1222 #define NO_SAMPLES 1000
1226 * Helper function used by _mesa_RenderbufferStorageEXT() and
1227 * _mesa_RenderbufferStorageMultisample().
1228 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
1231 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1232 GLsizei width
, GLsizei height
, GLsizei samples
)
1234 const char *func
= samples
== NO_SAMPLES
?
1235 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1236 struct gl_renderbuffer
*rb
;
1238 GET_CURRENT_CONTEXT(ctx
);
1240 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1242 if (target
!= GL_RENDERBUFFER_EXT
) {
1243 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1247 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1248 if (baseFormat
== 0) {
1249 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1253 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1254 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1258 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1259 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1263 if (samples
== NO_SAMPLES
) {
1264 /* NumSamples == 0 indicates non-multisampling */
1267 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1268 /* note: driver may choose to use more samples than what's requested */
1269 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1273 rb
= ctx
->CurrentRenderbuffer
;
1275 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1279 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1281 if (rb
->InternalFormat
== internalFormat
&&
1282 rb
->Width
== (GLuint
) width
&&
1283 rb
->Height
== (GLuint
) height
) {
1284 /* no change in allocation needed */
1288 /* These MUST get set by the AllocStorage func */
1289 rb
->Format
= MESA_FORMAT_NONE
;
1290 rb
->NumSamples
= samples
;
1292 /* Now allocate the storage */
1293 ASSERT(rb
->AllocStorage
);
1294 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1295 /* No error - check/set fields now */
1296 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1297 assert(rb
->Width
== (GLuint
) width
);
1298 assert(rb
->Height
== (GLuint
) height
);
1299 rb
->InternalFormat
= internalFormat
;
1300 rb
->_BaseFormat
= baseFormat
;
1301 assert(rb
->_BaseFormat
!= 0);
1304 /* Probably ran out of memory - clear the fields */
1307 rb
->Format
= MESA_FORMAT_NONE
;
1308 rb
->InternalFormat
= GL_NONE
;
1309 rb
->_BaseFormat
= GL_NONE
;
1313 /* Invalidate the framebuffers the renderbuffer is attached in. */
1314 if (rb
->AttachedAnytime
) {
1315 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1320 #if FEATURE_OES_EGL_image
1322 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1324 struct gl_renderbuffer
*rb
;
1325 GET_CURRENT_CONTEXT(ctx
);
1326 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1328 if (!ctx
->Extensions
.OES_EGL_image
) {
1329 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1330 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1334 if (target
!= GL_RENDERBUFFER
) {
1335 _mesa_error(ctx
, GL_INVALID_ENUM
,
1336 "EGLImageTargetRenderbufferStorageOES");
1340 rb
= ctx
->CurrentRenderbuffer
;
1342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1343 "EGLImageTargetRenderbufferStorageOES");
1347 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1349 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1355 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1356 * _mesa_GetFramebufferAttachmentParameterivEXT()
1357 * We have to be careful to respect the base format. For example, if a
1358 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1359 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1360 * we need to return zero.
1363 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1366 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1367 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1368 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
||
1369 baseFormat
== GL_RG
|| baseFormat
== GL_RED
)
1370 return _mesa_get_format_bits(format
, pname
);
1373 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1374 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1375 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
|| baseFormat
== GL_RG
)
1376 return _mesa_get_format_bits(format
, pname
);
1379 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1380 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1381 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1382 return _mesa_get_format_bits(format
, pname
);
1385 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1386 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1387 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
||
1388 baseFormat
== GL_LUMINANCE_ALPHA
)
1389 return _mesa_get_format_bits(format
, pname
);
1392 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1393 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1394 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1395 return _mesa_get_format_bits(format
, pname
);
1398 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1399 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1400 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1401 return _mesa_get_format_bits(format
, pname
);
1412 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1413 GLsizei width
, GLsizei height
)
1415 /* GL_ARB_fbo says calling this function is equivalent to calling
1416 * glRenderbufferStorageMultisample() with samples=0. We pass in
1417 * a token value here just for error reporting purposes.
1419 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1424 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1425 GLenum internalFormat
,
1426 GLsizei width
, GLsizei height
)
1428 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1433 * OpenGL ES version of glRenderBufferStorage.
1436 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1437 GLsizei width
, GLsizei height
)
1439 switch (internalFormat
) {
1441 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1442 /* choose a closest format */
1443 internalFormat
= GL_RGB5
;
1449 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1454 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1456 struct gl_renderbuffer
*rb
;
1457 GET_CURRENT_CONTEXT(ctx
);
1459 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1461 if (target
!= GL_RENDERBUFFER_EXT
) {
1462 _mesa_error(ctx
, GL_INVALID_ENUM
,
1463 "glGetRenderbufferParameterivEXT(target)");
1467 rb
= ctx
->CurrentRenderbuffer
;
1469 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1470 "glGetRenderbufferParameterivEXT");
1474 /* No need to flush here since we're just quering state which is
1475 * not effected by rendering.
1479 case GL_RENDERBUFFER_WIDTH_EXT
:
1480 *params
= rb
->Width
;
1482 case GL_RENDERBUFFER_HEIGHT_EXT
:
1483 *params
= rb
->Height
;
1485 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1486 *params
= rb
->InternalFormat
;
1488 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1489 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1490 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1491 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1492 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1493 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1494 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1496 case GL_RENDERBUFFER_SAMPLES
:
1497 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1498 *params
= rb
->NumSamples
;
1503 _mesa_error(ctx
, GL_INVALID_ENUM
,
1504 "glGetRenderbufferParameterivEXT(target)");
1510 GLboolean GLAPIENTRY
1511 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1513 GET_CURRENT_CONTEXT(ctx
);
1514 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1516 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1517 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1525 * Check if any of the attachments of the given framebuffer are textures
1526 * (render to texture). Call ctx->Driver.RenderTexture() for such
1530 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1533 ASSERT(ctx
->Driver
.RenderTexture
);
1536 return; /* can't render to texture with winsys framebuffers */
1538 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1539 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1540 if (att
->Texture
&& _mesa_get_attachment_teximage(att
)) {
1541 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1548 * Examine all the framebuffer's attachments to see if any are textures.
1549 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1550 * notify the device driver that the texture image may have changed.
1553 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1556 return; /* can't render to texture with winsys framebuffers */
1558 if (ctx
->Driver
.FinishRenderTexture
) {
1560 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1561 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1562 if (att
->Texture
&& att
->Renderbuffer
) {
1563 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1571 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1573 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1574 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1575 GLboolean bindReadBuf
, bindDrawBuf
;
1576 GET_CURRENT_CONTEXT(ctx
);
1579 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1580 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1581 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1585 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1587 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1588 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1589 "glBindFramebufferEXT(unsupported)");
1594 #if FEATURE_EXT_framebuffer_blit
1595 case GL_DRAW_FRAMEBUFFER_EXT
:
1596 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1597 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1600 bindDrawBuf
= GL_TRUE
;
1601 bindReadBuf
= GL_FALSE
;
1603 case GL_READ_FRAMEBUFFER_EXT
:
1604 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1605 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1608 bindDrawBuf
= GL_FALSE
;
1609 bindReadBuf
= GL_TRUE
;
1612 case GL_FRAMEBUFFER_EXT
:
1613 bindDrawBuf
= GL_TRUE
;
1614 bindReadBuf
= GL_TRUE
;
1617 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1622 /* Binding a user-created framebuffer object */
1623 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1624 if (newDrawFb
== &DummyFramebuffer
) {
1625 /* ID was reserved, but no real framebuffer object made yet */
1628 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1629 /* All FBO IDs must be Gen'd */
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1635 /* create new framebuffer object */
1636 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1638 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1641 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1643 newReadFb
= newDrawFb
;
1646 /* Binding the window system framebuffer (which was originally set
1647 * with MakeCurrent).
1649 newDrawFb
= ctx
->WinSysDrawBuffer
;
1650 newReadFb
= ctx
->WinSysReadBuffer
;
1654 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1656 /* save pointers to current/old framebuffers */
1657 oldDrawFb
= ctx
->DrawBuffer
;
1658 oldReadFb
= ctx
->ReadBuffer
;
1660 /* check if really changing bindings */
1661 if (oldDrawFb
== newDrawFb
)
1662 bindDrawBuf
= GL_FALSE
;
1663 if (oldReadFb
== newReadFb
)
1664 bindReadBuf
= GL_FALSE
;
1667 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1669 * We also check if we're beginning and/or ending render-to-texture.
1670 * When a framebuffer with texture attachments is unbound, call
1671 * ctx->Driver.FinishRenderTexture().
1672 * When a framebuffer with texture attachments is bound, call
1673 * ctx->Driver.RenderTexture().
1675 * Note that if the ReadBuffer has texture attachments we don't consider
1676 * that a render-to-texture case.
1679 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1681 /* check if old readbuffer was render-to-texture */
1682 check_end_texture_render(ctx
, oldReadFb
);
1684 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1688 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1690 /* check if old read/draw buffers were render-to-texture */
1692 check_end_texture_render(ctx
, oldReadFb
);
1694 if (oldDrawFb
!= oldReadFb
)
1695 check_end_texture_render(ctx
, oldDrawFb
);
1697 /* check if newly bound framebuffer has any texture attachments */
1698 check_begin_texture_render(ctx
, newDrawFb
);
1700 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1703 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1704 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1710 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1713 GET_CURRENT_CONTEXT(ctx
);
1715 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1716 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1718 for (i
= 0; i
< n
; i
++) {
1719 if (framebuffers
[i
] > 0) {
1720 struct gl_framebuffer
*fb
;
1721 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1723 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1725 /* check if deleting currently bound framebuffer object */
1726 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1727 /* separate draw/read binding points */
1728 if (fb
== ctx
->DrawBuffer
) {
1730 ASSERT(fb
->RefCount
>= 2);
1731 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1733 if (fb
== ctx
->ReadBuffer
) {
1735 ASSERT(fb
->RefCount
>= 2);
1736 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1740 /* only one binding point for read/draw buffers */
1741 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1743 ASSERT(fb
->RefCount
>= 2);
1744 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1748 /* remove from hash table immediately, to free the ID */
1749 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1751 if (fb
!= &DummyFramebuffer
) {
1752 /* But the object will not be freed until it's no longer
1753 * bound in any context.
1755 _mesa_reference_framebuffer(&fb
, NULL
);
1764 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1766 GET_CURRENT_CONTEXT(ctx
);
1770 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1773 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1780 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1782 for (i
= 0; i
< n
; i
++) {
1783 GLuint name
= first
+ i
;
1784 framebuffers
[i
] = name
;
1785 /* insert dummy placeholder into hash table */
1786 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1787 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1788 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1795 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1797 struct gl_framebuffer
*buffer
;
1798 GET_CURRENT_CONTEXT(ctx
);
1800 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1802 buffer
= get_framebuffer_target(ctx
, target
);
1804 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1808 if (buffer
->Name
== 0) {
1809 /* The window system / default framebuffer is always complete */
1810 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1813 /* No need to flush here */
1815 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1816 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1819 return buffer
->_Status
;
1825 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1828 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1829 GLenum attachment
, GLenum textarget
, GLuint texture
,
1830 GLint level
, GLint zoffset
)
1832 struct gl_renderbuffer_attachment
*att
;
1833 struct gl_texture_object
*texObj
= NULL
;
1834 struct gl_framebuffer
*fb
;
1836 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1838 fb
= get_framebuffer_target(ctx
, target
);
1840 _mesa_error(ctx
, GL_INVALID_ENUM
,
1841 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1845 /* check framebuffer binding */
1846 if (fb
->Name
== 0) {
1847 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1848 "glFramebufferTexture%sEXT", caller
);
1853 /* The textarget, level, and zoffset parameters are only validated if
1854 * texture is non-zero.
1857 GLboolean err
= GL_TRUE
;
1859 texObj
= _mesa_lookup_texture(ctx
, texture
);
1860 if (texObj
!= NULL
) {
1861 if (textarget
== 0) {
1862 /* XXX what's the purpose of this? */
1863 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1864 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1865 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1868 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1869 ? !IS_CUBE_FACE(textarget
)
1870 : (texObj
->Target
!= textarget
);
1874 /* can't render to a non-existant texture */
1875 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1876 "glFramebufferTexture%sEXT(non existant texture)",
1882 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1883 "glFramebufferTexture%sEXT(texture target mismatch)",
1888 if (texObj
->Target
== GL_TEXTURE_3D
) {
1889 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1890 if (zoffset
< 0 || zoffset
>= maxSize
) {
1891 _mesa_error(ctx
, GL_INVALID_VALUE
,
1892 "glFramebufferTexture%sEXT(zoffset)", caller
);
1896 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1897 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1898 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1899 _mesa_error(ctx
, GL_INVALID_VALUE
,
1900 "glFramebufferTexture%sEXT(layer)", caller
);
1906 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "glFramebufferTexture%sEXT(level)", caller
);
1913 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1915 _mesa_error(ctx
, GL_INVALID_ENUM
,
1916 "glFramebufferTexture%sEXT(attachment)", caller
);
1920 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1922 _glthread_LOCK_MUTEX(fb
->Mutex
);
1924 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1926 /* Set the render-to-texture flag. We'll check this flag in
1927 * glTexImage() and friends to determine if we need to revalidate
1928 * any FBOs that might be rendering into this texture.
1929 * This flag never gets cleared since it's non-trivial to determine
1930 * when all FBOs might be done rendering to this texture. That's OK
1931 * though since it's uncommon to render to a texture then repeatedly
1932 * call glTexImage() to change images in the texture.
1934 texObj
->_RenderToTexture
= GL_TRUE
;
1937 _mesa_remove_attachment(ctx
, att
);
1940 invalidate_framebuffer(fb
);
1942 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1948 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1949 GLenum textarget
, GLuint texture
, GLint level
)
1951 GET_CURRENT_CONTEXT(ctx
);
1953 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1954 _mesa_error(ctx
, GL_INVALID_ENUM
,
1955 "glFramebufferTexture1DEXT(textarget)");
1959 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1965 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1966 GLenum textarget
, GLuint texture
, GLint level
)
1968 GET_CURRENT_CONTEXT(ctx
);
1970 if ((texture
!= 0) &&
1971 (textarget
!= GL_TEXTURE_2D
) &&
1972 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1973 (!IS_CUBE_FACE(textarget
))) {
1974 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1975 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1979 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1985 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1986 GLenum textarget
, GLuint texture
,
1987 GLint level
, GLint zoffset
)
1989 GET_CURRENT_CONTEXT(ctx
);
1991 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1992 _mesa_error(ctx
, GL_INVALID_ENUM
,
1993 "glFramebufferTexture3DEXT(textarget)");
1997 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2003 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
2004 GLuint texture
, GLint level
, GLint layer
)
2006 GET_CURRENT_CONTEXT(ctx
);
2008 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2014 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
2015 GLenum renderbufferTarget
,
2016 GLuint renderbuffer
)
2018 struct gl_renderbuffer_attachment
*att
;
2019 struct gl_framebuffer
*fb
;
2020 struct gl_renderbuffer
*rb
;
2021 GET_CURRENT_CONTEXT(ctx
);
2023 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2025 fb
= get_framebuffer_target(ctx
, target
);
2027 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2031 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2032 _mesa_error(ctx
, GL_INVALID_ENUM
,
2033 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2037 if (fb
->Name
== 0) {
2038 /* Can't attach new renderbuffers to a window system framebuffer */
2039 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2043 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2045 _mesa_error(ctx
, GL_INVALID_ENUM
,
2046 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2047 _mesa_lookup_enum_by_nr(attachment
));
2052 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2054 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2055 "glFramebufferRenderbufferEXT(non-existant"
2056 " renderbuffer %u)", renderbuffer
);
2059 else if (rb
== &DummyRenderbuffer
) {
2060 /* This is what NVIDIA does */
2061 _mesa_error(ctx
, GL_INVALID_VALUE
,
2062 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2068 /* remove renderbuffer attachment */
2072 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2073 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2074 /* make sure the renderbuffer is a depth/stencil format */
2075 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2076 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2077 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2078 "glFramebufferRenderbufferEXT(renderbuffer"
2079 " is not DEPTH_STENCIL format)");
2085 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2087 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2088 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2090 /* Some subsequent GL commands may depend on the framebuffer's visual
2091 * after the binding is updated. Update visual info now.
2093 _mesa_update_framebuffer_visual(ctx
, fb
);
2098 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
2099 GLenum pname
, GLint
*params
)
2101 const struct gl_renderbuffer_attachment
*att
;
2102 struct gl_framebuffer
*buffer
;
2103 GET_CURRENT_CONTEXT(ctx
);
2105 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2107 buffer
= get_framebuffer_target(ctx
, target
);
2109 _mesa_error(ctx
, GL_INVALID_ENUM
,
2110 "glGetFramebufferAttachmentParameterivEXT(target)");
2114 if (buffer
->Name
== 0) {
2115 /* the default / window-system FBO */
2116 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2119 /* user-created framebuffer FBO */
2120 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2124 _mesa_error(ctx
, GL_INVALID_ENUM
,
2125 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2129 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2130 /* the depth and stencil attachments must point to the same buffer */
2131 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2132 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2133 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2134 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2136 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2137 " attachments differ)");
2142 /* No need to flush here */
2145 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2146 *params
= buffer
->Name
== 0 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2148 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2149 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2150 *params
= att
->Renderbuffer
->Name
;
2152 else if (att
->Type
== GL_TEXTURE
) {
2153 *params
= att
->Texture
->Name
;
2156 assert(att
->Type
== GL_NONE
);
2160 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2161 if (att
->Type
== GL_TEXTURE
) {
2162 *params
= att
->TextureLevel
;
2165 _mesa_error(ctx
, GL_INVALID_ENUM
,
2166 "glGetFramebufferAttachmentParameterivEXT(pname)");
2169 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2170 if (att
->Type
== GL_TEXTURE
) {
2171 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2172 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2179 _mesa_error(ctx
, GL_INVALID_ENUM
,
2180 "glGetFramebufferAttachmentParameterivEXT(pname)");
2183 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2184 if (att
->Type
== GL_TEXTURE
) {
2185 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2186 *params
= att
->Zoffset
;
2193 _mesa_error(ctx
, GL_INVALID_ENUM
,
2194 "glGetFramebufferAttachmentParameterivEXT(pname)");
2197 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2198 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2199 _mesa_error(ctx
, GL_INVALID_ENUM
,
2200 "glGetFramebufferAttachmentParameterivEXT(pname)");
2203 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&& ctx
->Const
.sRGBCapable
) {
2204 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2207 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2208 * if the sRGB conversion is unsupported. */
2209 *params
= GL_LINEAR
;
2213 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2214 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2215 _mesa_error(ctx
, GL_INVALID_ENUM
,
2216 "glGetFramebufferAttachmentParameterivEXT(pname)");
2220 gl_format format
= att
->Renderbuffer
->Format
;
2221 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2226 *params
= _mesa_get_format_datatype(format
);
2230 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2231 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2232 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2233 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2234 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2235 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2236 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2237 _mesa_error(ctx
, GL_INVALID_ENUM
,
2238 "glGetFramebufferAttachmentParameterivEXT(pname)");
2240 else if (att
->Texture
) {
2241 const struct gl_texture_image
*texImage
=
2242 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2245 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2246 texImage
->TexFormat
);
2252 else if (att
->Renderbuffer
) {
2253 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2254 att
->Renderbuffer
->Format
);
2261 _mesa_error(ctx
, GL_INVALID_ENUM
,
2262 "glGetFramebufferAttachmentParameterivEXT(pname)");
2269 _mesa_GenerateMipmapEXT(GLenum target
)
2271 struct gl_texture_object
*texObj
;
2272 GET_CURRENT_CONTEXT(ctx
);
2274 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2275 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2281 case GL_TEXTURE_CUBE_MAP
:
2282 /* OK, legal value */
2285 /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
2286 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2290 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2292 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2297 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2298 !_mesa_cube_complete(texObj
)) {
2299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2300 "glGenerateMipmap(incomplete cube map)");
2304 _mesa_lock_texture(ctx
, texObj
);
2305 if (target
== GL_TEXTURE_CUBE_MAP
) {
2307 for (face
= 0; face
< 6; face
++)
2308 ctx
->Driver
.GenerateMipmap(ctx
,
2309 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2313 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2315 _mesa_unlock_texture(ctx
, texObj
);
2319 #if FEATURE_EXT_framebuffer_blit
2321 static const struct gl_renderbuffer_attachment
*
2322 find_attachment(const struct gl_framebuffer
*fb
,
2323 const struct gl_renderbuffer
*rb
)
2326 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2327 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2328 return &fb
->Attachment
[i
];
2336 * Blit rectangular region, optionally from one framebuffer to another.
2338 * Note, if the src buffer is multisampled and the dest is not, this is
2339 * when the samples must be resolved to a single color.
2342 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2343 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2344 GLbitfield mask
, GLenum filter
)
2346 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2347 GL_DEPTH_BUFFER_BIT
|
2348 GL_STENCIL_BUFFER_BIT
);
2349 const struct gl_framebuffer
*readFb
, *drawFb
;
2350 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2351 GET_CURRENT_CONTEXT(ctx
);
2353 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2354 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2356 if (MESA_VERBOSE
& VERBOSE_API
)
2358 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2359 srcX0
, srcY0
, srcX1
, srcY1
,
2360 dstX0
, dstY0
, dstX1
, dstY1
,
2361 mask
, _mesa_lookup_enum_by_nr(filter
));
2363 if (ctx
->NewState
) {
2364 _mesa_update_state(ctx
);
2367 readFb
= ctx
->ReadBuffer
;
2368 drawFb
= ctx
->DrawBuffer
;
2370 if (!readFb
|| !drawFb
) {
2371 /* This will normally never happen but someday we may want to
2372 * support MakeCurrent() with no drawables.
2377 /* check for complete framebuffers */
2378 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2379 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2380 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2381 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2385 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2386 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2390 if (mask
& ~legalMaskBits
) {
2391 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2395 /* depth/stencil must be blitted with nearest filtering */
2396 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2397 && filter
!= GL_NEAREST
) {
2398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2399 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2403 /* get color read/draw renderbuffers */
2404 if (mask
& GL_COLOR_BUFFER_BIT
) {
2405 colorReadRb
= readFb
->_ColorReadBuffer
;
2406 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2409 colorReadRb
= colorDrawRb
= NULL
;
2412 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2413 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2414 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2417 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2418 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glBlitFramebufferEXT(stencil buffer size mismatch)");
2425 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2426 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2427 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2430 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2431 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2433 "glBlitFramebufferEXT(depth buffer size mismatch)");
2438 if (readFb
->Visual
.samples
> 0 &&
2439 drawFb
->Visual
.samples
> 0 &&
2440 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2442 "glBlitFramebufferEXT(mismatched samples");
2446 /* extra checks for multisample copies... */
2447 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2448 /* src and dest region sizes must be the same */
2449 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2450 srcY1
- srcY0
!= dstY1
- dstY0
) {
2451 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2452 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
2456 /* color formats must match */
2459 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2460 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2461 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
2466 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2467 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2473 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2475 srcX0
, srcY0
, srcX1
, srcY1
,
2476 dstX0
, dstY0
, dstX1
, dstY1
,
2479 const struct gl_renderbuffer_attachment
*att
;
2481 att
= find_attachment(readFb
, colorReadRb
);
2482 printf(" Src FBO %u RB %u (%dx%d) ",
2483 readFb
->Name
, colorReadRb
->Name
,
2484 colorReadRb
->Width
, colorReadRb
->Height
);
2485 if (att
&& att
->Texture
) {
2486 printf("Tex %u tgt 0x%x level %u face %u",
2488 att
->Texture
->Target
,
2494 att
= find_attachment(drawFb
, colorDrawRb
);
2495 printf(" Dst FBO %u RB %u (%dx%d) ",
2496 drawFb
->Name
, colorDrawRb
->Name
,
2497 colorDrawRb
->Width
, colorDrawRb
->Height
);
2498 if (att
&& att
->Texture
) {
2499 printf("Tex %u tgt 0x%x level %u face %u",
2501 att
->Texture
->Target
,
2509 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2510 ctx
->Driver
.BlitFramebuffer(ctx
,
2511 srcX0
, srcY0
, srcX1
, srcY1
,
2512 dstX0
, dstY0
, dstX1
, dstY1
,
2515 #endif /* FEATURE_EXT_framebuffer_blit */
2517 #if FEATURE_ARB_geometry_shader4
2519 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2520 GLuint texture
, GLint level
)
2522 GET_CURRENT_CONTEXT(ctx
);
2523 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2524 "glFramebufferTextureARB "
2525 "not implemented!");
2529 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2530 GLuint texture
, GLint level
, GLenum face
)
2532 GET_CURRENT_CONTEXT(ctx
);
2533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2534 "glFramebufferTextureFaceARB "
2535 "not implemented!");
2537 #endif /* FEATURE_ARB_geometry_shader4 */