2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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.
35 #include "framebuffer.h"
38 #include "renderbuffer.h"
48 * None of the GL_EXT_framebuffer_object functions are compiled into
55 * When glGenRender/FramebuffersEXT() is called we insert pointers to
56 * these placeholder objects into the hash table.
57 * Later, when the object ID is first bound, we replace the placeholder
58 * with the real frame/renderbuffer.
60 static struct gl_framebuffer DummyFramebuffer
;
61 static struct gl_renderbuffer DummyRenderbuffer
;
64 #define IS_CUBE_FACE(TARGET) \
65 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
66 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
70 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
76 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
83 _mesa_init_fbobjects(GLcontext
*ctx
)
85 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
86 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
91 * Helper routine for getting a gl_renderbuffer.
93 struct gl_renderbuffer
*
94 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
96 struct gl_renderbuffer
*rb
;
101 rb
= (struct gl_renderbuffer
*)
102 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
108 * Helper routine for getting a gl_framebuffer.
110 struct gl_framebuffer
*
111 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
113 struct gl_framebuffer
*fb
;
118 fb
= (struct gl_framebuffer
*)
119 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
125 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
126 * gl_renderbuffer_attachment object.
128 struct gl_renderbuffer_attachment
*
129 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
134 switch (attachment
) {
135 case GL_COLOR_ATTACHMENT0_EXT
:
136 case GL_COLOR_ATTACHMENT1_EXT
:
137 case GL_COLOR_ATTACHMENT2_EXT
:
138 case GL_COLOR_ATTACHMENT3_EXT
:
139 case GL_COLOR_ATTACHMENT4_EXT
:
140 case GL_COLOR_ATTACHMENT5_EXT
:
141 case GL_COLOR_ATTACHMENT6_EXT
:
142 case GL_COLOR_ATTACHMENT7_EXT
:
143 case GL_COLOR_ATTACHMENT8_EXT
:
144 case GL_COLOR_ATTACHMENT9_EXT
:
145 case GL_COLOR_ATTACHMENT10_EXT
:
146 case GL_COLOR_ATTACHMENT11_EXT
:
147 case GL_COLOR_ATTACHMENT12_EXT
:
148 case GL_COLOR_ATTACHMENT13_EXT
:
149 case GL_COLOR_ATTACHMENT14_EXT
:
150 case GL_COLOR_ATTACHMENT15_EXT
:
151 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
152 if (i
>= ctx
->Const
.MaxColorAttachments
) {
155 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
156 case GL_DEPTH_ATTACHMENT_EXT
:
157 return &fb
->Attachment
[BUFFER_DEPTH
];
158 case GL_STENCIL_ATTACHMENT_EXT
:
159 return &fb
->Attachment
[BUFFER_STENCIL
];
167 * Remove any texture or renderbuffer attached to the given attachment
168 * point. Update reference counts, etc.
171 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
173 if (att
->Type
== GL_TEXTURE
) {
174 ASSERT(att
->Texture
);
175 att
->Texture
->RefCount
--;
176 if (att
->Texture
->RefCount
== 0) {
177 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
180 /* tell driver that we're done rendering to this texture. */
181 if (ctx
->Driver
.FinishRenderTexture
) {
182 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
187 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
188 ASSERT(att
->Renderbuffer
);
189 ASSERT(!att
->Texture
);
190 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
193 att
->Complete
= GL_TRUE
;
198 * Bind a texture object to an attachment point.
199 * The previous binding, if any, will be removed first.
202 _mesa_set_texture_attachment(GLcontext
*ctx
,
203 struct gl_framebuffer
*fb
,
204 struct gl_renderbuffer_attachment
*att
,
205 struct gl_texture_object
*texObj
,
206 GLenum texTarget
, GLuint level
, GLuint zoffset
)
208 if (att
->Texture
== texObj
) {
209 /* re-attaching same texture */
210 ASSERT(att
->Type
== GL_TEXTURE
);
214 _mesa_remove_attachment(ctx
, att
);
215 att
->Type
= GL_TEXTURE
;
216 att
->Texture
= texObj
;
220 /* always update these fields */
221 att
->TextureLevel
= level
;
222 if (IS_CUBE_FACE(texTarget
)) {
223 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
226 att
->CubeMapFace
= 0;
228 att
->Zoffset
= zoffset
;
229 att
->Complete
= GL_FALSE
;
231 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
232 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
238 * Bind a renderbuffer to an attachment point.
239 * The previous binding, if any, will be removed first.
242 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
243 struct gl_renderbuffer_attachment
*att
,
244 struct gl_renderbuffer
*rb
)
246 /* XXX check if re-doing same attachment, exit early */
247 _mesa_remove_attachment(ctx
, att
);
248 att
->Type
= GL_RENDERBUFFER_EXT
;
249 att
->Texture
= NULL
; /* just to be safe */
250 att
->Complete
= GL_FALSE
;
251 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
256 * Fallback for ctx->Driver.FramebufferRenderbuffer()
257 * Attach a renderbuffer object to a framebuffer object.
260 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
261 GLenum attachment
, struct gl_renderbuffer
*rb
)
263 struct gl_renderbuffer_attachment
*att
;
265 _glthread_LOCK_MUTEX(fb
->Mutex
);
267 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
270 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
273 _mesa_remove_attachment(ctx
, att
);
276 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
281 * Test if an attachment point is complete and update its Complete field.
282 * \param format if GL_COLOR, this is a color attachment point,
283 * if GL_DEPTH, this is a depth component attachment point,
284 * if GL_STENCIL, this is a stencil component attachment point.
287 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
288 struct gl_renderbuffer_attachment
*att
)
290 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
292 /* assume complete */
293 att
->Complete
= GL_TRUE
;
295 /* Look for reasons why the attachment might be incomplete */
296 if (att
->Type
== GL_TEXTURE
) {
297 const struct gl_texture_object
*texObj
= att
->Texture
;
298 struct gl_texture_image
*texImage
;
301 att
->Complete
= GL_FALSE
;
305 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
307 att
->Complete
= GL_FALSE
;
310 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
311 att
->Complete
= GL_FALSE
;
314 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
315 att
->Complete
= GL_FALSE
;
319 if (format
== GL_COLOR
) {
320 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
321 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
322 att
->Complete
= GL_FALSE
;
326 else if (format
== GL_DEPTH
) {
327 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
330 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
331 texImage
->TexFormat
->BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
335 att
->Complete
= GL_FALSE
;
340 /* no such thing as stencil textures */
341 att
->Complete
= GL_FALSE
;
345 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
346 ASSERT(att
->Renderbuffer
);
347 if (!att
->Renderbuffer
->InternalFormat
||
348 att
->Renderbuffer
->Width
< 1 ||
349 att
->Renderbuffer
->Height
< 1) {
350 att
->Complete
= GL_FALSE
;
353 if (format
== GL_COLOR
) {
354 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
355 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
356 ASSERT(att
->Renderbuffer
->RedBits
);
357 ASSERT(att
->Renderbuffer
->GreenBits
);
358 ASSERT(att
->Renderbuffer
->BlueBits
);
359 att
->Complete
= GL_FALSE
;
363 else if (format
== GL_DEPTH
) {
364 ASSERT(att
->Renderbuffer
->DepthBits
);
365 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
368 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
369 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
373 att
->Complete
= GL_FALSE
;
378 assert(format
== GL_STENCIL
);
379 ASSERT(att
->Renderbuffer
->StencilBits
);
380 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
383 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
384 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
388 att
->Complete
= GL_FALSE
;
394 ASSERT(att
->Type
== GL_NONE
);
402 * Helpful for debugging
405 fbo_incomplete(const char *msg
, int index
)
410 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
416 * Test if the given framebuffer object is complete and update its
417 * Status field with the results.
418 * Also update the framebuffer's Width and Height fields if the
419 * framebuffer is complete.
422 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
424 GLuint numImages
, width
= 0, height
= 0;
425 GLenum intFormat
= GL_NONE
;
430 assert(fb
->Name
!= 0);
436 /* Start at -2 to more easily loop over all attachment points */
437 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
438 struct gl_renderbuffer_attachment
*att
;
442 att
= &fb
->Attachment
[BUFFER_DEPTH
];
443 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
444 if (!att
->Complete
) {
445 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
446 fbo_incomplete("depth attachment incomplete", -1);
451 att
= &fb
->Attachment
[BUFFER_STENCIL
];
452 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
453 if (!att
->Complete
) {
454 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
455 fbo_incomplete("stencil attachment incomplete", -1);
460 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
461 test_attachment_completeness(ctx
, GL_COLOR
, att
);
462 if (!att
->Complete
) {
463 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
464 fbo_incomplete("color attachment incomplete", i
);
469 if (att
->Type
== GL_TEXTURE
) {
470 const struct gl_texture_image
*texImg
471 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
474 f
= texImg
->_BaseFormat
;
476 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
477 && f
!= GL_DEPTH_STENCIL_EXT
) {
478 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
479 fbo_incomplete("texture attachment incomplete", -1);
483 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
484 w
= att
->Renderbuffer
->Width
;
485 h
= att
->Renderbuffer
->Height
;
486 f
= att
->Renderbuffer
->InternalFormat
;
490 assert(att
->Type
== GL_NONE
);
494 if (numImages
== 1) {
495 /* set required width, height and format */
502 /* check that width, height, format are same */
503 if (w
!= width
|| h
!= height
) {
504 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
505 fbo_incomplete("width or height mismatch", -1);
508 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
509 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
510 fbo_incomplete("format mismatch", -1);
516 /* Check that all DrawBuffers are present */
517 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
518 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
519 const struct gl_renderbuffer_attachment
*att
520 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
522 if (att
->Type
== GL_NONE
) {
523 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
524 fbo_incomplete("missing drawbuffer", j
);
530 /* Check that the ReadBuffer is present */
531 if (fb
->ColorReadBuffer
!= GL_NONE
) {
532 const struct gl_renderbuffer_attachment
*att
533 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
535 if (att
->Type
== GL_NONE
) {
536 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
537 fbo_incomplete("missing readbuffer", -1);
542 if (numImages
== 0) {
543 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
544 fbo_incomplete("no attachments", -1);
549 * If we get here, the framebuffer is complete!
551 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
558 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
560 GET_CURRENT_CONTEXT(ctx
);
561 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
563 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
564 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
572 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
574 struct gl_renderbuffer
*newRb
;
575 GET_CURRENT_CONTEXT(ctx
);
577 ASSERT_OUTSIDE_BEGIN_END(ctx
);
579 if (target
!= GL_RENDERBUFFER_EXT
) {
580 _mesa_error(ctx
, GL_INVALID_ENUM
,
581 "glBindRenderbufferEXT(target)");
585 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
586 /* The above doesn't fully flush the drivers in the way that a
587 * glFlush does, but that is required here:
589 if (ctx
->Driver
.Flush
)
590 ctx
->Driver
.Flush(ctx
);
594 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
595 if (newRb
== &DummyRenderbuffer
) {
596 /* ID was reserved, but no real renderbuffer object made yet */
600 /* create new renderbuffer object */
601 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
603 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
606 ASSERT(newRb
->AllocStorage
);
607 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
608 newRb
->RefCount
= 1; /* referenced by hash table */
615 ASSERT(newRb
!= &DummyRenderbuffer
);
617 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
622 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
625 GET_CURRENT_CONTEXT(ctx
);
627 ASSERT_OUTSIDE_BEGIN_END(ctx
);
628 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
630 for (i
= 0; i
< n
; i
++) {
631 if (renderbuffers
[i
] > 0) {
632 struct gl_renderbuffer
*rb
;
633 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
635 /* check if deleting currently bound renderbuffer object */
636 if (rb
== ctx
->CurrentRenderbuffer
) {
638 ASSERT(rb
->RefCount
>= 2);
639 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
642 /* Remove from hash table immediately, to free the ID.
643 * But the object will not be freed until it's no longer
644 * referenced anywhere else.
646 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
648 if (rb
!= &DummyRenderbuffer
) {
649 /* no longer referenced by hash table */
650 _mesa_reference_renderbuffer(&rb
, NULL
);
659 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
661 GET_CURRENT_CONTEXT(ctx
);
665 ASSERT_OUTSIDE_BEGIN_END(ctx
);
668 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
675 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
677 for (i
= 0; i
< n
; i
++) {
678 GLuint name
= first
+ i
;
679 renderbuffers
[i
] = name
;
680 /* insert dummy placeholder into hash table */
681 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
682 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
683 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
689 * Given an internal format token for a render buffer, return the
690 * corresponding base format.
691 * This is very similar to _mesa_base_tex_format() but the set of valid
692 * internal formats is somewhat different.
694 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
695 * GL_DEPTH_STENCIL_EXT or zero if error.
698 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
700 switch (internalFormat
) {
719 case GL_STENCIL_INDEX
:
720 case GL_STENCIL_INDEX1_EXT
:
721 case GL_STENCIL_INDEX4_EXT
:
722 case GL_STENCIL_INDEX8_EXT
:
723 case GL_STENCIL_INDEX16_EXT
:
724 return GL_STENCIL_INDEX
;
725 case GL_DEPTH_COMPONENT
:
726 case GL_DEPTH_COMPONENT16
:
727 case GL_DEPTH_COMPONENT24
:
728 case GL_DEPTH_COMPONENT32
:
729 return GL_DEPTH_COMPONENT
;
730 case GL_DEPTH_STENCIL_EXT
:
731 case GL_DEPTH24_STENCIL8_EXT
:
732 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
733 return GL_DEPTH_STENCIL_EXT
;
736 /* XXX add floating point formats eventually */
744 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
745 GLsizei width
, GLsizei height
)
747 struct gl_renderbuffer
*rb
;
749 GET_CURRENT_CONTEXT(ctx
);
751 ASSERT_OUTSIDE_BEGIN_END(ctx
);
753 if (target
!= GL_RENDERBUFFER_EXT
) {
754 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
758 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
759 if (baseFormat
== 0) {
760 _mesa_error(ctx
, GL_INVALID_ENUM
,
761 "glRenderbufferStorageEXT(internalFormat)");
765 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
766 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
770 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
771 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
775 rb
= ctx
->CurrentRenderbuffer
;
778 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
782 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
784 if (rb
->InternalFormat
== internalFormat
&&
785 rb
->Width
== (GLuint
) width
&&
786 rb
->Height
== (GLuint
) height
) {
787 /* no change in allocation needed */
791 /* These MUST get set by the AllocStorage func */
792 rb
->_ActualFormat
= 0;
801 /* Now allocate the storage */
802 ASSERT(rb
->AllocStorage
);
803 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
804 /* No error - check/set fields now */
805 assert(rb
->_ActualFormat
);
806 assert(rb
->Width
== (GLuint
) width
);
807 assert(rb
->Height
== (GLuint
) height
);
808 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
809 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
810 rb
->InternalFormat
= internalFormat
;
811 rb
->_BaseFormat
= baseFormat
;
814 /* Probably ran out of memory - clear the fields */
817 rb
->InternalFormat
= GL_NONE
;
818 rb
->_ActualFormat
= GL_NONE
;
819 rb
->_BaseFormat
= GL_NONE
;
830 test_framebuffer_completeness(ctx, fb);
832 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
839 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
841 GET_CURRENT_CONTEXT(ctx
);
843 ASSERT_OUTSIDE_BEGIN_END(ctx
);
845 if (target
!= GL_RENDERBUFFER_EXT
) {
846 _mesa_error(ctx
, GL_INVALID_ENUM
,
847 "glGetRenderbufferParameterivEXT(target)");
851 if (!ctx
->CurrentRenderbuffer
) {
852 _mesa_error(ctx
, GL_INVALID_OPERATION
,
853 "glGetRenderbufferParameterivEXT");
857 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
860 case GL_RENDERBUFFER_WIDTH_EXT
:
861 *params
= ctx
->CurrentRenderbuffer
->Width
;
863 case GL_RENDERBUFFER_HEIGHT_EXT
:
864 *params
= ctx
->CurrentRenderbuffer
->Height
;
866 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
867 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
869 case GL_RENDERBUFFER_RED_SIZE_EXT
:
870 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
872 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
873 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
875 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
876 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
878 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
879 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
881 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
882 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
884 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
885 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
888 _mesa_error(ctx
, GL_INVALID_ENUM
,
889 "glGetRenderbufferParameterivEXT(target)");
896 _mesa_IsFramebufferEXT(GLuint framebuffer
)
898 GET_CURRENT_CONTEXT(ctx
);
899 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
901 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
902 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
910 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
913 ASSERT(ctx
->Driver
.RenderTexture
);
914 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
915 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
916 struct gl_texture_object
*texObj
= att
->Texture
;
918 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
919 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
926 * Examine all the framebuffer's attachments to see if any are textures.
927 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
928 * notify the device driver that the texture image may have changed.
931 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
933 if (ctx
->Driver
.FinishRenderTexture
) {
935 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
936 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
937 if (att
->Texture
&& att
->Renderbuffer
) {
938 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
946 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
948 struct gl_framebuffer
*newFb
, *newFbread
;
949 GLboolean bindReadBuf
, bindDrawBuf
;
950 GET_CURRENT_CONTEXT(ctx
);
952 ASSERT_OUTSIDE_BEGIN_END(ctx
);
954 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
955 _mesa_error(ctx
, GL_INVALID_OPERATION
,
956 "glBindFramebufferEXT(unsupported)");
961 #if FEATURE_EXT_framebuffer_blit
962 case GL_DRAW_FRAMEBUFFER_EXT
:
963 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
964 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
967 bindDrawBuf
= GL_TRUE
;
968 bindReadBuf
= GL_FALSE
;
970 case GL_READ_FRAMEBUFFER_EXT
:
971 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
972 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
975 bindDrawBuf
= GL_FALSE
;
976 bindReadBuf
= GL_TRUE
;
979 case GL_FRAMEBUFFER_EXT
:
980 bindDrawBuf
= GL_TRUE
;
981 bindReadBuf
= GL_TRUE
;
984 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
988 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
989 if (ctx
->Driver
.Flush
) {
990 ctx
->Driver
.Flush(ctx
);
993 /* Binding a user-created framebuffer object */
994 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
995 if (newFb
== &DummyFramebuffer
) {
996 /* ID was reserved, but no real framebuffer object made yet */
1000 /* create new framebuffer object */
1001 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1003 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1006 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
1011 /* Binding the window system framebuffer (which was originally set
1012 * with MakeCurrent).
1014 newFb
= ctx
->WinSysDrawBuffer
;
1015 newFbread
= ctx
->WinSysReadBuffer
;
1019 ASSERT(newFb
!= &DummyFramebuffer
);
1022 * XXX check if re-binding same buffer and skip some of this code.
1025 /* for window-framebuffers, re-initialize the fbo values, as they
1026 could be wrong (makecurrent with a new drawable while still a fbo
1027 was bound will lead to default init fbo values).
1028 note that therefore the context ReadBuffer/DrawBuffer values are not
1029 valid while fbo's are bound!!! */
1031 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1032 if (!newFbread
->Name
) {
1033 _mesa_readbuffer_update_fields(ctx
, ctx
->Pixel
.ReadBuffer
);
1038 /* check if old FB had any texture attachments */
1039 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1040 /* check if time to delete this framebuffer */
1041 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1044 GLenum buffers
[MAX_DRAW_BUFFERS
];
1045 for(i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1046 buffers
[i
] = ctx
->Color
.DrawBuffer
[i
];
1048 _mesa_drawbuffers(ctx
, ctx
->Const
.MaxDrawBuffers
, buffers
, NULL
);
1051 /* check if newly bound framebuffer has any texture attachments */
1052 check_begin_texture_render(ctx
, newFb
);
1056 if (ctx
->Driver
.BindFramebuffer
) {
1057 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1063 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1066 GET_CURRENT_CONTEXT(ctx
);
1068 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1069 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1070 /* The above doesn't fully flush the drivers in the way that a
1071 * glFlush does, but that is required here:
1073 if (ctx
->Driver
.Flush
)
1074 ctx
->Driver
.Flush(ctx
);
1076 for (i
= 0; i
< n
; i
++) {
1077 if (framebuffers
[i
] > 0) {
1078 struct gl_framebuffer
*fb
;
1079 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1081 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1083 /* check if deleting currently bound framebuffer object */
1084 if (fb
== ctx
->DrawBuffer
) {
1086 ASSERT(fb
->RefCount
>= 2);
1087 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1090 /* remove from hash table immediately, to free the ID */
1091 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1093 if (fb
!= &DummyFramebuffer
) {
1094 /* But the object will not be freed until it's no longer
1095 * bound in any context.
1097 _mesa_unreference_framebuffer(&fb
);
1106 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1108 GET_CURRENT_CONTEXT(ctx
);
1112 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1115 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1122 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1124 for (i
= 0; i
< n
; i
++) {
1125 GLuint name
= first
+ i
;
1126 framebuffers
[i
] = name
;
1127 /* insert dummy placeholder into hash table */
1128 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1129 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1130 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1137 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1139 struct gl_framebuffer
*buffer
;
1140 GET_CURRENT_CONTEXT(ctx
);
1142 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1145 #if FEATURE_EXT_framebuffer_blit
1146 case GL_DRAW_FRAMEBUFFER_EXT
:
1147 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1148 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1151 buffer
= ctx
->DrawBuffer
;
1153 case GL_READ_FRAMEBUFFER_EXT
:
1154 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1155 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1158 buffer
= ctx
->ReadBuffer
;
1161 case GL_FRAMEBUFFER_EXT
:
1162 buffer
= ctx
->DrawBuffer
;
1165 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1166 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1169 if (buffer
->Name
== 0) {
1170 /* The window system / default framebuffer is always complete */
1171 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1174 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1176 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1177 return buffer
->_Status
;
1183 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1186 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1187 GLenum attachment
, GLenum textarget
, GLuint texture
,
1188 GLint level
, GLint zoffset
)
1190 struct gl_renderbuffer_attachment
*att
;
1191 struct gl_texture_object
*texObj
= NULL
;
1192 struct gl_framebuffer
*fb
;
1194 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1196 if (target
!= GL_FRAMEBUFFER_EXT
) {
1197 _mesa_error(ctx
, GL_INVALID_ENUM
,
1198 "glFramebufferTexture%sEXT(target)", caller
);
1202 fb
= ctx
->DrawBuffer
;
1205 /* check framebuffer binding */
1206 if (fb
->Name
== 0) {
1207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1208 "glFramebufferTexture%sEXT", caller
);
1213 /* The textarget, level, and zoffset parameters are only validated if
1214 * texture is non-zero.
1217 GLboolean err
= GL_TRUE
;
1219 texObj
= _mesa_lookup_texture(ctx
, texture
);
1220 if (texObj
!= NULL
) {
1221 if (textarget
== 0) {
1222 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1223 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1224 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1227 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1228 ? !IS_CUBE_FACE(textarget
)
1229 : (texObj
->Target
!= textarget
);
1234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1235 "glFramebufferTexture%sEXT(texture target mismatch)",
1240 if (texObj
->Target
== GL_TEXTURE_3D
) {
1241 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1242 if (zoffset
< 0 || zoffset
>= maxSize
) {
1243 _mesa_error(ctx
, GL_INVALID_VALUE
,
1244 "glFramebufferTexture%sEXT(zoffset)", caller
);
1248 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1249 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1250 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1251 _mesa_error(ctx
, GL_INVALID_VALUE
,
1252 "glFramebufferTexture%sEXT(layer)", caller
);
1259 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1260 _mesa_error(ctx
, GL_INVALID_VALUE
,
1261 "glFramebufferTexture%sEXT(level)", caller
);
1266 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1268 _mesa_error(ctx
, GL_INVALID_ENUM
,
1269 "glFramebufferTexture%sEXT(attachment)", caller
);
1273 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1274 /* The above doesn't fully flush the drivers in the way that a
1275 * glFlush does, but that is required here:
1277 if (ctx
->Driver
.Flush
)
1278 ctx
->Driver
.Flush(ctx
);
1280 _glthread_LOCK_MUTEX(fb
->Mutex
);
1282 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1286 _mesa_remove_attachment(ctx
, att
);
1288 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1294 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1295 GLenum textarget
, GLuint texture
, GLint level
)
1297 GET_CURRENT_CONTEXT(ctx
);
1299 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1300 _mesa_error(ctx
, GL_INVALID_ENUM
,
1301 "glFramebufferTexture1DEXT(textarget)");
1305 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1311 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1312 GLenum textarget
, GLuint texture
, GLint level
)
1314 GET_CURRENT_CONTEXT(ctx
);
1316 if ((texture
!= 0) &&
1317 (textarget
!= GL_TEXTURE_2D
) &&
1318 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1319 (!IS_CUBE_FACE(textarget
))) {
1320 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1321 "glFramebufferTexture2DEXT(textarget)");
1325 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1331 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1332 GLenum textarget
, GLuint texture
,
1333 GLint level
, GLint zoffset
)
1335 GET_CURRENT_CONTEXT(ctx
);
1337 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1338 _mesa_error(ctx
, GL_INVALID_ENUM
,
1339 "glFramebufferTexture3DEXT(textarget)");
1343 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1349 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1350 GLuint texture
, GLint level
, GLint layer
)
1352 GET_CURRENT_CONTEXT(ctx
);
1354 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1360 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1361 GLenum renderbufferTarget
,
1362 GLuint renderbuffer
)
1364 struct gl_renderbuffer_attachment
*att
;
1365 struct gl_framebuffer
*fb
;
1366 struct gl_renderbuffer
*rb
;
1367 GET_CURRENT_CONTEXT(ctx
);
1369 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1372 #if FEATURE_EXT_framebuffer_blit
1373 case GL_DRAW_FRAMEBUFFER_EXT
:
1374 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1375 _mesa_error(ctx
, GL_INVALID_ENUM
,
1376 "glFramebufferRenderbufferEXT(target)");
1379 fb
= ctx
->DrawBuffer
;
1381 case GL_READ_FRAMEBUFFER_EXT
:
1382 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1383 _mesa_error(ctx
, GL_INVALID_ENUM
,
1384 "glFramebufferRenderbufferEXT(target)");
1387 fb
= ctx
->ReadBuffer
;
1390 case GL_FRAMEBUFFER_EXT
:
1391 fb
= ctx
->DrawBuffer
;
1394 _mesa_error(ctx
, GL_INVALID_ENUM
,
1395 "glFramebufferRenderbufferEXT(target)");
1399 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1400 _mesa_error(ctx
, GL_INVALID_ENUM
,
1401 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1405 if (fb
->Name
== 0) {
1406 /* Can't attach new renderbuffers to a window system framebuffer */
1407 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1411 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1413 _mesa_error(ctx
, GL_INVALID_ENUM
,
1414 "glFramebufferRenderbufferEXT(attachment)");
1419 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1421 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1422 "glFramebufferRenderbufferEXT(renderbuffer)");
1427 /* remove renderbuffer attachment */
1431 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1432 /* The above doesn't fully flush the drivers in the way that a
1433 * glFlush does, but that is required here:
1435 if (ctx
->Driver
.Flush
)
1436 ctx
->Driver
.Flush(ctx
);
1438 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1439 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1441 /* Some subsequent GL commands may depend on the framebuffer's visual
1442 * after the binding is updated. Update visual info now.
1444 _mesa_update_framebuffer_visual(fb
);
1449 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1450 GLenum pname
, GLint
*params
)
1452 const struct gl_renderbuffer_attachment
*att
;
1453 struct gl_framebuffer
*buffer
;
1454 GET_CURRENT_CONTEXT(ctx
);
1456 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1459 #if FEATURE_EXT_framebuffer_blit
1460 case GL_DRAW_FRAMEBUFFER_EXT
:
1461 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1462 _mesa_error(ctx
, GL_INVALID_ENUM
,
1463 "glGetFramebufferAttachmentParameterivEXT(target)");
1466 buffer
= ctx
->DrawBuffer
;
1468 case GL_READ_FRAMEBUFFER_EXT
:
1469 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1470 _mesa_error(ctx
, GL_INVALID_ENUM
,
1471 "glGetFramebufferAttachmentParameterivEXT(target)");
1474 buffer
= ctx
->ReadBuffer
;
1477 case GL_FRAMEBUFFER_EXT
:
1478 buffer
= ctx
->DrawBuffer
;
1481 _mesa_error(ctx
, GL_INVALID_ENUM
,
1482 "glGetFramebufferAttachmentParameterivEXT(target)");
1486 if (buffer
->Name
== 0) {
1487 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1488 "glGetFramebufferAttachmentParameterivEXT");
1492 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1494 _mesa_error(ctx
, GL_INVALID_ENUM
,
1495 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1499 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1500 /* The above doesn't fully flush the drivers in the way that a
1501 * glFlush does, but that is required here:
1503 if (ctx
->Driver
.Flush
)
1504 ctx
->Driver
.Flush(ctx
);
1507 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1508 *params
= att
->Type
;
1510 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1511 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1512 *params
= att
->Renderbuffer
->Name
;
1514 else if (att
->Type
== GL_TEXTURE
) {
1515 *params
= att
->Texture
->Name
;
1518 _mesa_error(ctx
, GL_INVALID_ENUM
,
1519 "glGetFramebufferAttachmentParameterivEXT(pname)");
1522 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1523 if (att
->Type
== GL_TEXTURE
) {
1524 *params
= att
->TextureLevel
;
1527 _mesa_error(ctx
, GL_INVALID_ENUM
,
1528 "glGetFramebufferAttachmentParameterivEXT(pname)");
1531 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1532 if (att
->Type
== GL_TEXTURE
) {
1533 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1536 _mesa_error(ctx
, GL_INVALID_ENUM
,
1537 "glGetFramebufferAttachmentParameterivEXT(pname)");
1540 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1541 if (att
->Type
== GL_TEXTURE
) {
1542 *params
= att
->Zoffset
;
1545 _mesa_error(ctx
, GL_INVALID_ENUM
,
1546 "glGetFramebufferAttachmentParameterivEXT(pname)");
1550 _mesa_error(ctx
, GL_INVALID_ENUM
,
1551 "glGetFramebufferAttachmentParameterivEXT(pname)");
1558 _mesa_GenerateMipmapEXT(GLenum target
)
1560 struct gl_texture_unit
*texUnit
;
1561 struct gl_texture_object
*texObj
;
1562 GET_CURRENT_CONTEXT(ctx
);
1564 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1565 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1571 case GL_TEXTURE_CUBE_MAP
:
1572 /* OK, legal value */
1575 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1579 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1580 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1582 /* XXX this might not handle cube maps correctly */
1583 _mesa_lock_texture(ctx
, texObj
);
1584 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
1585 _mesa_unlock_texture(ctx
, texObj
);
1589 #if FEATURE_EXT_framebuffer_blit
1591 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1592 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1593 GLbitfield mask
, GLenum filter
)
1595 GET_CURRENT_CONTEXT(ctx
);
1597 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1598 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1600 if (ctx
->NewState
) {
1601 _mesa_update_state(ctx
);
1604 if (!ctx
->ReadBuffer
) {
1608 /* check for complete framebuffers */
1609 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1610 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1611 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1612 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1616 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1617 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1621 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1622 GL_DEPTH_BUFFER_BIT
|
1623 GL_STENCIL_BUFFER_BIT
)) {
1624 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1628 /* depth/stencil must be blitted with nearest filtering */
1629 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1630 && filter
!= GL_NEAREST
) {
1631 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1632 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1636 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1637 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1638 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1639 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1640 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1641 "glBlitFramebufferEXT(stencil buffer size mismatch");
1646 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1647 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1648 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1649 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1650 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1651 "glBlitFramebufferEXT(depth buffer size mismatch");
1656 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1657 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1661 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1662 ctx
->Driver
.BlitFramebuffer(ctx
,
1663 srcX0
, srcY0
, srcX1
, srcY1
,
1664 dstX0
, dstY0
, dstX1
, dstY1
,
1667 #endif /* FEATURE_EXT_framebuffer_blit */