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"
36 #include "renderbuffer.h"
45 * None of the GL_EXT_framebuffer_object functions are compiled into
52 * When glGenRender/FramebuffersEXT() is called we insert pointers to
53 * these placeholder objects into the hash table.
54 * Later, when the object ID is first bound, we replace the placeholder
55 * with the real frame/renderbuffer.
57 static struct gl_framebuffer DummyFramebuffer
;
58 static struct gl_renderbuffer DummyRenderbuffer
;
61 #define IS_CUBE_FACE(TARGET) \
62 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
63 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
67 * Helper routine for getting a gl_renderbuffer.
69 static struct gl_renderbuffer
*
70 lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
72 struct gl_renderbuffer
*rb
;
77 rb
= (struct gl_renderbuffer
*)
78 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
84 * Helper routine for getting a gl_framebuffer.
86 static struct gl_framebuffer
*
87 lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
89 struct gl_framebuffer
*fb
;
94 fb
= (struct gl_framebuffer
*)
95 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
101 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
102 * gl_renderbuffer_attachment object.
104 struct gl_renderbuffer_attachment
*
105 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
110 switch (attachment
) {
111 case GL_COLOR_ATTACHMENT0_EXT
:
112 case GL_COLOR_ATTACHMENT1_EXT
:
113 case GL_COLOR_ATTACHMENT2_EXT
:
114 case GL_COLOR_ATTACHMENT3_EXT
:
115 case GL_COLOR_ATTACHMENT4_EXT
:
116 case GL_COLOR_ATTACHMENT5_EXT
:
117 case GL_COLOR_ATTACHMENT6_EXT
:
118 case GL_COLOR_ATTACHMENT7_EXT
:
119 case GL_COLOR_ATTACHMENT8_EXT
:
120 case GL_COLOR_ATTACHMENT9_EXT
:
121 case GL_COLOR_ATTACHMENT10_EXT
:
122 case GL_COLOR_ATTACHMENT11_EXT
:
123 case GL_COLOR_ATTACHMENT12_EXT
:
124 case GL_COLOR_ATTACHMENT13_EXT
:
125 case GL_COLOR_ATTACHMENT14_EXT
:
126 case GL_COLOR_ATTACHMENT15_EXT
:
127 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
128 if (i
>= ctx
->Const
.MaxColorAttachments
) {
131 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
132 case GL_DEPTH_ATTACHMENT_EXT
:
133 return &fb
->Attachment
[BUFFER_DEPTH
];
134 case GL_STENCIL_ATTACHMENT_EXT
:
135 return &fb
->Attachment
[BUFFER_STENCIL
];
143 * Remove any texture or renderbuffer attached to the given attachment
144 * point. Update reference counts, etc.
147 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
149 if (att
->Type
== GL_TEXTURE
) {
150 ASSERT(att
->Texture
);
151 att
->Texture
->RefCount
--;
152 if (att
->Texture
->RefCount
== 0) {
153 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
156 /* tell driver that we're done rendering to this texture. */
157 if (ctx
->Driver
.FinishRenderTexture
) {
158 ctx
->Driver
.FinishRenderTexture(ctx
, att
->Texture
,
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_renderbuffer_attachment
*att
,
186 struct gl_texture_object
*texObj
,
187 GLenum texTarget
, GLuint level
, GLuint zoffset
)
189 if (att
->Texture
== texObj
) {
190 /* re-attaching same texture */
191 ASSERT(att
->Type
== GL_TEXTURE
);
195 _mesa_remove_attachment(ctx
, att
);
196 att
->Type
= GL_TEXTURE
;
197 att
->Texture
= texObj
;
201 /* always update these fields */
202 att
->TextureLevel
= level
;
203 if (IS_CUBE_FACE(texTarget
)) {
204 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
207 att
->CubeMapFace
= 0;
209 att
->Zoffset
= zoffset
;
210 att
->Complete
= GL_FALSE
;
215 * Bind a renderbuffer to an attachment point.
216 * The previous binding, if any, will be removed first.
219 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
220 struct gl_renderbuffer_attachment
*att
,
221 struct gl_renderbuffer
*rb
)
223 _mesa_remove_attachment(ctx
, att
);
224 att
->Type
= GL_RENDERBUFFER_EXT
;
225 att
->Renderbuffer
= rb
;
226 att
->Texture
= NULL
; /* just to be safe */
227 att
->Complete
= GL_FALSE
;
233 * Fallback for ctx->Driver.FramebufferRenderbuffer()
234 * Attach a renderbuffer object to a framebuffer object.
237 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
238 GLenum attachment
, struct gl_renderbuffer
*rb
)
240 struct gl_renderbuffer_attachment
*att
;
242 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
246 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
249 _mesa_remove_attachment(ctx
, att
);
255 * Test if an attachment point is complete and update its Complete field.
256 * \param format if GL_COLOR, this is a color attachment point,
257 * if GL_DEPTH, this is a depth component attachment point,
258 * if GL_STENCIL, this is a stencil component attachment point.
261 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
262 struct gl_renderbuffer_attachment
*att
)
264 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
266 /* assume complete */
267 att
->Complete
= GL_TRUE
;
269 /* Look for reasons why the attachment might be incomplete */
270 if (att
->Type
== GL_TEXTURE
) {
271 const struct gl_texture_object
*texObj
= att
->Texture
;
272 struct gl_texture_image
*texImage
;
275 att
->Complete
= GL_FALSE
;
279 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
281 att
->Complete
= GL_FALSE
;
284 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
285 att
->Complete
= GL_FALSE
;
288 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
289 att
->Complete
= GL_FALSE
;
293 if (format
== GL_COLOR
) {
294 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
295 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
296 att
->Complete
= GL_FALSE
;
300 else if (format
== GL_DEPTH
) {
301 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
304 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
305 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
309 att
->Complete
= GL_FALSE
;
314 /* no such thing as stencil textures */
315 att
->Complete
= GL_FALSE
;
319 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
320 if (att
->Renderbuffer
->Width
< 1 || att
->Renderbuffer
->Height
< 1) {
321 att
->Complete
= GL_FALSE
;
324 if (format
== GL_COLOR
) {
325 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
326 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
327 att
->Complete
= GL_FALSE
;
331 else if (format
== GL_DEPTH
) {
332 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
335 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
336 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
340 att
->Complete
= GL_FALSE
;
345 assert(format
== GL_STENCIL
);
346 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
349 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
350 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
354 att
->Complete
= GL_FALSE
;
360 ASSERT(att
->Type
== GL_NONE
);
368 * Test if the given framebuffer object is complete and update its
369 * Status field with the results.
370 * Also update the framebuffer's Width and Height fields if the
371 * framebuffer is complete.
374 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
376 GLuint numImages
, width
= 0, height
= 0;
377 GLenum intFormat
= GL_NONE
;
381 assert(fb
->Name
!= 0);
387 /* Start at -2 to more easily loop over all attachment points */
388 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
389 struct gl_renderbuffer_attachment
*att
;
393 att
= &fb
->Attachment
[BUFFER_DEPTH
];
394 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
395 if (!att
->Complete
) {
396 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
401 att
= &fb
->Attachment
[BUFFER_STENCIL
];
402 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
403 if (!att
->Complete
) {
404 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
409 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
410 test_attachment_completeness(ctx
, GL_COLOR
, att
);
411 if (!att
->Complete
) {
412 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
417 if (att
->Type
== GL_TEXTURE
) {
418 const struct gl_texture_image
*texImg
419 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
422 f
= texImg
->_BaseFormat
;
424 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
) {
425 /* XXX need GL_DEPTH_STENCIL_EXT test? */
426 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
430 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
431 w
= att
->Renderbuffer
->Width
;
432 h
= att
->Renderbuffer
->Height
;
433 f
= att
->Renderbuffer
->InternalFormat
;
437 assert(att
->Type
== GL_NONE
);
441 if (numImages
== 1) {
442 /* set required width, height and format */
449 /* check that width, height, format are same */
450 if (w
!= width
|| h
!= height
) {
451 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
454 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
455 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
461 /* Check that all DrawBuffers are present */
462 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
463 if (fb
->ColorDrawBuffer
[i
] != GL_NONE
) {
464 const struct gl_renderbuffer_attachment
*att
465 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[i
]);
467 if (att
->Type
== GL_NONE
) {
468 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
474 /* Check that the ReadBuffer is present */
475 if (fb
->ColorReadBuffer
!= GL_NONE
) {
476 const struct gl_renderbuffer_attachment
*att
477 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
479 if (att
->Type
== GL_NONE
) {
480 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
485 /* Check if any renderbuffer is attached more than once.
486 * Note that there's one exception: a GL_DEPTH_STENCIL renderbuffer can be
487 * bound to both the stencil and depth attachment points at the same time.
489 for (i
= 0; i
< BUFFER_COUNT
- 1; i
++) {
490 struct gl_renderbuffer
*rb_i
= fb
->Attachment
[i
].Renderbuffer
;
493 for (j
= i
+ 1; j
< BUFFER_COUNT
; j
++) {
494 struct gl_renderbuffer
*rb_j
= fb
->Attachment
[j
].Renderbuffer
;
495 if (rb_i
== rb_j
&& rb_i
->_BaseFormat
!= GL_DEPTH_STENCIL_EXT
) {
496 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
;
504 if (numImages
== 0) {
505 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
510 * If we get here, the framebuffer is complete!
512 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
519 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
521 GET_CURRENT_CONTEXT(ctx
);
522 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
524 struct gl_renderbuffer
*rb
= lookup_renderbuffer(ctx
, renderbuffer
);
525 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
533 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
535 struct gl_renderbuffer
*newRb
, *oldRb
;
536 GET_CURRENT_CONTEXT(ctx
);
538 ASSERT_OUTSIDE_BEGIN_END(ctx
);
540 if (target
!= GL_RENDERBUFFER_EXT
) {
541 _mesa_error(ctx
, GL_INVALID_ENUM
,
542 "glBindRenderbufferEXT(target)");
546 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
549 newRb
= lookup_renderbuffer(ctx
, renderbuffer
);
550 if (newRb
== &DummyRenderbuffer
) {
551 /* ID was reserved, but no real renderbuffer object made yet */
555 /* create new renderbuffer object */
556 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
558 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
561 ASSERT(newRb
->AllocStorage
);
562 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
570 oldRb
= ctx
->CurrentRenderbuffer
;
573 if (oldRb
->RefCount
== 0) {
574 oldRb
->Delete(oldRb
);
578 ASSERT(newRb
!= &DummyRenderbuffer
);
580 ctx
->CurrentRenderbuffer
= newRb
;
585 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
588 GET_CURRENT_CONTEXT(ctx
);
590 ASSERT_OUTSIDE_BEGIN_END(ctx
);
591 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
593 for (i
= 0; i
< n
; i
++) {
594 if (renderbuffers
[i
] > 0) {
595 struct gl_renderbuffer
*rb
;
596 rb
= lookup_renderbuffer(ctx
, renderbuffers
[i
]);
598 /* check if deleting currently bound renderbuffer object */
599 if (rb
== ctx
->CurrentRenderbuffer
) {
601 ASSERT(rb
->RefCount
>= 2);
602 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
605 /* remove from hash table immediately, to free the ID */
606 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
608 if (rb
!= &DummyRenderbuffer
) {
609 /* But the object will not be freed until it's no longer
610 * bound in any context.
613 if (rb
->RefCount
== 0) {
624 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
626 GET_CURRENT_CONTEXT(ctx
);
630 ASSERT_OUTSIDE_BEGIN_END(ctx
);
633 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
640 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
642 for (i
= 0; i
< n
; i
++) {
643 GLuint name
= first
+ i
;
644 renderbuffers
[i
] = name
;
645 /* insert dummy placeholder into hash table */
646 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
647 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
648 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
654 * Given an internal format token for a render buffer, return the
655 * corresponding base format.
656 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
657 * GL_DEPTH_STENCIL_EXT or zero if error.
660 base_internal_format(GLcontext
*ctx
, GLenum internalFormat
)
662 switch (internalFormat
) {
681 case GL_STENCIL_INDEX
:
682 case GL_STENCIL_INDEX1_EXT
:
683 case GL_STENCIL_INDEX4_EXT
:
684 case GL_STENCIL_INDEX8_EXT
:
685 case GL_STENCIL_INDEX16_EXT
:
686 return GL_STENCIL_INDEX
;
687 case GL_DEPTH_COMPONENT
:
688 case GL_DEPTH_COMPONENT16
:
689 case GL_DEPTH_COMPONENT24
:
690 case GL_DEPTH_COMPONENT32
:
691 return GL_DEPTH_COMPONENT
;
692 case GL_DEPTH_STENCIL_EXT
:
693 case GL_DEPTH24_STENCIL8_EXT
:
694 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
695 return GL_DEPTH_STENCIL_EXT
;
698 /* XXX add floating point formats eventually */
706 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
707 GLsizei width
, GLsizei height
)
709 struct gl_renderbuffer
*rb
;
711 GET_CURRENT_CONTEXT(ctx
);
713 ASSERT_OUTSIDE_BEGIN_END(ctx
);
715 if (target
!= GL_RENDERBUFFER_EXT
) {
716 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
720 baseFormat
= base_internal_format(ctx
, internalFormat
);
721 if (baseFormat
== 0) {
722 _mesa_error(ctx
, GL_INVALID_ENUM
,
723 "glRenderbufferStorageEXT(internalFormat)");
727 if (width
< 1 || width
> ctx
->Const
.MaxRenderbufferSize
) {
728 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
732 if (height
< 1 || height
> ctx
->Const
.MaxRenderbufferSize
) {
733 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
737 rb
= ctx
->CurrentRenderbuffer
;
740 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
744 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
746 if (rb
->InternalFormat
== internalFormat
&&
747 rb
->Width
== width
&&
748 rb
->Height
== height
) {
749 /* no change in allocation needed */
753 /* Now allocate the storage */
754 ASSERT(rb
->AllocStorage
);
755 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
756 /* No error - check/set fields now */
757 assert(rb
->Width
== width
);
758 assert(rb
->Height
== height
);
759 assert(rb
->InternalFormat
);
760 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
761 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
762 rb
->_BaseFormat
= baseFormat
;
765 /* Probably ran out of memory - clear the fields */
768 rb
->InternalFormat
= GL_NONE
;
769 rb
->_BaseFormat
= GL_NONE
;
780 test_framebuffer_completeness(ctx, fb);
782 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
789 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
791 GET_CURRENT_CONTEXT(ctx
);
793 ASSERT_OUTSIDE_BEGIN_END(ctx
);
795 if (target
!= GL_RENDERBUFFER_EXT
) {
796 _mesa_error(ctx
, GL_INVALID_ENUM
,
797 "glGetRenderbufferParameterivEXT(target)");
801 if (!ctx
->CurrentRenderbuffer
) {
802 _mesa_error(ctx
, GL_INVALID_OPERATION
,
803 "glGetRenderbufferParameterivEXT");
807 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
810 case GL_RENDERBUFFER_WIDTH_EXT
:
811 *params
= ctx
->CurrentRenderbuffer
->Width
;
813 case GL_RENDERBUFFER_HEIGHT_EXT
:
814 *params
= ctx
->CurrentRenderbuffer
->Height
;
816 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
817 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
819 case GL_RENDERBUFFER_RED_SIZE_EXT
:
820 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
822 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
823 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
825 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
826 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
828 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
829 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
831 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
832 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
834 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
835 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
838 _mesa_error(ctx
, GL_INVALID_ENUM
,
839 "glGetRenderbufferParameterivEXT(target)");
846 _mesa_IsFramebufferEXT(GLuint framebuffer
)
848 GET_CURRENT_CONTEXT(ctx
);
849 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
851 struct gl_framebuffer
*rb
= lookup_framebuffer(ctx
, framebuffer
);
852 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
860 * Examine all the framebuffer's attachments to see if any are textures.
861 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
862 * notify the device driver that the texture image may have changed.
865 check_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
867 if (ctx
->Driver
.FinishRenderTexture
) {
869 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
870 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
871 struct gl_texture_object
*texObj
= att
->Texture
;
873 ctx
->Driver
.FinishRenderTexture(ctx
, texObj
, att
->CubeMapFace
,
882 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
884 struct gl_framebuffer
*newFb
, *oldFb
;
885 GLboolean bindReadBuf
, bindDrawBuf
;
886 GET_CURRENT_CONTEXT(ctx
);
888 ASSERT_OUTSIDE_BEGIN_END(ctx
);
891 #if FEATURE_EXT_framebuffer_blit
892 case GL_DRAW_FRAMEBUFFER_EXT
:
893 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
894 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
897 bindDrawBuf
= GL_TRUE
;
898 bindReadBuf
= GL_FALSE
;
900 case GL_READ_FRAMEBUFFER_EXT
:
901 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
902 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
905 bindDrawBuf
= GL_FALSE
;
906 bindReadBuf
= GL_TRUE
;
909 case GL_FRAMEBUFFER_EXT
:
910 bindDrawBuf
= GL_TRUE
;
911 bindReadBuf
= GL_TRUE
;
914 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
918 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
921 /* Binding a user-created framebuffer object */
922 newFb
= lookup_framebuffer(ctx
, framebuffer
);
923 if (newFb
== &DummyFramebuffer
) {
924 /* ID was reserved, but no real framebuffer object made yet */
928 /* create new framebuffer object */
929 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
931 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
934 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
942 /* Binding the window system framebuffer (which was originally set
945 newFb
= ctx
->WinSysDrawBuffer
;
948 ASSERT(newFb
!= &DummyFramebuffer
);
951 oldFb
= ctx
->ReadBuffer
;
952 if (oldFb
&& oldFb
->Name
!= 0) {
954 if (oldFb
->RefCount
== 0) {
955 oldFb
->Delete(oldFb
);
958 ctx
->ReadBuffer
= newFb
;
962 oldFb
= ctx
->DrawBuffer
;
963 if (oldFb
&& oldFb
->Name
!= 0) {
964 /* check if old FB had any texture attachments */
965 if (ctx
->Driver
.FinishRenderTexture
) {
966 check_texture_render(ctx
, oldFb
);
968 /* check if time to delete this framebuffer */
970 if (oldFb
->RefCount
== 0) {
971 oldFb
->Delete(oldFb
);
974 ctx
->DrawBuffer
= newFb
;
980 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
983 GET_CURRENT_CONTEXT(ctx
);
985 ASSERT_OUTSIDE_BEGIN_END(ctx
);
986 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
988 for (i
= 0; i
< n
; i
++) {
989 if (framebuffers
[i
] > 0) {
990 struct gl_framebuffer
*fb
;
991 fb
= lookup_framebuffer(ctx
, framebuffers
[i
]);
993 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
995 /* check if deleting currently bound framebuffer object */
996 if (fb
== ctx
->DrawBuffer
) {
998 ASSERT(fb
->RefCount
>= 2);
999 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1002 /* remove from hash table immediately, to free the ID */
1003 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1005 if (fb
!= &DummyFramebuffer
) {
1006 /* But the object will not be freed until it's no longer
1007 * bound in any context.
1010 if (fb
->RefCount
== 0) {
1021 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1023 GET_CURRENT_CONTEXT(ctx
);
1027 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1030 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1037 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1039 for (i
= 0; i
< n
; i
++) {
1040 GLuint name
= first
+ i
;
1041 framebuffers
[i
] = name
;
1042 /* insert dummy placeholder into hash table */
1043 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1044 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1045 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1052 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1054 struct gl_framebuffer
*buffer
;
1055 GET_CURRENT_CONTEXT(ctx
);
1057 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1060 #if FEATURE_EXT_framebuffer_blit
1061 case GL_DRAW_FRAMEBUFFER_EXT
:
1062 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1063 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1066 buffer
= ctx
->DrawBuffer
;
1068 case GL_READ_FRAMEBUFFER_EXT
:
1069 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1070 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1073 buffer
= ctx
->ReadBuffer
;
1076 case GL_FRAMEBUFFER_EXT
:
1077 buffer
= ctx
->DrawBuffer
;
1080 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1081 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1084 if (buffer
->Name
== 0) {
1085 /* The window system / default framebuffer is always complete */
1086 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1089 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1091 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1092 return buffer
->_Status
;
1098 * Do error checking common to glFramebufferTexture1D/2D/3DEXT.
1099 * \return GL_TRUE if any error, GL_FALSE otherwise
1102 error_check_framebuffer_texture(GLcontext
*ctx
, GLuint dims
,
1103 GLenum target
, GLenum attachment
,
1104 GLenum textarget
, GLuint texture
, GLint level
)
1106 ASSERT(dims
>= 1 && dims
<= 3);
1108 if (target
!= GL_FRAMEBUFFER_EXT
) {
1109 _mesa_error(ctx
, GL_INVALID_ENUM
,
1110 "glFramebufferTexture%dDEXT(target)", dims
);
1114 /* check framebuffer binding */
1115 if (ctx
->DrawBuffer
->Name
== 0) {
1116 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1117 "glFramebufferTexture%dDEXT", dims
);
1121 /* only check textarget, level if texture ID is non-zero */
1123 if ((dims
== 1 && textarget
!= GL_TEXTURE_1D
) ||
1124 (dims
== 3 && textarget
!= GL_TEXTURE_3D
) ||
1125 (dims
== 2 && textarget
!= GL_TEXTURE_2D
&&
1126 textarget
!= GL_TEXTURE_RECTANGLE_ARB
&&
1127 !IS_CUBE_FACE(textarget
))) {
1128 _mesa_error(ctx
, GL_INVALID_VALUE
,
1129 "glFramebufferTexture%dDEXT(textarget)", dims
);
1133 if ((level
< 0) || level
>= _mesa_max_texture_levels(ctx
, textarget
)) {
1134 _mesa_error(ctx
, GL_INVALID_VALUE
,
1135 "glFramebufferTexture%dDEXT(level)", dims
);
1145 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1146 GLenum textarget
, GLuint texture
, GLint level
)
1148 struct gl_renderbuffer_attachment
*att
;
1149 struct gl_texture_object
*texObj
;
1150 GET_CURRENT_CONTEXT(ctx
);
1152 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1154 if (error_check_framebuffer_texture(ctx
, 1, target
, attachment
,
1155 textarget
, texture
, level
))
1158 ASSERT(textarget
== GL_TEXTURE_1D
);
1161 att
= _mesa_get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1163 _mesa_error(ctx
, GL_INVALID_ENUM
,
1164 "glFramebufferTexture1DEXT(attachment)");
1168 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1171 texObj
= (struct gl_texture_object
*)
1172 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1174 _mesa_error(ctx
, GL_INVALID_VALUE
,
1175 "glFramebufferTexture1DEXT(texture)");
1178 if (texObj
->Target
!= textarget
) {
1179 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1180 "glFramebufferTexture1DEXT(texture target)");
1185 /* remove texture attachment */
1188 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
, level
, 0);
1193 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1194 GLenum textarget
, GLuint texture
, GLint level
)
1196 struct gl_renderbuffer_attachment
*att
;
1197 struct gl_texture_object
*texObj
;
1198 GET_CURRENT_CONTEXT(ctx
);
1200 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1202 if (error_check_framebuffer_texture(ctx
, 2, target
, attachment
,
1203 textarget
, texture
, level
))
1206 ASSERT(textarget
== GL_TEXTURE_2D
||
1207 textarget
== GL_TEXTURE_RECTANGLE_ARB
||
1208 IS_CUBE_FACE(textarget
));
1210 att
= _mesa_get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1212 _mesa_error(ctx
, GL_INVALID_ENUM
,
1213 "glFramebufferTexture2DEXT(attachment)");
1217 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1220 texObj
= (struct gl_texture_object
*)
1221 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1223 _mesa_error(ctx
, GL_INVALID_VALUE
,
1224 "glFramebufferTexture2DEXT(texture)");
1227 if ((texObj
->Target
== GL_TEXTURE_2D
&& textarget
!= GL_TEXTURE_2D
) ||
1228 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
1229 && textarget
!= GL_TEXTURE_RECTANGLE_ARB
) ||
1230 (texObj
->Target
== GL_TEXTURE_CUBE_MAP
1231 && !IS_CUBE_FACE(textarget
))) {
1232 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1233 "glFramebufferTexture2DEXT(texture target)");
1238 /* remove texture attachment */
1241 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
, level
, 0);
1246 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1247 GLenum textarget
, GLuint texture
,
1248 GLint level
, GLint zoffset
)
1250 struct gl_renderbuffer_attachment
*att
;
1251 struct gl_texture_object
*texObj
;
1252 GET_CURRENT_CONTEXT(ctx
);
1254 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1256 if (error_check_framebuffer_texture(ctx
, 3, target
, attachment
,
1257 textarget
, texture
, level
))
1260 ASSERT(textarget
== GL_TEXTURE_3D
);
1262 att
= _mesa_get_attachment(ctx
, ctx
->DrawBuffer
, attachment
);
1264 _mesa_error(ctx
, GL_INVALID_ENUM
,
1265 "glFramebufferTexture1DEXT(attachment)");
1269 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1272 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1273 texObj
= (struct gl_texture_object
*)
1274 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);
1276 _mesa_error(ctx
, GL_INVALID_VALUE
,
1277 "glFramebufferTexture3DEXT(texture)");
1280 if (texObj
->Target
!= textarget
) {
1281 _mesa_error(ctx
, GL_INVALID_OPERATION
, /* XXX correct error? */
1282 "glFramebufferTexture3DEXT(texture target)");
1285 if (zoffset
< 0 || zoffset
>= maxSize
) {
1286 _mesa_error(ctx
, GL_INVALID_VALUE
,
1287 "glFramebufferTexture3DEXT(zoffset)");
1292 /* remove texture attachment */
1295 ctx
->Driver
.RenderbufferTexture(ctx
, att
, texObj
, textarget
,
1301 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1302 GLenum renderbufferTarget
,
1303 GLuint renderbuffer
)
1305 struct gl_renderbuffer_attachment
*att
;
1306 struct gl_framebuffer
*fb
;
1307 struct gl_renderbuffer
*rb
;
1308 GET_CURRENT_CONTEXT(ctx
);
1310 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1313 #if FEATURE_EXT_framebuffer_blit
1314 case GL_DRAW_FRAMEBUFFER_EXT
:
1315 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1316 _mesa_error(ctx
, GL_INVALID_ENUM
,
1317 "glFramebufferRenderbufferEXT(target)");
1320 fb
= ctx
->DrawBuffer
;
1322 case GL_READ_FRAMEBUFFER_EXT
:
1323 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1324 _mesa_error(ctx
, GL_INVALID_ENUM
,
1325 "glFramebufferRenderbufferEXT(target)");
1328 fb
= ctx
->ReadBuffer
;
1331 case GL_FRAMEBUFFER_EXT
:
1332 fb
= ctx
->DrawBuffer
;
1335 _mesa_error(ctx
, GL_INVALID_ENUM
,
1336 "glFramebufferRenderbufferEXT(target)");
1340 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1341 _mesa_error(ctx
, GL_INVALID_ENUM
,
1342 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1346 if (fb
->Name
== 0) {
1347 /* Can't attach new renderbuffers to a window system framebuffer */
1348 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1352 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1354 _mesa_error(ctx
, GL_INVALID_ENUM
,
1355 "glFramebufferRenderbufferEXT(attachment)");
1360 rb
= lookup_renderbuffer(ctx
, renderbuffer
);
1362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1363 "glFramebufferRenderbufferEXT(renderbuffer)");
1368 /* remove renderbuffer attachment */
1372 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1374 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1375 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1377 /* Some subsequent GL commands may depend on the framebuffer's visual
1378 * after the binding is updated. Update visual info now.
1380 _mesa_update_framebuffer_visual(fb
);
1385 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1386 GLenum pname
, GLint
*params
)
1388 const struct gl_renderbuffer_attachment
*att
;
1389 struct gl_framebuffer
*buffer
;
1390 GET_CURRENT_CONTEXT(ctx
);
1392 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1395 #if FEATURE_EXT_framebuffer_blit
1396 case GL_DRAW_FRAMEBUFFER_EXT
:
1397 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1398 _mesa_error(ctx
, GL_INVALID_ENUM
,
1399 "glGetFramebufferAttachmentParameterivEXT(target)");
1402 buffer
= ctx
->DrawBuffer
;
1404 case GL_READ_FRAMEBUFFER_EXT
:
1405 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1406 _mesa_error(ctx
, GL_INVALID_ENUM
,
1407 "glGetFramebufferAttachmentParameterivEXT(target)");
1410 buffer
= ctx
->ReadBuffer
;
1413 case GL_FRAMEBUFFER_EXT
:
1414 buffer
= ctx
->DrawBuffer
;
1417 _mesa_error(ctx
, GL_INVALID_ENUM
,
1418 "glGetFramebufferAttachmentParameterivEXT(target)");
1422 if (buffer
->Name
== 0) {
1423 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1424 "glGetFramebufferAttachmentParameterivEXT");
1428 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1430 _mesa_error(ctx
, GL_INVALID_ENUM
,
1431 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1435 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1438 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1439 *params
= att
->Type
;
1441 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1442 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1443 *params
= att
->Renderbuffer
->Name
;
1445 else if (att
->Type
== GL_TEXTURE
) {
1446 *params
= att
->Texture
->Name
;
1449 _mesa_error(ctx
, GL_INVALID_ENUM
,
1450 "glGetFramebufferAttachmentParameterivEXT(pname)");
1453 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1454 if (att
->Type
== GL_TEXTURE
) {
1455 *params
= att
->TextureLevel
;
1458 _mesa_error(ctx
, GL_INVALID_ENUM
,
1459 "glGetFramebufferAttachmentParameterivEXT(pname)");
1462 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1463 if (att
->Type
== GL_TEXTURE
) {
1464 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1467 _mesa_error(ctx
, GL_INVALID_ENUM
,
1468 "glGetFramebufferAttachmentParameterivEXT(pname)");
1471 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1472 if (att
->Type
== GL_TEXTURE
) {
1473 *params
= att
->Zoffset
;
1476 _mesa_error(ctx
, GL_INVALID_ENUM
,
1477 "glGetFramebufferAttachmentParameterivEXT(pname)");
1481 _mesa_error(ctx
, GL_INVALID_ENUM
,
1482 "glGetFramebufferAttachmentParameterivEXT(pname)");
1489 _mesa_GenerateMipmapEXT(GLenum target
)
1491 struct gl_texture_unit
*texUnit
;
1492 struct gl_texture_object
*texObj
;
1493 GET_CURRENT_CONTEXT(ctx
);
1495 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1496 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1502 case GL_TEXTURE_CUBE_MAP
:
1503 /* OK, legal value */
1506 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1510 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1511 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1513 /* XXX this might not handle cube maps correctly */
1514 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1518 #if FEATURE_EXT_framebuffer_blit
1520 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1521 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1522 GLbitfield mask
, GLenum filter
)
1524 GET_CURRENT_CONTEXT(ctx
);
1526 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1527 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1529 if (ctx
->NewState
) {
1530 _mesa_update_state(ctx
);
1533 if (!ctx
->ReadBuffer
) {
1537 /* check for complete framebuffers */
1538 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1539 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1540 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1541 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1545 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1546 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1550 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1551 GL_DEPTH_BUFFER_BIT
|
1552 GL_STENCIL_BUFFER_BIT
)) {
1553 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1557 /* depth/stencil must be blitted with nearest filtering */
1558 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1559 && filter
!= GL_NEAREST
) {
1560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1561 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1565 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1566 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1567 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1568 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1570 "glBlitFramebufferEXT(stencil buffer size mismatch");
1575 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1576 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1577 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1578 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1579 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1580 "glBlitFramebufferEXT(depth buffer size mismatch");
1585 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1590 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1591 ctx
->Driver
.BlitFramebuffer(ctx
,
1592 srcX0
, srcY0
, srcX1
, srcY1
,
1593 dstX0
, dstY0
, dstX1
, dstY1
,
1596 #endif /* FEATURE_EXT_framebuffer_blit */