2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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"
36 #include "renderbuffer.h"
42 /* XXX temporarily here */
43 #define GL_READ_FRAMEBUFFER_EXT 0x90
44 #define GL_DRAW_FRAMEBUFFER_EXT 0x9a
45 #define GL_DRAW_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING_EXT
46 #define GL_READ_FRAMEBUFFER_BINDING_EXT 0x9b
52 * None of the GL_EXT_framebuffer_object functions are compiled into
59 * When glGenRender/FramebuffersEXT() is called we insert pointers to
60 * these placeholder objects into the hash table.
61 * Later, when the object ID is first bound, we replace the placeholder
62 * with the real frame/renderbuffer.
64 static struct gl_framebuffer DummyFramebuffer
;
65 static struct gl_renderbuffer DummyRenderbuffer
;
68 #define IS_CUBE_FACE(TARGET) \
69 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
70 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
74 * Helper routine for getting a gl_renderbuffer.
76 static struct gl_renderbuffer
*
77 lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
79 struct gl_renderbuffer
*rb
;
84 rb
= (struct gl_renderbuffer
*)
85 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
91 * Helper routine for getting a gl_framebuffer.
93 static struct gl_framebuffer
*
94 lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
96 struct gl_framebuffer
*fb
;
101 fb
= (struct gl_framebuffer
*)
102 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
108 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
109 * gl_renderbuffer_attachment object.
111 static struct gl_renderbuffer_attachment
*
112 get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
, GLenum attachment
)
116 switch (attachment
) {
117 case GL_COLOR_ATTACHMENT0_EXT
:
118 case GL_COLOR_ATTACHMENT1_EXT
:
119 case GL_COLOR_ATTACHMENT2_EXT
:
120 case GL_COLOR_ATTACHMENT3_EXT
:
121 case GL_COLOR_ATTACHMENT4_EXT
:
122 case GL_COLOR_ATTACHMENT5_EXT
:
123 case GL_COLOR_ATTACHMENT6_EXT
:
124 case GL_COLOR_ATTACHMENT7_EXT
:
125 case GL_COLOR_ATTACHMENT8_EXT
:
126 case GL_COLOR_ATTACHMENT9_EXT
:
127 case GL_COLOR_ATTACHMENT10_EXT
:
128 case GL_COLOR_ATTACHMENT11_EXT
:
129 case GL_COLOR_ATTACHMENT12_EXT
:
130 case GL_COLOR_ATTACHMENT13_EXT
:
131 case GL_COLOR_ATTACHMENT14_EXT
:
132 case GL_COLOR_ATTACHMENT15_EXT
:
133 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
134 if (i
>= ctx
->Const
.MaxColorAttachments
) {
137 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
138 case GL_DEPTH_ATTACHMENT_EXT
:
139 return &fb
->Attachment
[BUFFER_DEPTH
];
140 case GL_STENCIL_ATTACHMENT_EXT
:
141 return &fb
->Attachment
[BUFFER_STENCIL
];
149 * Remove any texture or renderbuffer attached to the given attachment
150 * point. Update reference counts, etc.
153 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
155 if (att
->Type
== GL_TEXTURE
) {
156 ASSERT(att
->Texture
);
157 if (att
->Renderbuffer
) {
158 /* delete/remove the 'wrapper' renderbuffer */
159 /* XXX do we really want to do this??? */
160 att
->Renderbuffer
->Delete(att
->Renderbuffer
);
161 att
->Renderbuffer
= NULL
;
163 att
->Texture
->RefCount
--;
164 if (att
->Texture
->RefCount
== 0) {
165 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
169 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
170 ASSERT(att
->Renderbuffer
);
171 ASSERT(!att
->Texture
);
172 att
->Renderbuffer
->RefCount
--;
173 if (att
->Renderbuffer
->RefCount
== 0) {
174 att
->Renderbuffer
->Delete(att
->Renderbuffer
);
176 att
->Renderbuffer
= NULL
;
179 att
->Complete
= GL_TRUE
;
184 * Bind a texture object to an attachment point.
185 * The previous binding, if any, will be removed first.
188 _mesa_set_texture_attachment(GLcontext
*ctx
,
189 struct gl_renderbuffer_attachment
*att
,
190 struct gl_texture_object
*texObj
,
191 GLenum texTarget
, GLuint level
, GLuint zoffset
)
193 _mesa_remove_attachment(ctx
, att
);
194 att
->Type
= GL_TEXTURE
;
195 att
->Texture
= texObj
;
196 att
->TextureLevel
= level
;
197 if (IS_CUBE_FACE(texTarget
)) {
198 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
201 att
->CubeMapFace
= 0;
203 att
->Zoffset
= zoffset
;
204 att
->Complete
= GL_FALSE
;
208 /* XXX when we attach to a texture, we should probably set the
209 * att->Renderbuffer pointer to a "wrapper renderbuffer" which
210 * makes the texture image look like renderbuffer.
216 * Bind a renderbuffer to an attachment point.
217 * The previous binding, if any, will be removed first.
220 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
221 struct gl_renderbuffer_attachment
*att
,
222 struct gl_renderbuffer
*rb
)
224 _mesa_remove_attachment(ctx
, att
);
225 att
->Type
= GL_RENDERBUFFER_EXT
;
226 att
->Renderbuffer
= rb
;
227 att
->Texture
= NULL
; /* just to be safe */
228 att
->Complete
= GL_FALSE
;
234 * Fallback for ctx->Driver.FramebufferRenderbuffer()
235 * Sets a framebuffer attachment to a particular renderbuffer.
236 * The framebuffer in question is ctx->DrawBuffer.
237 * \sa _mesa_renderbuffer_texture
240 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
,
241 struct gl_renderbuffer_attachment
*att
,
242 struct gl_renderbuffer
*rb
)
245 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
248 _mesa_remove_attachment(ctx
, att
);
254 * Test if an attachment point is complete and update its Complete field.
255 * \param format if GL_COLOR, this is a color attachment point,
256 * if GL_DEPTH, this is a depth component attachment point,
257 * if GL_STENCIL, this is a stencil component attachment point.
260 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
261 struct gl_renderbuffer_attachment
*att
)
263 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
265 /* assume complete */
266 att
->Complete
= GL_TRUE
;
268 /* Look for reasons why the attachment might be incomplete */
269 if (att
->Type
== GL_TEXTURE
) {
270 const struct gl_texture_object
*texObj
= att
->Texture
;
271 struct gl_texture_image
*texImage
;
274 att
->Complete
= GL_FALSE
;
278 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
280 att
->Complete
= GL_FALSE
;
283 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
284 att
->Complete
= GL_FALSE
;
287 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
288 att
->Complete
= GL_FALSE
;
292 if (format
== GL_COLOR
) {
293 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
294 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
295 att
->Complete
= GL_FALSE
;
299 else if (format
== GL_DEPTH
) {
300 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
303 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
304 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
308 att
->Complete
= GL_FALSE
;
313 /* no such thing as stencil textures */
314 att
->Complete
= GL_FALSE
;
318 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
319 if (att
->Renderbuffer
->Width
< 1 || att
->Renderbuffer
->Height
< 1) {
320 att
->Complete
= GL_FALSE
;
323 if (format
== GL_COLOR
) {
324 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
325 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
326 att
->Complete
= GL_FALSE
;
330 else if (format
== GL_DEPTH
) {
331 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
334 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
335 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
339 att
->Complete
= GL_FALSE
;
344 assert(format
== GL_STENCIL
);
345 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
348 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
349 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
353 att
->Complete
= GL_FALSE
;
359 ASSERT(att
->Type
== GL_NONE
);
367 * Test if the given framebuffer object is complete and update its
368 * Status field with the results.
369 * Also update the framebuffer's Width and Height fields if the
370 * framebuffer is complete.
373 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
375 GLuint numImages
, width
= 0, height
= 0;
376 GLenum intFormat
= GL_NONE
;
380 assert(fb
->Name
!= 0);
386 /* Start at -2 to more easily loop over all attachment points */
387 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
388 struct gl_renderbuffer_attachment
*att
;
392 att
= &fb
->Attachment
[BUFFER_DEPTH
];
393 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
394 if (!att
->Complete
) {
395 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
400 att
= &fb
->Attachment
[BUFFER_STENCIL
];
401 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
402 if (!att
->Complete
) {
403 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
408 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
409 test_attachment_completeness(ctx
, GL_COLOR
, att
);
410 if (!att
->Complete
) {
411 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
416 if (att
->Type
== GL_TEXTURE
) {
417 const struct gl_texture_image
*texImg
418 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
421 f
= texImg
->_BaseFormat
;
423 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
) {
424 /* XXX need GL_DEPTH_STENCIL_EXT test? */
425 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
429 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
430 w
= att
->Renderbuffer
->Width
;
431 h
= att
->Renderbuffer
->Height
;
432 f
= att
->Renderbuffer
->InternalFormat
;
436 assert(att
->Type
== GL_NONE
);
440 if (numImages
== 1) {
441 /* set required width, height and format */
448 /* check that width, height, format are same */
449 if (w
!= width
|| h
!= height
) {
450 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
453 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
454 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
460 /* Check that all DrawBuffers are present */
461 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
462 if (fb
->ColorDrawBuffer
[i
] != GL_NONE
) {
463 const struct gl_renderbuffer_attachment
*att
464 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[i
]);
466 if (att
->Type
== GL_NONE
) {
467 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
473 /* Check that the ReadBuffer is present */
474 if (fb
->ColorReadBuffer
!= GL_NONE
) {
475 const struct gl_renderbuffer_attachment
*att
476 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
478 if (att
->Type
== GL_NONE
) {
479 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
484 /* Check if any renderbuffer is attached more than once.
485 * Note that there's one exception: a GL_DEPTH_STENCIL renderbuffer can be
486 * bound to both the stencil and depth attachment points at the same time.
488 for (i
= 0; i
< BUFFER_COUNT
- 1; i
++) {
489 struct gl_renderbuffer
*rb_i
= fb
->Attachment
[i
].Renderbuffer
;
492 for (j
= i
+ 1; j
< BUFFER_COUNT
; j
++) {
493 struct gl_renderbuffer
*rb_j
= fb
->Attachment
[j
].Renderbuffer
;
494 if (rb_i
== rb_j
&& rb_i
->_BaseFormat
!= GL_DEPTH_STENCIL_EXT
) {
495 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
;
503 if (numImages
== 0) {
504 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
509 * If we get here, the framebuffer is complete!
511 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
518 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
520 GET_CURRENT_CONTEXT(ctx
);
521 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
523 struct gl_renderbuffer
*rb
= lookup_renderbuffer(ctx
, renderbuffer
);
524 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
532 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
534 struct gl_renderbuffer
*newRb
, *oldRb
;
535 GET_CURRENT_CONTEXT(ctx
);
537 ASSERT_OUTSIDE_BEGIN_END(ctx
);
539 if (target
!= GL_RENDERBUFFER_EXT
) {
540 _mesa_error(ctx
, GL_INVALID_ENUM
,
541 "glBindRenderbufferEXT(target)");
545 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
548 newRb
= lookup_renderbuffer(ctx
, renderbuffer
);
549 if (newRb
== &DummyRenderbuffer
) {
550 /* ID was reserved, but no real renderbuffer object made yet */
554 /* create new renderbuffer object */
555 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
557 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
560 ASSERT(newRb
->AllocStorage
);
561 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
569 oldRb
= ctx
->CurrentRenderbuffer
;
572 if (oldRb
->RefCount
== 0) {
573 oldRb
->Delete(oldRb
);
577 ASSERT(newRb
!= &DummyRenderbuffer
);
579 ctx
->CurrentRenderbuffer
= newRb
;
584 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
587 GET_CURRENT_CONTEXT(ctx
);
589 ASSERT_OUTSIDE_BEGIN_END(ctx
);
590 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
592 for (i
= 0; i
< n
; i
++) {
593 if (renderbuffers
[i
] > 0) {
594 struct gl_renderbuffer
*rb
;
595 rb
= lookup_renderbuffer(ctx
, renderbuffers
[i
]);
597 /* check if deleting currently bound renderbuffer object */
598 if (rb
== ctx
->CurrentRenderbuffer
) {
600 ASSERT(rb
->RefCount
>= 2);
601 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
604 /* remove from hash table immediately, to free the ID */
605 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
607 if (rb
!= &DummyRenderbuffer
) {
608 /* But the object will not be freed until it's no longer
609 * bound in any context.
612 if (rb
->RefCount
== 0) {
623 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
625 GET_CURRENT_CONTEXT(ctx
);
629 ASSERT_OUTSIDE_BEGIN_END(ctx
);
632 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
639 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
641 for (i
= 0; i
< n
; i
++) {
642 GLuint name
= first
+ i
;
643 renderbuffers
[i
] = name
;
644 /* insert dummy placeholder into hash table */
645 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
646 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
647 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
653 * Given an internal format token for a render buffer, return the
654 * corresponding base format.
655 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
656 * GL_DEPTH_STENCIL_EXT or zero if error.
659 base_internal_format(GLcontext
*ctx
, GLenum internalFormat
)
661 switch (internalFormat
) {
680 case GL_STENCIL_INDEX
:
681 case GL_STENCIL_INDEX1_EXT
:
682 case GL_STENCIL_INDEX4_EXT
:
683 case GL_STENCIL_INDEX8_EXT
:
684 case GL_STENCIL_INDEX16_EXT
:
685 return GL_STENCIL_INDEX
;
686 case GL_DEPTH_COMPONENT
:
687 case GL_DEPTH_COMPONENT16
:
688 case GL_DEPTH_COMPONENT24
:
689 case GL_DEPTH_COMPONENT32
:
690 return GL_DEPTH_COMPONENT
;
691 case GL_DEPTH_STENCIL_EXT
:
692 case GL_DEPTH24_STENCIL8_EXT
:
693 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
694 return GL_DEPTH_STENCIL_EXT
;
697 /* XXX add floating point formats eventually */
705 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
706 GLsizei width
, GLsizei height
)
708 struct gl_renderbuffer
*rb
;
710 GET_CURRENT_CONTEXT(ctx
);
712 ASSERT_OUTSIDE_BEGIN_END(ctx
);
714 if (target
!= GL_RENDERBUFFER_EXT
) {
715 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
719 baseFormat
= base_internal_format(ctx
, internalFormat
);
720 if (baseFormat
== 0) {
721 _mesa_error(ctx
, GL_INVALID_ENUM
,
722 "glRenderbufferStorageEXT(internalFormat)");
726 if (width
< 1 || width
> ctx
->Const
.MaxRenderbufferSize
) {
727 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
731 if (height
< 1 || height
> ctx
->Const
.MaxRenderbufferSize
) {
732 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
736 rb
= ctx
->CurrentRenderbuffer
;
739 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
743 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
745 /* Now allocate the storage */
746 ASSERT(rb
->AllocStorage
);
747 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
748 /* No error - check/set fields now */
749 assert(rb
->Width
== width
);
750 assert(rb
->Height
== height
);
751 assert(rb
->InternalFormat
);
752 rb
->_BaseFormat
= baseFormat
;
755 /* Probably ran out of memory - clear the fields */
758 rb
->InternalFormat
= GL_NONE
;
759 rb
->_BaseFormat
= GL_NONE
;
763 test_framebuffer_completeness(ctx, fb);
765 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
772 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
774 GET_CURRENT_CONTEXT(ctx
);
776 ASSERT_OUTSIDE_BEGIN_END(ctx
);
778 if (target
!= GL_RENDERBUFFER_EXT
) {
779 _mesa_error(ctx
, GL_INVALID_ENUM
,
780 "glGetRenderbufferParameterivEXT(target)");
784 if (!ctx
->CurrentRenderbuffer
) {
785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
786 "glGetRenderbufferParameterivEXT");
790 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
793 case GL_RENDERBUFFER_WIDTH_EXT
:
794 *params
= ctx
->CurrentRenderbuffer
->Width
;
796 case GL_RENDERBUFFER_HEIGHT_EXT
:
797 *params
= ctx
->CurrentRenderbuffer
->Height
;
799 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
800 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
802 case GL_RENDERBUFFER_RED_SIZE_EXT
:
803 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGB
||
804 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGBA
) {
805 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
811 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
812 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGB
||
813 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGBA
) {
814 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
820 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
821 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGB
||
822 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGBA
) {
823 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
829 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
830 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGB
||
831 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_RGBA
) {
832 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
838 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
839 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
||
840 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
841 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
847 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
848 if (ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
||
849 ctx
->CurrentRenderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
850 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
858 _mesa_error(ctx
, GL_INVALID_ENUM
,
859 "glGetRenderbufferParameterivEXT(target)");
866 _mesa_IsFramebufferEXT(GLuint framebuffer
)
868 GET_CURRENT_CONTEXT(ctx
);
869 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
871 struct gl_framebuffer
*rb
= lookup_framebuffer(ctx
, framebuffer
);
872 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
880 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
882 struct gl_framebuffer
*newFb
, *oldFb
;
883 GLboolean bindReadBuf
, bindDrawBuf
;
884 GET_CURRENT_CONTEXT(ctx
);
886 ASSERT_OUTSIDE_BEGIN_END(ctx
);
889 #if FEATURE_EXT_framebuffer_blit
890 case GL_DRAW_FRAMEBUFFER_EXT
:
891 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
892 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
895 bindDrawBuf
= GL_TRUE
;
896 bindReadBuf
= GL_FALSE
;
898 case GL_READ_FRAMEBUFFER_EXT
:
899 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
903 bindDrawBuf
= GL_FALSE
;
904 bindReadBuf
= GL_TRUE
;
907 case GL_FRAMEBUFFER_EXT
:
908 bindDrawBuf
= GL_TRUE
;
909 bindReadBuf
= GL_TRUE
;
912 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
916 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
919 /* Binding a user-created framebuffer object */
920 newFb
= lookup_framebuffer(ctx
, framebuffer
);
921 if (newFb
== &DummyFramebuffer
) {
922 /* ID was reserved, but no real framebuffer object made yet */
926 /* create new framebuffer object */
927 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
929 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
932 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
940 /* Binding the window system framebuffer (which was originally set
943 newFb
= ctx
->WinSysDrawBuffer
;
946 ASSERT(newFb
!= &DummyFramebuffer
);
949 oldFb
= ctx
->ReadBuffer
;
950 if (oldFb
&& oldFb
->Name
!= 0) {
952 if (oldFb
->RefCount
== 0) {
953 oldFb
->Delete(oldFb
);
956 ctx
->ReadBuffer
= newFb
;
960 oldFb
= ctx
->DrawBuffer
;
961 if (oldFb
&& oldFb
->Name
!= 0) {
963 if (oldFb
->RefCount
== 0) {
964 oldFb
->Delete(oldFb
);
967 ctx
->DrawBuffer
= newFb
;
973 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
976 GET_CURRENT_CONTEXT(ctx
);
978 ASSERT_OUTSIDE_BEGIN_END(ctx
);
979 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
981 for (i
= 0; i
< n
; i
++) {
982 if (framebuffers
[i
] > 0) {
983 struct gl_framebuffer
*fb
;
984 fb
= lookup_framebuffer(ctx
, framebuffers
[i
]);
986 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
988 /* check if deleting currently bound framebuffer object */
989 if (fb
== ctx
->DrawBuffer
) {
991 ASSERT(fb
->RefCount
>= 2);
992 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
995 /* remove from hash table immediately, to free the ID */
996 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
998 if (fb
!= &DummyFramebuffer
) {
999 /* But the object will not be freed until it's no longer
1000 * bound in any context.
1003 if (fb
->RefCount
== 0) {
1014 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1016 GET_CURRENT_CONTEXT(ctx
);
1020 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1023 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1030 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1032 for (i
= 0; i
< n
; i
++) {
1033 GLuint name
= first
+ i
;
1034 framebuffers
[i
] = name
;
1035 /* insert dummy placeholder into hash table */
1036 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1037 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1038 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1045 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1047 struct gl_framebuffer
*buffer
;
1048 GET_CURRENT_CONTEXT(ctx
);
1050 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1053 #if FEATURE_EXT_framebuffer_blit
1054 case GL_DRAW_FRAMEBUFFER_EXT
:
1055 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1056 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1059 buffer
= ctx
->DrawBuffer
;
1061 case GL_READ_FRAMEBUFFER_EXT
:
1062 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1063 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1066 buffer
= ctx
->ReadBuffer
;
1069 case GL_FRAMEBUFFER_EXT
:
1070 buffer
= ctx
->DrawBuffer
;
1073 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1074 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1077 if (buffer
->Name
== 0) {
1078 /* The window system / default framebuffer is always complete */
1079 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1082 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1084 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1085 return buffer
->_Status
;
1091 * Do error checking common to glFramebufferTexture1D/2D/3DEXT.
1092 * \return GL_TRUE if any error, GL_FALSE otherwise
1095 error_check_framebuffer_texture(GLcontext
*ctx
, GLuint dims
,
1096 GLenum target
, GLenum attachment
,
1097 GLenum textarget
, GLuint texture
, GLint level
)
1099 ASSERT(dims
>= 1 && dims
<= 3);
1101 if (target
!= GL_FRAMEBUFFER_EXT
) {
1102 _mesa_error(ctx
, GL_INVALID_ENUM
,
1103 "glFramebufferTexture%dDEXT(target)", dims
);
1107 /* check framebuffer binding */
1108 if (ctx
->DrawBuffer
->Name
== 0) {
1109 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1110 "glFramebufferTexture%dDEXT", dims
);
1114 /* only check textarget, level if texture ID is non-zero */
1116 if ((dims
== 1 && textarget
!= GL_TEXTURE_1D
) ||
1117 (dims
== 3 && textarget
!= GL_TEXTURE_3D
) ||
1118 (dims
== 2 && textarget
!= GL_TEXTURE_2D
&&
1119 textarget
!= GL_TEXTURE_RECTANGLE_ARB
&&
1120 !IS_CUBE_FACE(textarget
))) {
1121 _mesa_error(ctx
, GL_INVALID_VALUE
,
1122 "glFramebufferTexture%dDEXT(textarget)", dims
);
1126 if ((level
< 0) || level
>= _mesa_max_texture_levels(ctx
, textarget
)) {
1127 _mesa_error(ctx
, GL_INVALID_VALUE
,
1128 "glFramebufferTexture%dDEXT(level)", dims
);
1138 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1139 GLenum textarget
, GLuint texture
, GLint level
)
1141 struct gl_renderbuffer_attachment
*att
;
1142 struct gl_texture_object
*texObj
;
1143 GET_CURRENT_CONTEXT(ctx
);
1145 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1147 if (error_check_framebuffer_texture(ctx
, 1, target
, attachment
,
1148 textarget
, texture
, level
))
1151 ASSERT(textarget
== GL_TEXTURE_1D
);
1154 att
= get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1156 _mesa_error(ctx
, GL_INVALID_ENUM
,
1157 "glFramebufferTexture1DEXT(attachment)");
1161 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1164 texObj
= (struct gl_texture_object
*)
1165 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1167 _mesa_error(ctx
, GL_INVALID_VALUE
,
1168 "glFramebufferTexture1DEXT(texture)");
1171 if (texObj
->Target
!= textarget
) {
1172 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1173 "glFramebufferTexture1DEXT(texture target)");
1178 /* remove texture attachment */
1181 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
, level
, 0);
1186 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1187 GLenum textarget
, GLuint texture
, GLint level
)
1189 struct gl_renderbuffer_attachment
*att
;
1190 struct gl_texture_object
*texObj
;
1191 GET_CURRENT_CONTEXT(ctx
);
1193 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1195 if (error_check_framebuffer_texture(ctx
, 2, target
, attachment
,
1196 textarget
, texture
, level
))
1199 ASSERT(textarget
== GL_TEXTURE_2D
||
1200 textarget
== GL_TEXTURE_RECTANGLE_ARB
||
1201 IS_CUBE_FACE(textarget
));
1203 att
= get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1205 _mesa_error(ctx
, GL_INVALID_ENUM
,
1206 "glFramebufferTexture2DEXT(attachment)");
1210 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1213 texObj
= (struct gl_texture_object
*)
1214 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1216 _mesa_error(ctx
, GL_INVALID_VALUE
,
1217 "glFramebufferTexture2DEXT(texture)");
1220 if ((texObj
->Target
== GL_TEXTURE_2D
&& textarget
!= GL_TEXTURE_2D
) ||
1221 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
1222 && textarget
!= GL_TEXTURE_RECTANGLE_ARB
) ||
1223 (texObj
->Target
== GL_TEXTURE_CUBE_MAP
1224 && !IS_CUBE_FACE(textarget
))) {
1225 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1226 "glFramebufferTexture2DEXT(texture target)");
1231 /* remove texture attachment */
1234 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
, level
, 0);
1239 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1240 GLenum textarget
, GLuint texture
,
1241 GLint level
, GLint zoffset
)
1243 struct gl_renderbuffer_attachment
*att
;
1244 struct gl_texture_object
*texObj
;
1245 GET_CURRENT_CONTEXT(ctx
);
1247 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1249 if (error_check_framebuffer_texture(ctx
, 3, target
, attachment
,
1250 textarget
, texture
, level
))
1253 ASSERT(textarget
== GL_TEXTURE_3D
);
1255 att
= get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1257 _mesa_error(ctx
, GL_INVALID_ENUM
,
1258 "glFramebufferTexture1DEXT(attachment)");
1262 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1265 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1266 texObj
= (struct gl_texture_object
*)
1267 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1269 _mesa_error(ctx
, GL_INVALID_VALUE
,
1270 "glFramebufferTexture3DEXT(texture)");
1273 if (texObj
->Target
!= textarget
) {
1274 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1275 "glFramebufferTexture3DEXT(texture target)");
1278 if (zoffset
< 0 || zoffset
>= maxSize
) {
1279 _mesa_error(ctx
, GL_INVALID_VALUE
,
1280 "glFramebufferTexture3DEXT(zoffset)");
1285 /* remove texture attachment */
1288 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
,
1294 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1295 GLenum renderbufferTarget
,
1296 GLuint renderbuffer
)
1298 struct gl_renderbuffer_attachment
*att
;
1299 struct gl_framebuffer
*fb
;
1300 struct gl_renderbuffer
*rb
;
1301 GET_CURRENT_CONTEXT(ctx
);
1303 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1306 #if FEATURE_EXT_framebuffer_blit
1307 case GL_DRAW_FRAMEBUFFER_EXT
:
1308 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1309 _mesa_error(ctx
, GL_INVALID_ENUM
,
1310 "glFramebufferRenderbufferEXT(target)");
1313 fb
= ctx
->DrawBuffer
;
1315 case GL_READ_FRAMEBUFFER_EXT
:
1316 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1317 _mesa_error(ctx
, GL_INVALID_ENUM
,
1318 "glFramebufferRenderbufferEXT(target)");
1321 fb
= ctx
->ReadBuffer
;
1324 case GL_FRAMEBUFFER_EXT
:
1325 fb
= ctx
->DrawBuffer
;
1328 _mesa_error(ctx
, GL_INVALID_ENUM
,
1329 "glFramebufferRenderbufferEXT(target)");
1333 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1334 _mesa_error(ctx
, GL_INVALID_ENUM
,
1335 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1339 if (fb
->Name
== 0) {
1340 /* Can't attach new renderbuffers to a window system framebuffer */
1341 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1345 att
= get_attachment(ctx
, fb
, attachment
);
1347 _mesa_error(ctx
, GL_INVALID_ENUM
,
1348 "glFramebufferRenderbufferEXT(attachment)");
1353 rb
= lookup_renderbuffer(ctx
, renderbuffer
);
1355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1356 "glFramebufferRenderbufferEXT(renderbuffer)");
1361 /* remove renderbuffer attachment */
1365 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1367 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1368 ctx
->Driver
.FramebufferRenderbuffer(ctx
, att
, rb
);
1373 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1374 GLenum pname
, GLint
*params
)
1376 const struct gl_renderbuffer_attachment
*att
;
1377 struct gl_framebuffer
*buffer
;
1378 GET_CURRENT_CONTEXT(ctx
);
1380 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1383 #if FEATURE_EXT_framebuffer_blit
1384 case GL_DRAW_FRAMEBUFFER_EXT
:
1385 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1386 _mesa_error(ctx
, GL_INVALID_ENUM
,
1387 "glGetFramebufferAttachmentParameterivEXT(target)");
1390 buffer
= ctx
->DrawBuffer
;
1392 case GL_READ_FRAMEBUFFER_EXT
:
1393 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1394 _mesa_error(ctx
, GL_INVALID_ENUM
,
1395 "glGetFramebufferAttachmentParameterivEXT(target)");
1398 buffer
= ctx
->ReadBuffer
;
1401 case GL_FRAMEBUFFER_EXT
:
1402 buffer
= ctx
->DrawBuffer
;
1405 _mesa_error(ctx
, GL_INVALID_ENUM
,
1406 "glGetFramebufferAttachmentParameterivEXT(target)");
1410 if (buffer
->Name
== 0) {
1411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1412 "glGetFramebufferAttachmentParameterivEXT");
1416 att
= get_attachment(ctx
, buffer
, attachment
);
1418 _mesa_error(ctx
, GL_INVALID_ENUM
,
1419 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1423 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1426 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1427 *params
= att
->Type
;
1429 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1430 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1431 *params
= att
->Renderbuffer
->Name
;
1433 else if (att
->Type
== GL_TEXTURE
) {
1434 *params
= att
->Texture
->Name
;
1437 _mesa_error(ctx
, GL_INVALID_ENUM
,
1438 "glGetFramebufferAttachmentParameterivEXT(pname)");
1441 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1442 if (att
->Type
== GL_TEXTURE
) {
1443 *params
= att
->TextureLevel
;
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glGetFramebufferAttachmentParameterivEXT(pname)");
1450 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1451 if (att
->Type
== GL_TEXTURE
) {
1452 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1455 _mesa_error(ctx
, GL_INVALID_ENUM
,
1456 "glGetFramebufferAttachmentParameterivEXT(pname)");
1459 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1460 if (att
->Type
== GL_TEXTURE
) {
1461 *params
= att
->Zoffset
;
1464 _mesa_error(ctx
, GL_INVALID_ENUM
,
1465 "glGetFramebufferAttachmentParameterivEXT(pname)");
1469 _mesa_error(ctx
, GL_INVALID_ENUM
,
1470 "glGetFramebufferAttachmentParameterivEXT(pname)");
1477 _mesa_GenerateMipmapEXT(GLenum target
)
1479 struct gl_texture_unit
*texUnit
;
1480 struct gl_texture_object
*texObj
;
1481 GET_CURRENT_CONTEXT(ctx
);
1483 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1484 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1490 case GL_TEXTURE_CUBE_MAP
:
1491 /* OK, legal value */
1494 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1498 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1499 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1501 /* XXX this might not handle cube maps correctly */
1502 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1506 #if FEATURE_EXT_framebuffer_blit
1508 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1509 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1510 GLbitfield mask
, GLenum filter
)
1512 GET_CURRENT_CONTEXT(ctx
);
1514 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1515 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1517 /* check for complete framebuffers */
1518 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1519 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1520 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1521 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1525 /* depth/stencil must be blitted with nearest filtering */
1526 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1527 && filter
!= GL_NEAREST
) {
1528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1529 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1533 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1534 GL_DEPTH_BUFFER_BIT
|
1535 GL_STENCIL_BUFFER_BIT
)) {
1536 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1540 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1541 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1545 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1546 ctx
->Driver
.BlitFramebuffer(ctx
,
1547 srcX0
, srcY0
, srcX1
, srcY1
,
1548 dstX0
, dstY0
, dstX1
, dstY1
,
1551 #endif /* FEATURE_EXT_framebuffer_blit */