2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include "framebuffer.h"
37 #include "renderbuffer.h"
47 * None of the GL_EXT_framebuffer_object functions are compiled into
54 * When glGenRender/FramebuffersEXT() is called we insert pointers to
55 * these placeholder objects into the hash table.
56 * Later, when the object ID is first bound, we replace the placeholder
57 * with the real frame/renderbuffer.
59 static struct gl_framebuffer DummyFramebuffer
;
60 static struct gl_renderbuffer DummyRenderbuffer
;
63 #define IS_CUBE_FACE(TARGET) \
64 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
65 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
69 * Helper routine for getting a gl_renderbuffer.
71 struct gl_renderbuffer
*
72 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
74 struct gl_renderbuffer
*rb
;
79 rb
= (struct gl_renderbuffer
*)
80 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
86 * Helper routine for getting a gl_framebuffer.
88 struct gl_framebuffer
*
89 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
91 struct gl_framebuffer
*fb
;
96 fb
= (struct gl_framebuffer
*)
97 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
103 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
104 * gl_renderbuffer_attachment object.
106 struct gl_renderbuffer_attachment
*
107 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
112 switch (attachment
) {
113 case GL_COLOR_ATTACHMENT0_EXT
:
114 case GL_COLOR_ATTACHMENT1_EXT
:
115 case GL_COLOR_ATTACHMENT2_EXT
:
116 case GL_COLOR_ATTACHMENT3_EXT
:
117 case GL_COLOR_ATTACHMENT4_EXT
:
118 case GL_COLOR_ATTACHMENT5_EXT
:
119 case GL_COLOR_ATTACHMENT6_EXT
:
120 case GL_COLOR_ATTACHMENT7_EXT
:
121 case GL_COLOR_ATTACHMENT8_EXT
:
122 case GL_COLOR_ATTACHMENT9_EXT
:
123 case GL_COLOR_ATTACHMENT10_EXT
:
124 case GL_COLOR_ATTACHMENT11_EXT
:
125 case GL_COLOR_ATTACHMENT12_EXT
:
126 case GL_COLOR_ATTACHMENT13_EXT
:
127 case GL_COLOR_ATTACHMENT14_EXT
:
128 case GL_COLOR_ATTACHMENT15_EXT
:
129 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
130 if (i
>= ctx
->Const
.MaxColorAttachments
) {
133 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
134 case GL_DEPTH_ATTACHMENT_EXT
:
135 return &fb
->Attachment
[BUFFER_DEPTH
];
136 case GL_STENCIL_ATTACHMENT_EXT
:
137 return &fb
->Attachment
[BUFFER_STENCIL
];
145 * Remove any texture or renderbuffer attached to the given attachment
146 * point. Update reference counts, etc.
149 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
151 if (att
->Type
== GL_TEXTURE
) {
152 ASSERT(att
->Texture
);
153 att
->Texture
->RefCount
--;
154 if (att
->Texture
->RefCount
== 0) {
155 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
158 /* tell driver that we're done rendering to this texture. */
159 if (ctx
->Driver
.FinishRenderTexture
) {
160 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
165 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
166 ASSERT(att
->Renderbuffer
);
167 ASSERT(!att
->Texture
);
168 att
->Renderbuffer
->RefCount
--;
169 if (att
->Renderbuffer
->RefCount
== 0) {
170 att
->Renderbuffer
->Delete(att
->Renderbuffer
);
172 att
->Renderbuffer
= NULL
;
175 att
->Complete
= GL_TRUE
;
180 * Bind a texture object to an attachment point.
181 * The previous binding, if any, will be removed first.
184 _mesa_set_texture_attachment(GLcontext
*ctx
,
185 struct gl_framebuffer
*fb
,
186 struct gl_renderbuffer_attachment
*att
,
187 struct gl_texture_object
*texObj
,
188 GLenum texTarget
, GLuint level
, GLuint zoffset
)
190 if (att
->Texture
== texObj
) {
191 /* re-attaching same texture */
192 ASSERT(att
->Type
== GL_TEXTURE
);
196 _mesa_remove_attachment(ctx
, att
);
197 att
->Type
= GL_TEXTURE
;
198 att
->Texture
= texObj
;
202 /* always update these fields */
203 att
->TextureLevel
= level
;
204 if (IS_CUBE_FACE(texTarget
)) {
205 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
208 att
->CubeMapFace
= 0;
210 att
->Zoffset
= zoffset
;
211 att
->Complete
= GL_FALSE
;
213 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
214 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
220 * Bind a renderbuffer to an attachment point.
221 * The previous binding, if any, will be removed first.
224 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
225 struct gl_renderbuffer_attachment
*att
,
226 struct gl_renderbuffer
*rb
)
228 /* XXX check if re-doing same attachment, exit early */
229 _mesa_remove_attachment(ctx
, att
);
230 att
->Type
= GL_RENDERBUFFER_EXT
;
231 att
->Renderbuffer
= rb
;
232 att
->Texture
= NULL
; /* just to be safe */
233 att
->Complete
= GL_FALSE
;
239 * Fallback for ctx->Driver.FramebufferRenderbuffer()
240 * Attach a renderbuffer object to a framebuffer object.
243 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
244 GLenum attachment
, struct gl_renderbuffer
*rb
)
246 struct gl_renderbuffer_attachment
*att
;
248 _glthread_LOCK_MUTEX(fb
->Mutex
);
250 _glthread_LOCK_MUTEX(rb
->Mutex
);
252 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
256 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
259 _mesa_remove_attachment(ctx
, att
);
263 _glthread_UNLOCK_MUTEX(rb
->Mutex
);
264 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
269 * Test if an attachment point is complete and update its Complete field.
270 * \param format if GL_COLOR, this is a color attachment point,
271 * if GL_DEPTH, this is a depth component attachment point,
272 * if GL_STENCIL, this is a stencil component attachment point.
275 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
276 struct gl_renderbuffer_attachment
*att
)
278 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
280 /* assume complete */
281 att
->Complete
= GL_TRUE
;
283 /* Look for reasons why the attachment might be incomplete */
284 if (att
->Type
== GL_TEXTURE
) {
285 const struct gl_texture_object
*texObj
= att
->Texture
;
286 struct gl_texture_image
*texImage
;
289 att
->Complete
= GL_FALSE
;
293 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
295 att
->Complete
= GL_FALSE
;
298 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
299 att
->Complete
= GL_FALSE
;
302 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
303 att
->Complete
= GL_FALSE
;
307 if (format
== GL_COLOR
) {
308 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
309 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
310 att
->Complete
= GL_FALSE
;
314 else if (format
== GL_DEPTH
) {
315 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
318 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
319 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
323 att
->Complete
= GL_FALSE
;
328 /* no such thing as stencil textures */
329 att
->Complete
= GL_FALSE
;
333 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
334 ASSERT(att
->Renderbuffer
);
335 if (!att
->Renderbuffer
->InternalFormat
||
336 att
->Renderbuffer
->Width
< 1 ||
337 att
->Renderbuffer
->Height
< 1) {
338 att
->Complete
= GL_FALSE
;
341 if (format
== GL_COLOR
) {
342 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
343 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
344 ASSERT(att
->Renderbuffer
->RedBits
);
345 ASSERT(att
->Renderbuffer
->GreenBits
);
346 ASSERT(att
->Renderbuffer
->BlueBits
);
347 att
->Complete
= GL_FALSE
;
351 else if (format
== GL_DEPTH
) {
352 ASSERT(att
->Renderbuffer
->DepthBits
);
353 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
356 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
357 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
361 att
->Complete
= GL_FALSE
;
366 assert(format
== GL_STENCIL
);
367 ASSERT(att
->Renderbuffer
->StencilBits
);
368 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
371 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
372 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
376 att
->Complete
= GL_FALSE
;
382 ASSERT(att
->Type
== GL_NONE
);
390 * Helpful for debugging
393 fbo_incomplete(const char *msg
, int index
)
398 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
404 * Test if the given framebuffer object is complete and update its
405 * Status field with the results.
406 * Also update the framebuffer's Width and Height fields if the
407 * framebuffer is complete.
410 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
412 GLuint numImages
, width
= 0, height
= 0;
413 GLenum intFormat
= GL_NONE
;
418 assert(fb
->Name
!= 0);
424 /* Start at -2 to more easily loop over all attachment points */
425 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
426 struct gl_renderbuffer_attachment
*att
;
430 att
= &fb
->Attachment
[BUFFER_DEPTH
];
431 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
432 if (!att
->Complete
) {
433 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
434 fbo_incomplete("depth attachment incomplete", -1);
439 att
= &fb
->Attachment
[BUFFER_STENCIL
];
440 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
441 if (!att
->Complete
) {
442 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
443 fbo_incomplete("stencil attachment incomplete", -1);
448 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
449 test_attachment_completeness(ctx
, GL_COLOR
, att
);
450 if (!att
->Complete
) {
451 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
452 fbo_incomplete("color attachment incomplete", i
);
457 if (att
->Type
== GL_TEXTURE
) {
458 const struct gl_texture_image
*texImg
459 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
462 f
= texImg
->_BaseFormat
;
464 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
465 && f
!= GL_DEPTH_STENCIL_EXT
) {
466 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
467 fbo_incomplete("texture attachment incomplete", -1);
471 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
472 w
= att
->Renderbuffer
->Width
;
473 h
= att
->Renderbuffer
->Height
;
474 f
= att
->Renderbuffer
->InternalFormat
;
478 assert(att
->Type
== GL_NONE
);
482 if (numImages
== 1) {
483 /* set required width, height and format */
490 /* check that width, height, format are same */
491 if (w
!= width
|| h
!= height
) {
492 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
493 fbo_incomplete("width or height mismatch", -1);
496 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
497 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
498 fbo_incomplete("format mismatch", -1);
504 /* Check that all DrawBuffers are present */
505 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
506 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
507 const struct gl_renderbuffer_attachment
*att
508 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
510 if (att
->Type
== GL_NONE
) {
511 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
512 fbo_incomplete("missing drawbuffer", j
);
518 /* Check that the ReadBuffer is present */
519 if (fb
->ColorReadBuffer
!= GL_NONE
) {
520 const struct gl_renderbuffer_attachment
*att
521 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
523 if (att
->Type
== GL_NONE
) {
524 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
525 fbo_incomplete("missing readbuffer", -1);
530 if (numImages
== 0) {
531 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
532 fbo_incomplete("no attachments", -1);
537 * If we get here, the framebuffer is complete!
539 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
546 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
548 GET_CURRENT_CONTEXT(ctx
);
549 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
551 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
552 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
560 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
562 struct gl_renderbuffer
*newRb
, *oldRb
;
563 GET_CURRENT_CONTEXT(ctx
);
565 ASSERT_OUTSIDE_BEGIN_END(ctx
);
567 if (target
!= GL_RENDERBUFFER_EXT
) {
568 _mesa_error(ctx
, GL_INVALID_ENUM
,
569 "glBindRenderbufferEXT(target)");
573 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
574 /* The above doesn't fully flush the drivers in the way that a
575 * glFlush does, but that is required here:
577 if (ctx
->Driver
.Flush
)
578 ctx
->Driver
.Flush(ctx
);
582 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
583 if (newRb
== &DummyRenderbuffer
) {
584 /* ID was reserved, but no real renderbuffer object made yet */
588 /* create new renderbuffer object */
589 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
591 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
594 ASSERT(newRb
->AllocStorage
);
595 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
603 oldRb
= ctx
->CurrentRenderbuffer
;
605 _mesa_unreference_renderbuffer(&oldRb
);
608 ASSERT(newRb
!= &DummyRenderbuffer
);
610 ctx
->CurrentRenderbuffer
= newRb
;
615 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
618 GET_CURRENT_CONTEXT(ctx
);
620 ASSERT_OUTSIDE_BEGIN_END(ctx
);
621 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
623 for (i
= 0; i
< n
; i
++) {
624 if (renderbuffers
[i
] > 0) {
625 struct gl_renderbuffer
*rb
;
626 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
628 /* check if deleting currently bound renderbuffer object */
629 if (rb
== ctx
->CurrentRenderbuffer
) {
631 ASSERT(rb
->RefCount
>= 2);
632 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
635 /* remove from hash table immediately, to free the ID */
636 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
638 if (rb
!= &DummyRenderbuffer
) {
639 /* But the object will not be freed until it's no longer
640 * bound in any context.
642 _mesa_unreference_renderbuffer(&rb
);
651 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
653 GET_CURRENT_CONTEXT(ctx
);
657 ASSERT_OUTSIDE_BEGIN_END(ctx
);
660 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
667 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
669 for (i
= 0; i
< n
; i
++) {
670 GLuint name
= first
+ i
;
671 renderbuffers
[i
] = name
;
672 /* insert dummy placeholder into hash table */
673 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
674 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
675 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
681 * Given an internal format token for a render buffer, return the
682 * corresponding base format.
683 * This is very similar to _mesa_base_tex_format() but the set of valid
684 * internal formats is somewhat different.
686 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
687 * GL_DEPTH_STENCIL_EXT or zero if error.
690 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
692 switch (internalFormat
) {
711 case GL_STENCIL_INDEX
:
712 case GL_STENCIL_INDEX1_EXT
:
713 case GL_STENCIL_INDEX4_EXT
:
714 case GL_STENCIL_INDEX8_EXT
:
715 case GL_STENCIL_INDEX16_EXT
:
716 return GL_STENCIL_INDEX
;
717 case GL_DEPTH_COMPONENT
:
718 case GL_DEPTH_COMPONENT16
:
719 case GL_DEPTH_COMPONENT24
:
720 case GL_DEPTH_COMPONENT32
:
721 return GL_DEPTH_COMPONENT
;
722 case GL_DEPTH_STENCIL_EXT
:
723 case GL_DEPTH24_STENCIL8_EXT
:
724 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
725 return GL_DEPTH_STENCIL_EXT
;
728 /* XXX add floating point formats eventually */
736 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
737 GLsizei width
, GLsizei height
)
739 struct gl_renderbuffer
*rb
;
741 GET_CURRENT_CONTEXT(ctx
);
743 ASSERT_OUTSIDE_BEGIN_END(ctx
);
745 if (target
!= GL_RENDERBUFFER_EXT
) {
746 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
750 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
751 if (baseFormat
== 0) {
752 _mesa_error(ctx
, GL_INVALID_ENUM
,
753 "glRenderbufferStorageEXT(internalFormat)");
757 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
758 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
762 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
767 rb
= ctx
->CurrentRenderbuffer
;
770 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
774 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
776 if (rb
->InternalFormat
== internalFormat
&&
777 rb
->Width
== (GLuint
) width
&&
778 rb
->Height
== (GLuint
) height
) {
779 /* no change in allocation needed */
783 /* These MUST get set by the AllocStorage func */
784 rb
->_ActualFormat
= 0;
793 /* Now allocate the storage */
794 ASSERT(rb
->AllocStorage
);
795 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
796 /* No error - check/set fields now */
797 assert(rb
->_ActualFormat
);
798 assert(rb
->Width
== (GLuint
) width
);
799 assert(rb
->Height
== (GLuint
) height
);
800 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
801 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
802 rb
->InternalFormat
= internalFormat
;
803 rb
->_BaseFormat
= baseFormat
;
806 /* Probably ran out of memory - clear the fields */
809 rb
->InternalFormat
= GL_NONE
;
810 rb
->_ActualFormat
= GL_NONE
;
811 rb
->_BaseFormat
= GL_NONE
;
822 test_framebuffer_completeness(ctx, fb);
824 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
831 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
833 GET_CURRENT_CONTEXT(ctx
);
835 ASSERT_OUTSIDE_BEGIN_END(ctx
);
837 if (target
!= GL_RENDERBUFFER_EXT
) {
838 _mesa_error(ctx
, GL_INVALID_ENUM
,
839 "glGetRenderbufferParameterivEXT(target)");
843 if (!ctx
->CurrentRenderbuffer
) {
844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
845 "glGetRenderbufferParameterivEXT");
849 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
852 case GL_RENDERBUFFER_WIDTH_EXT
:
853 *params
= ctx
->CurrentRenderbuffer
->Width
;
855 case GL_RENDERBUFFER_HEIGHT_EXT
:
856 *params
= ctx
->CurrentRenderbuffer
->Height
;
858 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
859 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
861 case GL_RENDERBUFFER_RED_SIZE_EXT
:
862 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
864 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
865 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
867 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
868 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
870 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
871 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
873 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
874 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
876 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
877 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
880 _mesa_error(ctx
, GL_INVALID_ENUM
,
881 "glGetRenderbufferParameterivEXT(target)");
888 _mesa_IsFramebufferEXT(GLuint framebuffer
)
890 GET_CURRENT_CONTEXT(ctx
);
891 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
893 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
894 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
902 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
905 ASSERT(ctx
->Driver
.RenderTexture
);
906 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
907 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
908 struct gl_texture_object
*texObj
= att
->Texture
;
910 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
911 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
918 * Examine all the framebuffer's attachments to see if any are textures.
919 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
920 * notify the device driver that the texture image may have changed.
923 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
925 if (ctx
->Driver
.FinishRenderTexture
) {
927 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
928 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
929 struct gl_texture_object
*texObj
= att
->Texture
;
931 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
939 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
941 struct gl_framebuffer
*newFb
;
942 GLboolean bindReadBuf
, bindDrawBuf
;
943 GET_CURRENT_CONTEXT(ctx
);
945 ASSERT_OUTSIDE_BEGIN_END(ctx
);
947 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
948 _mesa_error(ctx
, GL_INVALID_OPERATION
,
949 "glBindFramebufferEXT(unsupported)");
954 #if FEATURE_EXT_framebuffer_blit
955 case GL_DRAW_FRAMEBUFFER_EXT
:
956 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
957 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
960 bindDrawBuf
= GL_TRUE
;
961 bindReadBuf
= GL_FALSE
;
963 case GL_READ_FRAMEBUFFER_EXT
:
964 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
965 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
968 bindDrawBuf
= GL_FALSE
;
969 bindReadBuf
= GL_TRUE
;
972 case GL_FRAMEBUFFER_EXT
:
973 bindDrawBuf
= GL_TRUE
;
974 bindReadBuf
= GL_TRUE
;
977 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
981 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
982 if (ctx
->Driver
.Flush
) {
983 ctx
->Driver
.Flush(ctx
);
986 /* Binding a user-created framebuffer object */
987 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
988 if (newFb
== &DummyFramebuffer
) {
989 /* ID was reserved, but no real framebuffer object made yet */
993 /* create new framebuffer object */
994 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
996 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
999 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
1003 /* Binding the window system framebuffer (which was originally set
1004 * with MakeCurrent).
1006 newFb
= ctx
->WinSysDrawBuffer
;
1010 ASSERT(newFb
!= &DummyFramebuffer
);
1013 * XXX check if re-binding same buffer and skip some of this code.
1017 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFb
);
1021 /* check if old FB had any texture attachments */
1022 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1023 /* check if time to delete this framebuffer */
1024 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1025 if (newFb
->Name
!= 0) {
1026 /* check if newly bound framebuffer has any texture attachments */
1027 check_begin_texture_render(ctx
, newFb
);
1031 if (ctx
->Driver
.BindFramebuffer
) {
1032 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
);
1038 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1041 GET_CURRENT_CONTEXT(ctx
);
1043 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1044 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1045 /* The above doesn't fully flush the drivers in the way that a
1046 * glFlush does, but that is required here:
1048 if (ctx
->Driver
.Flush
)
1049 ctx
->Driver
.Flush(ctx
);
1051 for (i
= 0; i
< n
; i
++) {
1052 if (framebuffers
[i
] > 0) {
1053 struct gl_framebuffer
*fb
;
1054 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1056 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1058 /* check if deleting currently bound framebuffer object */
1059 if (fb
== ctx
->DrawBuffer
) {
1061 ASSERT(fb
->RefCount
>= 2);
1062 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1065 /* remove from hash table immediately, to free the ID */
1066 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1068 if (fb
!= &DummyFramebuffer
) {
1069 /* But the object will not be freed until it's no longer
1070 * bound in any context.
1072 _mesa_unreference_framebuffer(&fb
);
1081 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1083 GET_CURRENT_CONTEXT(ctx
);
1087 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1090 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1097 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1099 for (i
= 0; i
< n
; i
++) {
1100 GLuint name
= first
+ i
;
1101 framebuffers
[i
] = name
;
1102 /* insert dummy placeholder into hash table */
1103 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1104 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1105 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1112 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1114 struct gl_framebuffer
*buffer
;
1115 GET_CURRENT_CONTEXT(ctx
);
1117 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1120 #if FEATURE_EXT_framebuffer_blit
1121 case GL_DRAW_FRAMEBUFFER_EXT
:
1122 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1123 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1126 buffer
= ctx
->DrawBuffer
;
1128 case GL_READ_FRAMEBUFFER_EXT
:
1129 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1130 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1133 buffer
= ctx
->ReadBuffer
;
1136 case GL_FRAMEBUFFER_EXT
:
1137 buffer
= ctx
->DrawBuffer
;
1140 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1141 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1144 if (buffer
->Name
== 0) {
1145 /* The window system / default framebuffer is always complete */
1146 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1149 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1151 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1152 return buffer
->_Status
;
1158 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1161 framebuffer_texture(GLuint dims
, GLenum target
, GLenum attachment
,
1162 GLenum textarget
, GLuint texture
,
1163 GLint level
, GLint zoffset
)
1165 struct gl_renderbuffer_attachment
*att
;
1166 struct gl_texture_object
*texObj
= NULL
;
1167 struct gl_framebuffer
*fb
;
1168 GET_CURRENT_CONTEXT(ctx
);
1170 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1172 if (target
!= GL_FRAMEBUFFER_EXT
) {
1173 _mesa_error(ctx
, GL_INVALID_ENUM
,
1174 "glFramebufferTexture%dDEXT(target)", dims
);
1178 fb
= ctx
->DrawBuffer
;
1181 /* check framebuffer binding */
1182 if (fb
->Name
== 0) {
1183 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1184 "glFramebufferTexture%dDEXT", dims
);
1189 texObj
= _mesa_lookup_texture(ctx
, texture
);
1192 /* Check dimension-dependent things */
1195 if (textarget
!= GL_TEXTURE_1D
) {
1196 _mesa_error(ctx
, GL_INVALID_ENUM
,
1197 "glFramebufferTexture1DEXT(textarget)");
1200 if (texObj
&& texObj
->Target
!= GL_TEXTURE_1D
) {
1201 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1202 "glFramebufferTexture1DEXT(texture target mismatch)");
1207 if (textarget
!= GL_TEXTURE_2D
&&
1208 textarget
!= GL_TEXTURE_RECTANGLE_ARB
&&
1209 !IS_CUBE_FACE(textarget
)) {
1210 _mesa_error(ctx
, GL_INVALID_ENUM
,
1211 "glFramebufferTexture2DEXT(textarget)");
1215 if ((texObj
->Target
== GL_TEXTURE_2D
&& textarget
!= GL_TEXTURE_2D
) ||
1216 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
1217 && textarget
!= GL_TEXTURE_RECTANGLE_ARB
) ||
1218 (texObj
->Target
== GL_TEXTURE_CUBE_MAP
1219 && !IS_CUBE_FACE(textarget
))) {
1220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1221 "glFramebufferTexture1DEXT(texture target mismatch)");
1227 if (textarget
!= GL_TEXTURE_3D
) {
1228 _mesa_error(ctx
, GL_INVALID_ENUM
,
1229 "glFramebufferTexture3DEXT(textarget)");
1232 if (texObj
&& texObj
->Target
!= GL_TEXTURE_3D
) {
1233 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1234 "glFramebufferTexture3DEXT(texture target mismatch)");
1238 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1239 if (zoffset
< 0 || zoffset
>= maxSize
) {
1240 _mesa_error(ctx
, GL_INVALID_VALUE
,
1241 "glFramebufferTexture3DEXT(zoffset)");
1247 _mesa_problem(ctx
, "Unexpected dims in error_check_framebuffer_texture");
1251 if ((level
< 0) || level
>= _mesa_max_texture_levels(ctx
, textarget
)) {
1252 _mesa_error(ctx
, GL_INVALID_VALUE
,
1253 "glFramebufferTexture%dDEXT(level)", dims
);
1257 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1259 _mesa_error(ctx
, GL_INVALID_ENUM
,
1260 "glFramebufferTexture%dDEXT(attachment)", dims
);
1264 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1265 /* The above doesn't fully flush the drivers in the way that a
1266 * glFlush does, but that is required here:
1268 if (ctx
->Driver
.Flush
)
1269 ctx
->Driver
.Flush(ctx
);
1271 _glthread_LOCK_MUTEX(fb
->Mutex
);
1273 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1277 _mesa_remove_attachment(ctx
, att
);
1279 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1285 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1286 GLenum textarget
, GLuint texture
, GLint level
)
1288 const GLint zoffset
= 0;
1289 framebuffer_texture(1, target
, attachment
, textarget
, texture
,
1295 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1296 GLenum textarget
, GLuint texture
, GLint level
)
1298 const GLint zoffset
= 0;
1299 framebuffer_texture(2, target
, attachment
, textarget
, texture
,
1305 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1306 GLenum textarget
, GLuint texture
,
1307 GLint level
, GLint zoffset
)
1309 framebuffer_texture(3, target
, attachment
, textarget
, texture
,
1316 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1317 GLenum renderbufferTarget
,
1318 GLuint renderbuffer
)
1320 struct gl_renderbuffer_attachment
*att
;
1321 struct gl_framebuffer
*fb
;
1322 struct gl_renderbuffer
*rb
;
1323 GET_CURRENT_CONTEXT(ctx
);
1325 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1328 #if FEATURE_EXT_framebuffer_blit
1329 case GL_DRAW_FRAMEBUFFER_EXT
:
1330 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1331 _mesa_error(ctx
, GL_INVALID_ENUM
,
1332 "glFramebufferRenderbufferEXT(target)");
1335 fb
= ctx
->DrawBuffer
;
1337 case GL_READ_FRAMEBUFFER_EXT
:
1338 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1339 _mesa_error(ctx
, GL_INVALID_ENUM
,
1340 "glFramebufferRenderbufferEXT(target)");
1343 fb
= ctx
->ReadBuffer
;
1346 case GL_FRAMEBUFFER_EXT
:
1347 fb
= ctx
->DrawBuffer
;
1350 _mesa_error(ctx
, GL_INVALID_ENUM
,
1351 "glFramebufferRenderbufferEXT(target)");
1355 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1356 _mesa_error(ctx
, GL_INVALID_ENUM
,
1357 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1361 if (fb
->Name
== 0) {
1362 /* Can't attach new renderbuffers to a window system framebuffer */
1363 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1367 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1369 _mesa_error(ctx
, GL_INVALID_ENUM
,
1370 "glFramebufferRenderbufferEXT(attachment)");
1375 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1378 "glFramebufferRenderbufferEXT(renderbuffer)");
1383 /* remove renderbuffer attachment */
1387 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1388 /* The above doesn't fully flush the drivers in the way that a
1389 * glFlush does, but that is required here:
1391 if (ctx
->Driver
.Flush
)
1392 ctx
->Driver
.Flush(ctx
);
1394 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1395 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1397 /* Some subsequent GL commands may depend on the framebuffer's visual
1398 * after the binding is updated. Update visual info now.
1400 _mesa_update_framebuffer_visual(fb
);
1405 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1406 GLenum pname
, GLint
*params
)
1408 const struct gl_renderbuffer_attachment
*att
;
1409 struct gl_framebuffer
*buffer
;
1410 GET_CURRENT_CONTEXT(ctx
);
1412 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1415 #if FEATURE_EXT_framebuffer_blit
1416 case GL_DRAW_FRAMEBUFFER_EXT
:
1417 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1418 _mesa_error(ctx
, GL_INVALID_ENUM
,
1419 "glGetFramebufferAttachmentParameterivEXT(target)");
1422 buffer
= ctx
->DrawBuffer
;
1424 case GL_READ_FRAMEBUFFER_EXT
:
1425 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1426 _mesa_error(ctx
, GL_INVALID_ENUM
,
1427 "glGetFramebufferAttachmentParameterivEXT(target)");
1430 buffer
= ctx
->ReadBuffer
;
1433 case GL_FRAMEBUFFER_EXT
:
1434 buffer
= ctx
->DrawBuffer
;
1437 _mesa_error(ctx
, GL_INVALID_ENUM
,
1438 "glGetFramebufferAttachmentParameterivEXT(target)");
1442 if (buffer
->Name
== 0) {
1443 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1444 "glGetFramebufferAttachmentParameterivEXT");
1448 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1455 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1456 /* The above doesn't fully flush the drivers in the way that a
1457 * glFlush does, but that is required here:
1459 if (ctx
->Driver
.Flush
)
1460 ctx
->Driver
.Flush(ctx
);
1463 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1464 *params
= att
->Type
;
1466 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1467 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1468 *params
= att
->Renderbuffer
->Name
;
1470 else if (att
->Type
== GL_TEXTURE
) {
1471 *params
= att
->Texture
->Name
;
1474 _mesa_error(ctx
, GL_INVALID_ENUM
,
1475 "glGetFramebufferAttachmentParameterivEXT(pname)");
1478 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1479 if (att
->Type
== GL_TEXTURE
) {
1480 *params
= att
->TextureLevel
;
1483 _mesa_error(ctx
, GL_INVALID_ENUM
,
1484 "glGetFramebufferAttachmentParameterivEXT(pname)");
1487 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1488 if (att
->Type
== GL_TEXTURE
) {
1489 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1492 _mesa_error(ctx
, GL_INVALID_ENUM
,
1493 "glGetFramebufferAttachmentParameterivEXT(pname)");
1496 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1497 if (att
->Type
== GL_TEXTURE
) {
1498 *params
= att
->Zoffset
;
1501 _mesa_error(ctx
, GL_INVALID_ENUM
,
1502 "glGetFramebufferAttachmentParameterivEXT(pname)");
1506 _mesa_error(ctx
, GL_INVALID_ENUM
,
1507 "glGetFramebufferAttachmentParameterivEXT(pname)");
1514 _mesa_GenerateMipmapEXT(GLenum target
)
1516 struct gl_texture_unit
*texUnit
;
1517 struct gl_texture_object
*texObj
;
1518 GET_CURRENT_CONTEXT(ctx
);
1520 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1521 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1527 case GL_TEXTURE_CUBE_MAP
:
1528 /* OK, legal value */
1531 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1535 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1536 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1538 /* XXX this might not handle cube maps correctly */
1539 _mesa_lock_texture(ctx
, texObj
);
1540 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1541 _mesa_unlock_texture(ctx
, texObj
);
1545 #if FEATURE_EXT_framebuffer_blit
1547 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1548 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1549 GLbitfield mask
, GLenum filter
)
1551 GET_CURRENT_CONTEXT(ctx
);
1553 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1554 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1556 if (ctx
->NewState
) {
1557 _mesa_update_state(ctx
);
1560 if (!ctx
->ReadBuffer
) {
1564 /* check for complete framebuffers */
1565 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1566 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1567 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1568 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1572 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1573 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1577 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1578 GL_DEPTH_BUFFER_BIT
|
1579 GL_STENCIL_BUFFER_BIT
)) {
1580 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1584 /* depth/stencil must be blitted with nearest filtering */
1585 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1586 && filter
!= GL_NEAREST
) {
1587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1588 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1592 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1593 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1594 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1595 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1597 "glBlitFramebufferEXT(stencil buffer size mismatch");
1602 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1603 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1604 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1605 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1606 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1607 "glBlitFramebufferEXT(depth buffer size mismatch");
1612 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1617 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1618 ctx
->Driver
.BlitFramebuffer(ctx
,
1619 srcX0
, srcY0
, srcX1
, srcY1
,
1620 dstX0
, dstY0
, dstX1
, dstY1
,
1623 #endif /* FEATURE_EXT_framebuffer_blit */