2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
38 #include "framebuffer.h"
42 #include "renderbuffer.h"
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 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
80 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
87 _mesa_init_fbobjects(GLcontext
*ctx
)
89 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
90 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
95 * Helper routine for getting a gl_renderbuffer.
97 struct gl_renderbuffer
*
98 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
100 struct gl_renderbuffer
*rb
;
105 rb
= (struct gl_renderbuffer
*)
106 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
112 * Helper routine for getting a gl_framebuffer.
114 struct gl_framebuffer
*
115 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
117 struct gl_framebuffer
*fb
;
122 fb
= (struct gl_framebuffer
*)
123 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
129 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
130 * gl_renderbuffer_attachment object.
132 struct gl_renderbuffer_attachment
*
133 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
138 switch (attachment
) {
139 case GL_COLOR_ATTACHMENT0_EXT
:
140 case GL_COLOR_ATTACHMENT1_EXT
:
141 case GL_COLOR_ATTACHMENT2_EXT
:
142 case GL_COLOR_ATTACHMENT3_EXT
:
143 case GL_COLOR_ATTACHMENT4_EXT
:
144 case GL_COLOR_ATTACHMENT5_EXT
:
145 case GL_COLOR_ATTACHMENT6_EXT
:
146 case GL_COLOR_ATTACHMENT7_EXT
:
147 case GL_COLOR_ATTACHMENT8_EXT
:
148 case GL_COLOR_ATTACHMENT9_EXT
:
149 case GL_COLOR_ATTACHMENT10_EXT
:
150 case GL_COLOR_ATTACHMENT11_EXT
:
151 case GL_COLOR_ATTACHMENT12_EXT
:
152 case GL_COLOR_ATTACHMENT13_EXT
:
153 case GL_COLOR_ATTACHMENT14_EXT
:
154 case GL_COLOR_ATTACHMENT15_EXT
:
155 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
156 if (i
>= ctx
->Const
.MaxColorAttachments
) {
159 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
160 case GL_DEPTH_ATTACHMENT_EXT
:
161 return &fb
->Attachment
[BUFFER_DEPTH
];
162 case GL_STENCIL_ATTACHMENT_EXT
:
163 return &fb
->Attachment
[BUFFER_STENCIL
];
171 * Remove any texture or renderbuffer attached to the given attachment
172 * point. Update reference counts, etc.
175 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
177 if (att
->Type
== GL_TEXTURE
) {
178 ASSERT(att
->Texture
);
179 if (ctx
->Driver
.FinishRenderTexture
) {
180 /* tell driver we're done rendering to this texobj */
181 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
183 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
184 ASSERT(!att
->Texture
);
186 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
187 ASSERT(!att
->Texture
);
188 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
189 ASSERT(!att
->Renderbuffer
);
192 att
->Complete
= GL_TRUE
;
197 * Bind a texture object to an attachment point.
198 * The previous binding, if any, will be removed first.
201 _mesa_set_texture_attachment(GLcontext
*ctx
,
202 struct gl_framebuffer
*fb
,
203 struct gl_renderbuffer_attachment
*att
,
204 struct gl_texture_object
*texObj
,
205 GLenum texTarget
, GLuint level
, GLuint zoffset
)
207 if (att
->Texture
== texObj
) {
208 /* re-attaching same texture */
209 ASSERT(att
->Type
== GL_TEXTURE
);
213 _mesa_remove_attachment(ctx
, att
);
214 att
->Type
= GL_TEXTURE
;
215 assert(!att
->Texture
);
216 _mesa_reference_texobj(&att
->Texture
, texObj
);
219 /* always update these fields */
220 att
->TextureLevel
= level
;
221 if (IS_CUBE_FACE(texTarget
)) {
222 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
225 att
->CubeMapFace
= 0;
227 att
->Zoffset
= zoffset
;
228 att
->Complete
= GL_FALSE
;
230 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
231 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
237 * Bind a renderbuffer to an attachment point.
238 * The previous binding, if any, will be removed first.
241 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
242 struct gl_renderbuffer_attachment
*att
,
243 struct gl_renderbuffer
*rb
)
245 /* XXX check if re-doing same attachment, exit early */
246 _mesa_remove_attachment(ctx
, att
);
247 att
->Type
= GL_RENDERBUFFER_EXT
;
248 att
->Texture
= NULL
; /* just to be safe */
249 att
->Complete
= GL_FALSE
;
250 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
255 * Fallback for ctx->Driver.FramebufferRenderbuffer()
256 * Attach a renderbuffer object to a framebuffer object.
259 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
260 GLenum attachment
, struct gl_renderbuffer
*rb
)
262 struct gl_renderbuffer_attachment
*att
;
264 _glthread_LOCK_MUTEX(fb
->Mutex
);
266 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
269 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
272 _mesa_remove_attachment(ctx
, att
);
275 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
280 * Test if an attachment point is complete and update its Complete field.
281 * \param format if GL_COLOR, this is a color attachment point,
282 * if GL_DEPTH, this is a depth component attachment point,
283 * if GL_STENCIL, this is a stencil component attachment point.
286 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
287 struct gl_renderbuffer_attachment
*att
)
289 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
291 /* assume complete */
292 att
->Complete
= GL_TRUE
;
294 /* Look for reasons why the attachment might be incomplete */
295 if (att
->Type
== GL_TEXTURE
) {
296 const struct gl_texture_object
*texObj
= att
->Texture
;
297 struct gl_texture_image
*texImage
;
300 att
->Complete
= GL_FALSE
;
304 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
306 att
->Complete
= GL_FALSE
;
309 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
310 att
->Complete
= GL_FALSE
;
313 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
314 att
->Complete
= GL_FALSE
;
318 if (format
== GL_COLOR
) {
319 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
320 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
321 att
->Complete
= GL_FALSE
;
325 else if (format
== GL_DEPTH
) {
326 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
329 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
330 texImage
->TexFormat
->BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
334 att
->Complete
= GL_FALSE
;
339 /* no such thing as stencil textures */
340 att
->Complete
= GL_FALSE
;
344 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
345 ASSERT(att
->Renderbuffer
);
346 if (!att
->Renderbuffer
->InternalFormat
||
347 att
->Renderbuffer
->Width
< 1 ||
348 att
->Renderbuffer
->Height
< 1) {
349 att
->Complete
= GL_FALSE
;
352 if (format
== GL_COLOR
) {
353 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
354 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
355 ASSERT(att
->Renderbuffer
->RedBits
);
356 ASSERT(att
->Renderbuffer
->GreenBits
);
357 ASSERT(att
->Renderbuffer
->BlueBits
);
358 att
->Complete
= GL_FALSE
;
362 else if (format
== GL_DEPTH
) {
363 ASSERT(att
->Renderbuffer
->DepthBits
);
364 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
367 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
368 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
372 att
->Complete
= GL_FALSE
;
377 assert(format
== GL_STENCIL
);
378 ASSERT(att
->Renderbuffer
->StencilBits
);
379 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
382 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
383 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
387 att
->Complete
= GL_FALSE
;
393 ASSERT(att
->Type
== GL_NONE
);
401 * Helpful for debugging
404 fbo_incomplete(const char *msg
, int index
)
409 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
415 * Test if the given framebuffer object is complete and update its
416 * Status field with the results.
417 * Also update the framebuffer's Width and Height fields if the
418 * framebuffer is complete.
421 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
424 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
425 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
429 assert(fb
->Name
!= 0);
435 /* Start at -2 to more easily loop over all attachment points.
440 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
441 struct gl_renderbuffer_attachment
*att
;
444 /* check for attachment completeness
447 att
= &fb
->Attachment
[BUFFER_DEPTH
];
448 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
449 if (!att
->Complete
) {
450 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
451 fbo_incomplete("depth attachment incomplete", -1);
456 att
= &fb
->Attachment
[BUFFER_STENCIL
];
457 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
458 if (!att
->Complete
) {
459 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
460 fbo_incomplete("stencil attachment incomplete", -1);
465 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
466 test_attachment_completeness(ctx
, GL_COLOR
, att
);
467 if (!att
->Complete
) {
468 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
469 fbo_incomplete("color attachment incomplete", i
);
474 /* get width, height, format of the renderbuffer/texture
476 if (att
->Type
== GL_TEXTURE
) {
477 const struct gl_texture_image
*texImg
478 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
479 minWidth
= MIN2(minWidth
, texImg
->Width
);
480 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
481 minHeight
= MIN2(minHeight
, texImg
->Height
);
482 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
483 f
= texImg
->_BaseFormat
;
485 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
486 && f
!= GL_DEPTH_STENCIL_EXT
) {
487 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
488 fbo_incomplete("texture attachment incomplete", -1);
492 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
493 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
494 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
495 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
496 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
497 f
= att
->Renderbuffer
->InternalFormat
;
501 assert(att
->Type
== GL_NONE
);
505 /* Error-check width, height, format
507 if (numImages
== 1) {
513 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
514 /* check that width, height, format are same */
515 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
516 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
517 fbo_incomplete("width or height mismatch", -1);
520 /* check that all color buffer have same format */
521 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
522 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
523 fbo_incomplete("format mismatch", -1);
530 #ifndef FEATURE_OES_framebuffer_object
531 /* Check that all DrawBuffers are present */
532 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
533 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
534 const struct gl_renderbuffer_attachment
*att
535 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
537 if (att
->Type
== GL_NONE
) {
538 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
539 fbo_incomplete("missing drawbuffer", j
);
545 /* Check that the ReadBuffer is present */
546 if (fb
->ColorReadBuffer
!= GL_NONE
) {
547 const struct gl_renderbuffer_attachment
*att
548 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
550 if (att
->Type
== GL_NONE
) {
551 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
552 fbo_incomplete("missing readbuffer", -1);
558 if (numImages
== 0) {
559 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
560 fbo_incomplete("no attachments", -1);
565 * If we get here, the framebuffer is complete!
566 * Note that if ARB_framebuffer_object is supported and the attached
567 * renderbuffers/textures are different sizes, the framebuffer width/height
568 * will be set to the smallest width/height.
570 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
571 fb
->Width
= minWidth
;
572 fb
->Height
= minHeight
;
577 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
579 GET_CURRENT_CONTEXT(ctx
);
580 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
582 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
583 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
591 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
593 struct gl_renderbuffer
*newRb
;
594 GET_CURRENT_CONTEXT(ctx
);
596 ASSERT_OUTSIDE_BEGIN_END(ctx
);
598 if (target
!= GL_RENDERBUFFER_EXT
) {
599 _mesa_error(ctx
, GL_INVALID_ENUM
,
600 "glBindRenderbufferEXT(target)");
604 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
605 /* The above doesn't fully flush the drivers in the way that a
606 * glFlush does, but that is required here:
608 if (ctx
->Driver
.Flush
)
609 ctx
->Driver
.Flush(ctx
);
613 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
614 if (newRb
== &DummyRenderbuffer
) {
615 /* ID was reserved, but no real renderbuffer object made yet */
619 /* create new renderbuffer object */
620 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
622 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
625 ASSERT(newRb
->AllocStorage
);
626 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
627 newRb
->RefCount
= 1; /* referenced by hash table */
634 ASSERT(newRb
!= &DummyRenderbuffer
);
636 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
641 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
644 GET_CURRENT_CONTEXT(ctx
);
646 ASSERT_OUTSIDE_BEGIN_END(ctx
);
647 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
649 for (i
= 0; i
< n
; i
++) {
650 if (renderbuffers
[i
] > 0) {
651 struct gl_renderbuffer
*rb
;
652 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
654 /* check if deleting currently bound renderbuffer object */
655 if (rb
== ctx
->CurrentRenderbuffer
) {
657 ASSERT(rb
->RefCount
>= 2);
658 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
661 /* Remove from hash table immediately, to free the ID.
662 * But the object will not be freed until it's no longer
663 * referenced anywhere else.
665 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
667 if (rb
!= &DummyRenderbuffer
) {
668 /* no longer referenced by hash table */
669 _mesa_reference_renderbuffer(&rb
, NULL
);
678 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
680 GET_CURRENT_CONTEXT(ctx
);
684 ASSERT_OUTSIDE_BEGIN_END(ctx
);
687 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
694 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
696 for (i
= 0; i
< n
; i
++) {
697 GLuint name
= first
+ i
;
698 renderbuffers
[i
] = name
;
699 /* insert dummy placeholder into hash table */
700 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
701 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
702 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
708 * Given an internal format token for a render buffer, return the
709 * corresponding base format.
710 * This is very similar to _mesa_base_tex_format() but the set of valid
711 * internal formats is somewhat different.
713 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
714 * GL_DEPTH_STENCIL_EXT or zero if error.
717 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
719 switch (internalFormat
) {
738 case GL_STENCIL_INDEX
:
739 case GL_STENCIL_INDEX1_EXT
:
740 case GL_STENCIL_INDEX4_EXT
:
741 case GL_STENCIL_INDEX8_EXT
:
742 case GL_STENCIL_INDEX16_EXT
:
743 return GL_STENCIL_INDEX
;
744 case GL_DEPTH_COMPONENT
:
745 case GL_DEPTH_COMPONENT16
:
746 case GL_DEPTH_COMPONENT24
:
747 case GL_DEPTH_COMPONENT32
:
748 return GL_DEPTH_COMPONENT
;
749 case GL_DEPTH_STENCIL_EXT
:
750 case GL_DEPTH24_STENCIL8_EXT
:
751 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
752 return GL_DEPTH_STENCIL_EXT
;
755 /* XXX add floating point formats eventually */
763 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
764 GLsizei width
, GLsizei height
)
766 struct gl_renderbuffer
*rb
;
768 GET_CURRENT_CONTEXT(ctx
);
770 ASSERT_OUTSIDE_BEGIN_END(ctx
);
772 if (target
!= GL_RENDERBUFFER_EXT
) {
773 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
777 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
778 if (baseFormat
== 0) {
779 _mesa_error(ctx
, GL_INVALID_ENUM
,
780 "glRenderbufferStorageEXT(internalFormat)");
784 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
785 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
789 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
790 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
794 rb
= ctx
->CurrentRenderbuffer
;
797 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
801 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
803 if (rb
->InternalFormat
== internalFormat
&&
804 rb
->Width
== (GLuint
) width
&&
805 rb
->Height
== (GLuint
) height
) {
806 /* no change in allocation needed */
810 /* These MUST get set by the AllocStorage func */
811 rb
->_ActualFormat
= 0;
820 /* Now allocate the storage */
821 ASSERT(rb
->AllocStorage
);
822 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
823 /* No error - check/set fields now */
824 assert(rb
->_ActualFormat
);
825 assert(rb
->Width
== (GLuint
) width
);
826 assert(rb
->Height
== (GLuint
) height
);
827 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
828 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
829 rb
->InternalFormat
= internalFormat
;
830 rb
->_BaseFormat
= baseFormat
;
833 /* Probably ran out of memory - clear the fields */
836 rb
->InternalFormat
= GL_NONE
;
837 rb
->_ActualFormat
= GL_NONE
;
838 rb
->_BaseFormat
= GL_NONE
;
849 test_framebuffer_completeness(ctx, fb);
851 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
858 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
860 GET_CURRENT_CONTEXT(ctx
);
862 ASSERT_OUTSIDE_BEGIN_END(ctx
);
864 if (target
!= GL_RENDERBUFFER_EXT
) {
865 _mesa_error(ctx
, GL_INVALID_ENUM
,
866 "glGetRenderbufferParameterivEXT(target)");
870 if (!ctx
->CurrentRenderbuffer
) {
871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
872 "glGetRenderbufferParameterivEXT");
876 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
879 case GL_RENDERBUFFER_WIDTH_EXT
:
880 *params
= ctx
->CurrentRenderbuffer
->Width
;
882 case GL_RENDERBUFFER_HEIGHT_EXT
:
883 *params
= ctx
->CurrentRenderbuffer
->Height
;
885 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
886 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
888 case GL_RENDERBUFFER_RED_SIZE_EXT
:
889 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
891 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
892 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
894 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
895 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
897 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
898 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
900 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
901 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
903 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
904 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
907 _mesa_error(ctx
, GL_INVALID_ENUM
,
908 "glGetRenderbufferParameterivEXT(target)");
915 _mesa_IsFramebufferEXT(GLuint framebuffer
)
917 GET_CURRENT_CONTEXT(ctx
);
918 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
920 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
921 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
929 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
932 ASSERT(ctx
->Driver
.RenderTexture
);
933 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
934 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
935 struct gl_texture_object
*texObj
= att
->Texture
;
937 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
938 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
945 * Examine all the framebuffer's attachments to see if any are textures.
946 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
947 * notify the device driver that the texture image may have changed.
950 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
952 if (ctx
->Driver
.FinishRenderTexture
) {
954 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
955 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
956 if (att
->Texture
&& att
->Renderbuffer
) {
957 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
965 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
967 struct gl_framebuffer
*newFb
, *newFbread
;
968 GLboolean bindReadBuf
, bindDrawBuf
;
969 GET_CURRENT_CONTEXT(ctx
);
971 ASSERT_OUTSIDE_BEGIN_END(ctx
);
973 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
974 _mesa_error(ctx
, GL_INVALID_OPERATION
,
975 "glBindFramebufferEXT(unsupported)");
980 #if FEATURE_EXT_framebuffer_blit
981 case GL_DRAW_FRAMEBUFFER_EXT
:
982 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
983 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
986 bindDrawBuf
= GL_TRUE
;
987 bindReadBuf
= GL_FALSE
;
989 case GL_READ_FRAMEBUFFER_EXT
:
990 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
991 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
994 bindDrawBuf
= GL_FALSE
;
995 bindReadBuf
= GL_TRUE
;
998 case GL_FRAMEBUFFER_EXT
:
999 bindDrawBuf
= GL_TRUE
;
1000 bindReadBuf
= GL_TRUE
;
1003 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1007 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1009 if (ctx
->Driver
.Flush
) {
1010 ctx
->Driver
.Flush(ctx
);
1014 /* Binding a user-created framebuffer object */
1015 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1016 if (newFb
== &DummyFramebuffer
) {
1017 /* ID was reserved, but no real framebuffer object made yet */
1021 /* create new framebuffer object */
1022 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1024 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1027 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
1032 /* Binding the window system framebuffer (which was originally set
1033 * with MakeCurrent).
1035 newFb
= ctx
->WinSysDrawBuffer
;
1036 newFbread
= ctx
->WinSysReadBuffer
;
1040 ASSERT(newFb
!= &DummyFramebuffer
);
1043 * XXX check if re-binding same buffer and skip some of this code.
1047 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1051 /* check if old FB had any texture attachments */
1052 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1054 /* check if time to delete this framebuffer */
1055 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1057 if (newFb
->Name
!= 0) {
1058 /* check if newly bound framebuffer has any texture attachments */
1059 check_begin_texture_render(ctx
, newFb
);
1063 if (ctx
->Driver
.BindFramebuffer
) {
1064 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1070 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1073 GET_CURRENT_CONTEXT(ctx
);
1075 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1076 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1077 /* The above doesn't fully flush the drivers in the way that a
1078 * glFlush does, but that is required here:
1080 if (ctx
->Driver
.Flush
)
1081 ctx
->Driver
.Flush(ctx
);
1083 for (i
= 0; i
< n
; i
++) {
1084 if (framebuffers
[i
] > 0) {
1085 struct gl_framebuffer
*fb
;
1086 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1088 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1090 /* check if deleting currently bound framebuffer object */
1091 if (fb
== ctx
->DrawBuffer
) {
1093 ASSERT(fb
->RefCount
>= 2);
1094 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1097 /* remove from hash table immediately, to free the ID */
1098 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1100 if (fb
!= &DummyFramebuffer
) {
1101 /* But the object will not be freed until it's no longer
1102 * bound in any context.
1104 _mesa_unreference_framebuffer(&fb
);
1113 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1115 GET_CURRENT_CONTEXT(ctx
);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1122 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1129 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1131 for (i
= 0; i
< n
; i
++) {
1132 GLuint name
= first
+ i
;
1133 framebuffers
[i
] = name
;
1134 /* insert dummy placeholder into hash table */
1135 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1136 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1137 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1144 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1146 struct gl_framebuffer
*buffer
;
1147 GET_CURRENT_CONTEXT(ctx
);
1149 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1152 #if FEATURE_EXT_framebuffer_blit
1153 case GL_DRAW_FRAMEBUFFER_EXT
:
1154 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1155 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1158 buffer
= ctx
->DrawBuffer
;
1160 case GL_READ_FRAMEBUFFER_EXT
:
1161 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1162 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1165 buffer
= ctx
->ReadBuffer
;
1168 case GL_FRAMEBUFFER_EXT
:
1169 buffer
= ctx
->DrawBuffer
;
1172 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1173 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1176 if (buffer
->Name
== 0) {
1177 /* The window system / default framebuffer is always complete */
1178 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1181 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1183 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1184 return buffer
->_Status
;
1190 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1193 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1194 GLenum attachment
, GLenum textarget
, GLuint texture
,
1195 GLint level
, GLint zoffset
)
1197 struct gl_renderbuffer_attachment
*att
;
1198 struct gl_texture_object
*texObj
= NULL
;
1199 struct gl_framebuffer
*fb
;
1201 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1203 if (target
!= GL_FRAMEBUFFER_EXT
) {
1204 _mesa_error(ctx
, GL_INVALID_ENUM
,
1205 "glFramebufferTexture%sEXT(target)", caller
);
1209 fb
= ctx
->DrawBuffer
;
1212 /* check framebuffer binding */
1213 if (fb
->Name
== 0) {
1214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1215 "glFramebufferTexture%sEXT", caller
);
1220 /* The textarget, level, and zoffset parameters are only validated if
1221 * texture is non-zero.
1224 GLboolean err
= GL_TRUE
;
1226 texObj
= _mesa_lookup_texture(ctx
, texture
);
1227 if (texObj
!= NULL
) {
1228 if (textarget
== 0) {
1229 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1230 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1231 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1234 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1235 ? !IS_CUBE_FACE(textarget
)
1236 : (texObj
->Target
!= textarget
);
1241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1242 "glFramebufferTexture%sEXT(texture target mismatch)",
1247 if (texObj
->Target
== GL_TEXTURE_3D
) {
1248 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1249 if (zoffset
< 0 || zoffset
>= maxSize
) {
1250 _mesa_error(ctx
, GL_INVALID_VALUE
,
1251 "glFramebufferTexture%sEXT(zoffset)", caller
);
1255 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1256 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1257 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1258 _mesa_error(ctx
, GL_INVALID_VALUE
,
1259 "glFramebufferTexture%sEXT(layer)", caller
);
1266 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1267 _mesa_error(ctx
, GL_INVALID_VALUE
,
1268 "glFramebufferTexture%sEXT(level)", caller
);
1273 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1275 _mesa_error(ctx
, GL_INVALID_ENUM
,
1276 "glFramebufferTexture%sEXT(attachment)", caller
);
1280 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1281 /* The above doesn't fully flush the drivers in the way that a
1282 * glFlush does, but that is required here:
1284 if (ctx
->Driver
.Flush
)
1285 ctx
->Driver
.Flush(ctx
);
1287 _glthread_LOCK_MUTEX(fb
->Mutex
);
1289 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1293 _mesa_remove_attachment(ctx
, att
);
1295 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1301 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1302 GLenum textarget
, GLuint texture
, GLint level
)
1304 GET_CURRENT_CONTEXT(ctx
);
1306 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1307 _mesa_error(ctx
, GL_INVALID_ENUM
,
1308 "glFramebufferTexture1DEXT(textarget)");
1312 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1318 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1319 GLenum textarget
, GLuint texture
, GLint level
)
1321 GET_CURRENT_CONTEXT(ctx
);
1323 if ((texture
!= 0) &&
1324 (textarget
!= GL_TEXTURE_2D
) &&
1325 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1326 (!IS_CUBE_FACE(textarget
))) {
1327 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1328 "glFramebufferTexture2DEXT(textarget)");
1332 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1338 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1339 GLenum textarget
, GLuint texture
,
1340 GLint level
, GLint zoffset
)
1342 GET_CURRENT_CONTEXT(ctx
);
1344 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1345 _mesa_error(ctx
, GL_INVALID_ENUM
,
1346 "glFramebufferTexture3DEXT(textarget)");
1350 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1356 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1357 GLuint texture
, GLint level
, GLint layer
)
1359 GET_CURRENT_CONTEXT(ctx
);
1361 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1367 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1368 GLenum renderbufferTarget
,
1369 GLuint renderbuffer
)
1371 struct gl_renderbuffer_attachment
*att
;
1372 struct gl_framebuffer
*fb
;
1373 struct gl_renderbuffer
*rb
;
1374 GET_CURRENT_CONTEXT(ctx
);
1376 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1379 #if FEATURE_EXT_framebuffer_blit
1380 case GL_DRAW_FRAMEBUFFER_EXT
:
1381 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1382 _mesa_error(ctx
, GL_INVALID_ENUM
,
1383 "glFramebufferRenderbufferEXT(target)");
1386 fb
= ctx
->DrawBuffer
;
1388 case GL_READ_FRAMEBUFFER_EXT
:
1389 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1390 _mesa_error(ctx
, GL_INVALID_ENUM
,
1391 "glFramebufferRenderbufferEXT(target)");
1394 fb
= ctx
->ReadBuffer
;
1397 case GL_FRAMEBUFFER_EXT
:
1398 fb
= ctx
->DrawBuffer
;
1401 _mesa_error(ctx
, GL_INVALID_ENUM
,
1402 "glFramebufferRenderbufferEXT(target)");
1406 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1407 _mesa_error(ctx
, GL_INVALID_ENUM
,
1408 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1412 if (fb
->Name
== 0) {
1413 /* Can't attach new renderbuffers to a window system framebuffer */
1414 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1418 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1420 _mesa_error(ctx
, GL_INVALID_ENUM
,
1421 "glFramebufferRenderbufferEXT(attachment)");
1426 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1429 "glFramebufferRenderbufferEXT(renderbuffer)");
1434 /* remove renderbuffer attachment */
1438 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1439 /* The above doesn't fully flush the drivers in the way that a
1440 * glFlush does, but that is required here:
1442 if (ctx
->Driver
.Flush
)
1443 ctx
->Driver
.Flush(ctx
);
1445 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1446 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1448 /* Some subsequent GL commands may depend on the framebuffer's visual
1449 * after the binding is updated. Update visual info now.
1451 _mesa_update_framebuffer_visual(fb
);
1456 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1457 GLenum pname
, GLint
*params
)
1459 const struct gl_renderbuffer_attachment
*att
;
1460 struct gl_framebuffer
*buffer
;
1461 GET_CURRENT_CONTEXT(ctx
);
1463 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1466 #if FEATURE_EXT_framebuffer_blit
1467 case GL_DRAW_FRAMEBUFFER_EXT
:
1468 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1469 _mesa_error(ctx
, GL_INVALID_ENUM
,
1470 "glGetFramebufferAttachmentParameterivEXT(target)");
1473 buffer
= ctx
->DrawBuffer
;
1475 case GL_READ_FRAMEBUFFER_EXT
:
1476 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1477 _mesa_error(ctx
, GL_INVALID_ENUM
,
1478 "glGetFramebufferAttachmentParameterivEXT(target)");
1481 buffer
= ctx
->ReadBuffer
;
1484 case GL_FRAMEBUFFER_EXT
:
1485 buffer
= ctx
->DrawBuffer
;
1488 _mesa_error(ctx
, GL_INVALID_ENUM
,
1489 "glGetFramebufferAttachmentParameterivEXT(target)");
1493 if (buffer
->Name
== 0) {
1494 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1495 "glGetFramebufferAttachmentParameterivEXT");
1499 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1501 _mesa_error(ctx
, GL_INVALID_ENUM
,
1502 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1506 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1507 /* The above doesn't fully flush the drivers in the way that a
1508 * glFlush does, but that is required here:
1510 if (ctx
->Driver
.Flush
)
1511 ctx
->Driver
.Flush(ctx
);
1514 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1515 *params
= att
->Type
;
1517 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1518 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1519 *params
= att
->Renderbuffer
->Name
;
1521 else if (att
->Type
== GL_TEXTURE
) {
1522 *params
= att
->Texture
->Name
;
1525 _mesa_error(ctx
, GL_INVALID_ENUM
,
1526 "glGetFramebufferAttachmentParameterivEXT(pname)");
1529 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1530 if (att
->Type
== GL_TEXTURE
) {
1531 *params
= att
->TextureLevel
;
1534 _mesa_error(ctx
, GL_INVALID_ENUM
,
1535 "glGetFramebufferAttachmentParameterivEXT(pname)");
1538 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1539 if (att
->Type
== GL_TEXTURE
) {
1540 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
1541 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1548 _mesa_error(ctx
, GL_INVALID_ENUM
,
1549 "glGetFramebufferAttachmentParameterivEXT(pname)");
1552 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1553 if (att
->Type
== GL_TEXTURE
) {
1554 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
1555 *params
= att
->Zoffset
;
1562 _mesa_error(ctx
, GL_INVALID_ENUM
,
1563 "glGetFramebufferAttachmentParameterivEXT(pname)");
1567 _mesa_error(ctx
, GL_INVALID_ENUM
,
1568 "glGetFramebufferAttachmentParameterivEXT(pname)");
1575 _mesa_GenerateMipmapEXT(GLenum target
)
1577 struct gl_texture_unit
*texUnit
;
1578 struct gl_texture_object
*texObj
;
1579 GET_CURRENT_CONTEXT(ctx
);
1581 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1582 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1588 case GL_TEXTURE_CUBE_MAP
:
1589 /* OK, legal value */
1592 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1596 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1597 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1599 _mesa_lock_texture(ctx
, texObj
);
1600 if (target
== GL_TEXTURE_CUBE_MAP
) {
1603 for (face
= 0; face
< 6; face
++)
1604 ctx
->Driver
.GenerateMipmap(ctx
,
1605 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
1608 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
1610 _mesa_unlock_texture(ctx
, texObj
);
1614 #if FEATURE_EXT_framebuffer_blit
1616 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1617 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1618 GLbitfield mask
, GLenum filter
)
1620 GET_CURRENT_CONTEXT(ctx
);
1622 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1623 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1625 if (ctx
->NewState
) {
1626 _mesa_update_state(ctx
);
1629 if (!ctx
->ReadBuffer
) {
1633 /* check for complete framebuffers */
1634 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1635 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1636 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1637 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1641 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1642 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1646 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1647 GL_DEPTH_BUFFER_BIT
|
1648 GL_STENCIL_BUFFER_BIT
)) {
1649 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1653 /* depth/stencil must be blitted with nearest filtering */
1654 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1655 && filter
!= GL_NEAREST
) {
1656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1657 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1661 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1662 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1663 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1664 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1665 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1666 "glBlitFramebufferEXT(stencil buffer size mismatch");
1671 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1672 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1673 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1674 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1675 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1676 "glBlitFramebufferEXT(depth buffer size mismatch");
1681 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1682 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1686 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1687 ctx
->Driver
.BlitFramebuffer(ctx
,
1688 srcX0
, srcY0
, srcX1
, srcY1
,
1689 dstX0
, dstY0
, dstX1
, dstY1
,
1692 #endif /* FEATURE_EXT_framebuffer_blit */