2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include "framebuffer.h"
37 #include "renderbuffer.h"
47 * None of the GL_EXT_framebuffer_object functions are compiled into
54 * When glGenRender/FramebuffersEXT() is called we insert pointers to
55 * these placeholder objects into the hash table.
56 * Later, when the object ID is first bound, we replace the placeholder
57 * with the real frame/renderbuffer.
59 static struct gl_framebuffer DummyFramebuffer
;
60 static struct gl_renderbuffer DummyRenderbuffer
;
63 #define IS_CUBE_FACE(TARGET) \
64 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
65 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
69 * Helper routine for getting a gl_renderbuffer.
71 struct gl_renderbuffer
*
72 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
74 struct gl_renderbuffer
*rb
;
79 rb
= (struct gl_renderbuffer
*)
80 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
86 * Helper routine for getting a gl_framebuffer.
88 struct gl_framebuffer
*
89 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
91 struct gl_framebuffer
*fb
;
96 fb
= (struct gl_framebuffer
*)
97 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
103 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
104 * gl_renderbuffer_attachment object.
106 struct gl_renderbuffer_attachment
*
107 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
112 switch (attachment
) {
113 case GL_COLOR_ATTACHMENT0_EXT
:
114 case GL_COLOR_ATTACHMENT1_EXT
:
115 case GL_COLOR_ATTACHMENT2_EXT
:
116 case GL_COLOR_ATTACHMENT3_EXT
:
117 case GL_COLOR_ATTACHMENT4_EXT
:
118 case GL_COLOR_ATTACHMENT5_EXT
:
119 case GL_COLOR_ATTACHMENT6_EXT
:
120 case GL_COLOR_ATTACHMENT7_EXT
:
121 case GL_COLOR_ATTACHMENT8_EXT
:
122 case GL_COLOR_ATTACHMENT9_EXT
:
123 case GL_COLOR_ATTACHMENT10_EXT
:
124 case GL_COLOR_ATTACHMENT11_EXT
:
125 case GL_COLOR_ATTACHMENT12_EXT
:
126 case GL_COLOR_ATTACHMENT13_EXT
:
127 case GL_COLOR_ATTACHMENT14_EXT
:
128 case GL_COLOR_ATTACHMENT15_EXT
:
129 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
130 if (i
>= ctx
->Const
.MaxColorAttachments
) {
133 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
134 case GL_DEPTH_ATTACHMENT_EXT
:
135 return &fb
->Attachment
[BUFFER_DEPTH
];
136 case GL_STENCIL_ATTACHMENT_EXT
:
137 return &fb
->Attachment
[BUFFER_STENCIL
];
145 * Remove any texture or renderbuffer attached to the given attachment
146 * point. Update reference counts, etc.
149 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
151 if (att
->Type
== GL_TEXTURE
) {
152 ASSERT(att
->Texture
);
153 att
->Texture
->RefCount
--;
154 if (att
->Texture
->RefCount
== 0) {
155 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
158 /* tell driver that we're done rendering to this texture. */
159 if (ctx
->Driver
.FinishRenderTexture
) {
160 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
165 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
166 ASSERT(att
->Renderbuffer
);
167 ASSERT(!att
->Texture
);
168 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
171 att
->Complete
= GL_TRUE
;
176 * Bind a texture object to an attachment point.
177 * The previous binding, if any, will be removed first.
180 _mesa_set_texture_attachment(GLcontext
*ctx
,
181 struct gl_framebuffer
*fb
,
182 struct gl_renderbuffer_attachment
*att
,
183 struct gl_texture_object
*texObj
,
184 GLenum texTarget
, GLuint level
, GLuint zoffset
)
186 if (att
->Texture
== texObj
) {
187 /* re-attaching same texture */
188 ASSERT(att
->Type
== GL_TEXTURE
);
192 _mesa_remove_attachment(ctx
, att
);
193 att
->Type
= GL_TEXTURE
;
194 att
->Texture
= texObj
;
198 /* always update these fields */
199 att
->TextureLevel
= level
;
200 if (IS_CUBE_FACE(texTarget
)) {
201 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
204 att
->CubeMapFace
= 0;
206 att
->Zoffset
= zoffset
;
207 att
->Complete
= GL_FALSE
;
209 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
210 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
216 * Bind a renderbuffer to an attachment point.
217 * The previous binding, if any, will be removed first.
220 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
221 struct gl_renderbuffer_attachment
*att
,
222 struct gl_renderbuffer
*rb
)
224 /* XXX check if re-doing same attachment, exit early */
225 _mesa_remove_attachment(ctx
, att
);
226 att
->Type
= GL_RENDERBUFFER_EXT
;
227 att
->Texture
= NULL
; /* just to be safe */
228 att
->Complete
= GL_FALSE
;
229 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
234 * Fallback for ctx->Driver.FramebufferRenderbuffer()
235 * Attach a renderbuffer object to a framebuffer object.
238 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
239 GLenum attachment
, struct gl_renderbuffer
*rb
)
241 struct gl_renderbuffer_attachment
*att
;
243 _glthread_LOCK_MUTEX(fb
->Mutex
);
245 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
248 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
251 _mesa_remove_attachment(ctx
, att
);
254 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
259 * Test if an attachment point is complete and update its Complete field.
260 * \param format if GL_COLOR, this is a color attachment point,
261 * if GL_DEPTH, this is a depth component attachment point,
262 * if GL_STENCIL, this is a stencil component attachment point.
265 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
266 struct gl_renderbuffer_attachment
*att
)
268 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
270 /* assume complete */
271 att
->Complete
= GL_TRUE
;
273 /* Look for reasons why the attachment might be incomplete */
274 if (att
->Type
== GL_TEXTURE
) {
275 const struct gl_texture_object
*texObj
= att
->Texture
;
276 struct gl_texture_image
*texImage
;
279 att
->Complete
= GL_FALSE
;
283 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
285 att
->Complete
= GL_FALSE
;
288 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
289 att
->Complete
= GL_FALSE
;
292 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
293 att
->Complete
= GL_FALSE
;
297 if (format
== GL_COLOR
) {
298 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
299 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
300 att
->Complete
= GL_FALSE
;
304 else if (format
== GL_DEPTH
) {
305 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
308 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
309 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
313 att
->Complete
= GL_FALSE
;
318 /* no such thing as stencil textures */
319 att
->Complete
= GL_FALSE
;
323 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
324 ASSERT(att
->Renderbuffer
);
325 if (!att
->Renderbuffer
->InternalFormat
||
326 att
->Renderbuffer
->Width
< 1 ||
327 att
->Renderbuffer
->Height
< 1) {
328 att
->Complete
= GL_FALSE
;
331 if (format
== GL_COLOR
) {
332 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
333 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
334 ASSERT(att
->Renderbuffer
->RedBits
);
335 ASSERT(att
->Renderbuffer
->GreenBits
);
336 ASSERT(att
->Renderbuffer
->BlueBits
);
337 att
->Complete
= GL_FALSE
;
341 else if (format
== GL_DEPTH
) {
342 ASSERT(att
->Renderbuffer
->DepthBits
);
343 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
346 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
347 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
351 att
->Complete
= GL_FALSE
;
356 assert(format
== GL_STENCIL
);
357 ASSERT(att
->Renderbuffer
->StencilBits
);
358 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
361 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
362 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
366 att
->Complete
= GL_FALSE
;
372 ASSERT(att
->Type
== GL_NONE
);
380 * Helpful for debugging
383 fbo_incomplete(const char *msg
, int index
)
388 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
394 * Test if the given framebuffer object is complete and update its
395 * Status field with the results.
396 * Also update the framebuffer's Width and Height fields if the
397 * framebuffer is complete.
400 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
402 GLuint numImages
, width
= 0, height
= 0;
403 GLenum intFormat
= GL_NONE
;
408 assert(fb
->Name
!= 0);
414 /* Start at -2 to more easily loop over all attachment points */
415 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
416 struct gl_renderbuffer_attachment
*att
;
420 att
= &fb
->Attachment
[BUFFER_DEPTH
];
421 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
422 if (!att
->Complete
) {
423 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
424 fbo_incomplete("depth attachment incomplete", -1);
429 att
= &fb
->Attachment
[BUFFER_STENCIL
];
430 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
431 if (!att
->Complete
) {
432 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
433 fbo_incomplete("stencil attachment incomplete", -1);
438 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
439 test_attachment_completeness(ctx
, GL_COLOR
, att
);
440 if (!att
->Complete
) {
441 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
442 fbo_incomplete("color attachment incomplete", i
);
447 if (att
->Type
== GL_TEXTURE
) {
448 const struct gl_texture_image
*texImg
449 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
452 f
= texImg
->_BaseFormat
;
454 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
455 && f
!= GL_DEPTH_STENCIL_EXT
) {
456 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
457 fbo_incomplete("texture attachment incomplete", -1);
461 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
462 w
= att
->Renderbuffer
->Width
;
463 h
= att
->Renderbuffer
->Height
;
464 f
= att
->Renderbuffer
->InternalFormat
;
468 assert(att
->Type
== GL_NONE
);
472 if (numImages
== 1) {
473 /* set required width, height and format */
480 /* check that width, height, format are same */
481 if (w
!= width
|| h
!= height
) {
482 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
483 fbo_incomplete("width or height mismatch", -1);
486 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
487 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
488 fbo_incomplete("format mismatch", -1);
494 /* Check that all DrawBuffers are present */
495 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
496 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
497 const struct gl_renderbuffer_attachment
*att
498 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
500 if (att
->Type
== GL_NONE
) {
501 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
502 fbo_incomplete("missing drawbuffer", j
);
508 /* Check that the ReadBuffer is present */
509 if (fb
->ColorReadBuffer
!= GL_NONE
) {
510 const struct gl_renderbuffer_attachment
*att
511 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
513 if (att
->Type
== GL_NONE
) {
514 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
515 fbo_incomplete("missing readbuffer", -1);
520 if (numImages
== 0) {
521 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
522 fbo_incomplete("no attachments", -1);
527 * If we get here, the framebuffer is complete!
529 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
536 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
538 GET_CURRENT_CONTEXT(ctx
);
539 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
541 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
542 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
550 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
552 struct gl_renderbuffer
*newRb
;
553 GET_CURRENT_CONTEXT(ctx
);
555 ASSERT_OUTSIDE_BEGIN_END(ctx
);
557 if (target
!= GL_RENDERBUFFER_EXT
) {
558 _mesa_error(ctx
, GL_INVALID_ENUM
,
559 "glBindRenderbufferEXT(target)");
563 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
564 /* The above doesn't fully flush the drivers in the way that a
565 * glFlush does, but that is required here:
567 if (ctx
->Driver
.Flush
)
568 ctx
->Driver
.Flush(ctx
);
572 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
573 if (newRb
== &DummyRenderbuffer
) {
574 /* ID was reserved, but no real renderbuffer object made yet */
578 /* create new renderbuffer object */
579 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
581 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
584 ASSERT(newRb
->AllocStorage
);
585 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
586 newRb
->RefCount
= 1; /* referenced by hash table */
593 ASSERT(newRb
!= &DummyRenderbuffer
);
595 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
600 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
603 GET_CURRENT_CONTEXT(ctx
);
605 ASSERT_OUTSIDE_BEGIN_END(ctx
);
606 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
608 for (i
= 0; i
< n
; i
++) {
609 if (renderbuffers
[i
] > 0) {
610 struct gl_renderbuffer
*rb
;
611 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
613 /* check if deleting currently bound renderbuffer object */
614 if (rb
== ctx
->CurrentRenderbuffer
) {
616 ASSERT(rb
->RefCount
>= 2);
617 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
620 /* Remove from hash table immediately, to free the ID.
621 * But the object will not be freed until it's no longer
622 * referenced anywhere else.
624 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
626 if (rb
!= &DummyRenderbuffer
) {
627 /* no longer referenced by hash table */
628 _mesa_reference_renderbuffer(&rb
, NULL
);
637 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
639 GET_CURRENT_CONTEXT(ctx
);
643 ASSERT_OUTSIDE_BEGIN_END(ctx
);
646 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
653 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
655 for (i
= 0; i
< n
; i
++) {
656 GLuint name
= first
+ i
;
657 renderbuffers
[i
] = name
;
658 /* insert dummy placeholder into hash table */
659 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
660 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
661 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
667 * Given an internal format token for a render buffer, return the
668 * corresponding base format.
669 * This is very similar to _mesa_base_tex_format() but the set of valid
670 * internal formats is somewhat different.
672 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
673 * GL_DEPTH_STENCIL_EXT or zero if error.
676 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
678 switch (internalFormat
) {
697 case GL_STENCIL_INDEX
:
698 case GL_STENCIL_INDEX1_EXT
:
699 case GL_STENCIL_INDEX4_EXT
:
700 case GL_STENCIL_INDEX8_EXT
:
701 case GL_STENCIL_INDEX16_EXT
:
702 return GL_STENCIL_INDEX
;
703 case GL_DEPTH_COMPONENT
:
704 case GL_DEPTH_COMPONENT16
:
705 case GL_DEPTH_COMPONENT24
:
706 case GL_DEPTH_COMPONENT32
:
707 return GL_DEPTH_COMPONENT
;
708 case GL_DEPTH_STENCIL_EXT
:
709 case GL_DEPTH24_STENCIL8_EXT
:
710 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
711 return GL_DEPTH_STENCIL_EXT
;
714 /* XXX add floating point formats eventually */
722 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
723 GLsizei width
, GLsizei height
)
725 struct gl_renderbuffer
*rb
;
727 GET_CURRENT_CONTEXT(ctx
);
729 ASSERT_OUTSIDE_BEGIN_END(ctx
);
731 if (target
!= GL_RENDERBUFFER_EXT
) {
732 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
736 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
737 if (baseFormat
== 0) {
738 _mesa_error(ctx
, GL_INVALID_ENUM
,
739 "glRenderbufferStorageEXT(internalFormat)");
743 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
744 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
748 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
749 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
753 rb
= ctx
->CurrentRenderbuffer
;
756 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
760 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
762 if (rb
->InternalFormat
== internalFormat
&&
763 rb
->Width
== (GLuint
) width
&&
764 rb
->Height
== (GLuint
) height
) {
765 /* no change in allocation needed */
769 /* These MUST get set by the AllocStorage func */
770 rb
->_ActualFormat
= 0;
779 /* Now allocate the storage */
780 ASSERT(rb
->AllocStorage
);
781 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
782 /* No error - check/set fields now */
783 assert(rb
->_ActualFormat
);
784 assert(rb
->Width
== (GLuint
) width
);
785 assert(rb
->Height
== (GLuint
) height
);
786 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
787 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
788 rb
->InternalFormat
= internalFormat
;
789 rb
->_BaseFormat
= baseFormat
;
792 /* Probably ran out of memory - clear the fields */
795 rb
->InternalFormat
= GL_NONE
;
796 rb
->_ActualFormat
= GL_NONE
;
797 rb
->_BaseFormat
= GL_NONE
;
808 test_framebuffer_completeness(ctx, fb);
810 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
817 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
819 GET_CURRENT_CONTEXT(ctx
);
821 ASSERT_OUTSIDE_BEGIN_END(ctx
);
823 if (target
!= GL_RENDERBUFFER_EXT
) {
824 _mesa_error(ctx
, GL_INVALID_ENUM
,
825 "glGetRenderbufferParameterivEXT(target)");
829 if (!ctx
->CurrentRenderbuffer
) {
830 _mesa_error(ctx
, GL_INVALID_OPERATION
,
831 "glGetRenderbufferParameterivEXT");
835 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
838 case GL_RENDERBUFFER_WIDTH_EXT
:
839 *params
= ctx
->CurrentRenderbuffer
->Width
;
841 case GL_RENDERBUFFER_HEIGHT_EXT
:
842 *params
= ctx
->CurrentRenderbuffer
->Height
;
844 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
845 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
847 case GL_RENDERBUFFER_RED_SIZE_EXT
:
848 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
850 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
851 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
853 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
854 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
856 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
857 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
859 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
860 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
862 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
863 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
866 _mesa_error(ctx
, GL_INVALID_ENUM
,
867 "glGetRenderbufferParameterivEXT(target)");
874 _mesa_IsFramebufferEXT(GLuint framebuffer
)
876 GET_CURRENT_CONTEXT(ctx
);
877 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
879 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
880 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
888 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
891 ASSERT(ctx
->Driver
.RenderTexture
);
892 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
893 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
894 struct gl_texture_object
*texObj
= att
->Texture
;
896 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
897 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
904 * Examine all the framebuffer's attachments to see if any are textures.
905 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
906 * notify the device driver that the texture image may have changed.
909 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
911 if (ctx
->Driver
.FinishRenderTexture
) {
913 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
914 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
915 struct gl_texture_object
*texObj
= att
->Texture
;
917 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
925 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
927 struct gl_framebuffer
*newFb
, *newFbread
;
928 GLboolean bindReadBuf
, bindDrawBuf
;
929 GET_CURRENT_CONTEXT(ctx
);
931 ASSERT_OUTSIDE_BEGIN_END(ctx
);
933 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
934 _mesa_error(ctx
, GL_INVALID_OPERATION
,
935 "glBindFramebufferEXT(unsupported)");
940 #if FEATURE_EXT_framebuffer_blit
941 case GL_DRAW_FRAMEBUFFER_EXT
:
942 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
943 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
946 bindDrawBuf
= GL_TRUE
;
947 bindReadBuf
= GL_FALSE
;
949 case GL_READ_FRAMEBUFFER_EXT
:
950 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
951 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
954 bindDrawBuf
= GL_FALSE
;
955 bindReadBuf
= GL_TRUE
;
958 case GL_FRAMEBUFFER_EXT
:
959 bindDrawBuf
= GL_TRUE
;
960 bindReadBuf
= GL_TRUE
;
963 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
967 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
968 if (ctx
->Driver
.Flush
) {
969 ctx
->Driver
.Flush(ctx
);
972 /* Binding a user-created framebuffer object */
973 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
974 if (newFb
== &DummyFramebuffer
) {
975 /* ID was reserved, but no real framebuffer object made yet */
979 /* create new framebuffer object */
980 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
982 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
985 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
990 /* Binding the window system framebuffer (which was originally set
993 newFb
= ctx
->WinSysDrawBuffer
;
994 newFbread
= ctx
->WinSysReadBuffer
;
998 ASSERT(newFb
!= &DummyFramebuffer
);
1001 * XXX check if re-binding same buffer and skip some of this code.
1005 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1009 /* check if old FB had any texture attachments */
1010 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1011 /* check if time to delete this framebuffer */
1012 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1013 if (newFb
->Name
!= 0) {
1014 /* check if newly bound framebuffer has any texture attachments */
1015 check_begin_texture_render(ctx
, newFb
);
1019 if (ctx
->Driver
.BindFramebuffer
) {
1020 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1026 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1029 GET_CURRENT_CONTEXT(ctx
);
1031 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1032 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1033 /* The above doesn't fully flush the drivers in the way that a
1034 * glFlush does, but that is required here:
1036 if (ctx
->Driver
.Flush
)
1037 ctx
->Driver
.Flush(ctx
);
1039 for (i
= 0; i
< n
; i
++) {
1040 if (framebuffers
[i
] > 0) {
1041 struct gl_framebuffer
*fb
;
1042 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1044 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1046 /* check if deleting currently bound framebuffer object */
1047 if (fb
== ctx
->DrawBuffer
) {
1049 ASSERT(fb
->RefCount
>= 2);
1050 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1053 /* remove from hash table immediately, to free the ID */
1054 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1056 if (fb
!= &DummyFramebuffer
) {
1057 /* But the object will not be freed until it's no longer
1058 * bound in any context.
1060 _mesa_unreference_framebuffer(&fb
);
1069 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1071 GET_CURRENT_CONTEXT(ctx
);
1075 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1078 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1085 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1087 for (i
= 0; i
< n
; i
++) {
1088 GLuint name
= first
+ i
;
1089 framebuffers
[i
] = name
;
1090 /* insert dummy placeholder into hash table */
1091 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1092 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1093 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1100 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1102 struct gl_framebuffer
*buffer
;
1103 GET_CURRENT_CONTEXT(ctx
);
1105 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1108 #if FEATURE_EXT_framebuffer_blit
1109 case GL_DRAW_FRAMEBUFFER_EXT
:
1110 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1111 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1114 buffer
= ctx
->DrawBuffer
;
1116 case GL_READ_FRAMEBUFFER_EXT
:
1117 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1118 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1121 buffer
= ctx
->ReadBuffer
;
1124 case GL_FRAMEBUFFER_EXT
:
1125 buffer
= ctx
->DrawBuffer
;
1128 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1129 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1132 if (buffer
->Name
== 0) {
1133 /* The window system / default framebuffer is always complete */
1134 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1137 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1139 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1140 return buffer
->_Status
;
1146 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1149 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1150 GLenum attachment
, GLenum textarget
, GLuint texture
,
1151 GLint level
, GLint zoffset
)
1153 struct gl_renderbuffer_attachment
*att
;
1154 struct gl_texture_object
*texObj
= NULL
;
1155 struct gl_framebuffer
*fb
;
1157 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1159 if (target
!= GL_FRAMEBUFFER_EXT
) {
1160 _mesa_error(ctx
, GL_INVALID_ENUM
,
1161 "glFramebufferTexture%sEXT(target)", caller
);
1165 fb
= ctx
->DrawBuffer
;
1168 /* check framebuffer binding */
1169 if (fb
->Name
== 0) {
1170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1171 "glFramebufferTexture%sEXT", caller
);
1176 /* The textarget, level, and zoffset parameters are only validated if
1177 * texture is non-zero.
1180 GLboolean err
= GL_TRUE
;
1182 texObj
= _mesa_lookup_texture(ctx
, texture
);
1183 if (texObj
!= NULL
) {
1184 if (textarget
== 0) {
1185 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1186 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1187 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1190 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1191 ? !IS_CUBE_FACE(textarget
)
1192 : (texObj
->Target
!= textarget
);
1197 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1198 "glFramebufferTexture%sEXT(texture target mismatch)",
1203 if (texObj
->Target
== GL_TEXTURE_3D
) {
1204 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1205 if (zoffset
< 0 || zoffset
>= maxSize
) {
1206 _mesa_error(ctx
, GL_INVALID_VALUE
,
1207 "glFramebufferTexture%sEXT(zoffset)", caller
);
1211 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1212 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1213 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
,
1215 "glFramebufferTexture%sEXT(layer)", caller
);
1222 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1223 _mesa_error(ctx
, GL_INVALID_VALUE
,
1224 "glFramebufferTexture%sEXT(level)", caller
);
1229 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1231 _mesa_error(ctx
, GL_INVALID_ENUM
,
1232 "glFramebufferTexture%sEXT(attachment)", caller
);
1236 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1237 /* The above doesn't fully flush the drivers in the way that a
1238 * glFlush does, but that is required here:
1240 if (ctx
->Driver
.Flush
)
1241 ctx
->Driver
.Flush(ctx
);
1243 _glthread_LOCK_MUTEX(fb
->Mutex
);
1245 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1249 _mesa_remove_attachment(ctx
, att
);
1251 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1257 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1258 GLenum textarget
, GLuint texture
, GLint level
)
1260 GET_CURRENT_CONTEXT(ctx
);
1262 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1263 _mesa_error(ctx
, GL_INVALID_ENUM
,
1264 "glFramebufferTexture1DEXT(textarget)");
1268 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1274 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1275 GLenum textarget
, GLuint texture
, GLint level
)
1277 GET_CURRENT_CONTEXT(ctx
);
1279 if ((texture
!= 0) &&
1280 (textarget
!= GL_TEXTURE_2D
) &&
1281 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1282 (!IS_CUBE_FACE(textarget
))) {
1283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1284 "glFramebufferTexture2DEXT(textarget)");
1288 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1294 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1295 GLenum textarget
, GLuint texture
,
1296 GLint level
, GLint zoffset
)
1298 GET_CURRENT_CONTEXT(ctx
);
1300 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1301 _mesa_error(ctx
, GL_INVALID_ENUM
,
1302 "glFramebufferTexture3DEXT(textarget)");
1306 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1312 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1313 GLuint texture
, GLint level
, GLint layer
)
1315 GET_CURRENT_CONTEXT(ctx
);
1317 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1323 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1324 GLenum renderbufferTarget
,
1325 GLuint renderbuffer
)
1327 struct gl_renderbuffer_attachment
*att
;
1328 struct gl_framebuffer
*fb
;
1329 struct gl_renderbuffer
*rb
;
1330 GET_CURRENT_CONTEXT(ctx
);
1332 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1335 #if FEATURE_EXT_framebuffer_blit
1336 case GL_DRAW_FRAMEBUFFER_EXT
:
1337 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1338 _mesa_error(ctx
, GL_INVALID_ENUM
,
1339 "glFramebufferRenderbufferEXT(target)");
1342 fb
= ctx
->DrawBuffer
;
1344 case GL_READ_FRAMEBUFFER_EXT
:
1345 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1346 _mesa_error(ctx
, GL_INVALID_ENUM
,
1347 "glFramebufferRenderbufferEXT(target)");
1350 fb
= ctx
->ReadBuffer
;
1353 case GL_FRAMEBUFFER_EXT
:
1354 fb
= ctx
->DrawBuffer
;
1357 _mesa_error(ctx
, GL_INVALID_ENUM
,
1358 "glFramebufferRenderbufferEXT(target)");
1362 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1363 _mesa_error(ctx
, GL_INVALID_ENUM
,
1364 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1368 if (fb
->Name
== 0) {
1369 /* Can't attach new renderbuffers to a window system framebuffer */
1370 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1374 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1376 _mesa_error(ctx
, GL_INVALID_ENUM
,
1377 "glFramebufferRenderbufferEXT(attachment)");
1382 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1385 "glFramebufferRenderbufferEXT(renderbuffer)");
1390 /* remove renderbuffer attachment */
1394 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1395 /* The above doesn't fully flush the drivers in the way that a
1396 * glFlush does, but that is required here:
1398 if (ctx
->Driver
.Flush
)
1399 ctx
->Driver
.Flush(ctx
);
1401 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1402 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1404 /* Some subsequent GL commands may depend on the framebuffer's visual
1405 * after the binding is updated. Update visual info now.
1407 _mesa_update_framebuffer_visual(fb
);
1412 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1413 GLenum pname
, GLint
*params
)
1415 const struct gl_renderbuffer_attachment
*att
;
1416 struct gl_framebuffer
*buffer
;
1417 GET_CURRENT_CONTEXT(ctx
);
1419 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1422 #if FEATURE_EXT_framebuffer_blit
1423 case GL_DRAW_FRAMEBUFFER_EXT
:
1424 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1425 _mesa_error(ctx
, GL_INVALID_ENUM
,
1426 "glGetFramebufferAttachmentParameterivEXT(target)");
1429 buffer
= ctx
->DrawBuffer
;
1431 case GL_READ_FRAMEBUFFER_EXT
:
1432 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1433 _mesa_error(ctx
, GL_INVALID_ENUM
,
1434 "glGetFramebufferAttachmentParameterivEXT(target)");
1437 buffer
= ctx
->ReadBuffer
;
1440 case GL_FRAMEBUFFER_EXT
:
1441 buffer
= ctx
->DrawBuffer
;
1444 _mesa_error(ctx
, GL_INVALID_ENUM
,
1445 "glGetFramebufferAttachmentParameterivEXT(target)");
1449 if (buffer
->Name
== 0) {
1450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1451 "glGetFramebufferAttachmentParameterivEXT");
1455 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1457 _mesa_error(ctx
, GL_INVALID_ENUM
,
1458 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1462 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1463 /* The above doesn't fully flush the drivers in the way that a
1464 * glFlush does, but that is required here:
1466 if (ctx
->Driver
.Flush
)
1467 ctx
->Driver
.Flush(ctx
);
1470 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1471 *params
= att
->Type
;
1473 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1474 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1475 *params
= att
->Renderbuffer
->Name
;
1477 else if (att
->Type
== GL_TEXTURE
) {
1478 *params
= att
->Texture
->Name
;
1481 _mesa_error(ctx
, GL_INVALID_ENUM
,
1482 "glGetFramebufferAttachmentParameterivEXT(pname)");
1485 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1486 if (att
->Type
== GL_TEXTURE
) {
1487 *params
= att
->TextureLevel
;
1490 _mesa_error(ctx
, GL_INVALID_ENUM
,
1491 "glGetFramebufferAttachmentParameterivEXT(pname)");
1494 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1495 if (att
->Type
== GL_TEXTURE
) {
1496 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1499 _mesa_error(ctx
, GL_INVALID_ENUM
,
1500 "glGetFramebufferAttachmentParameterivEXT(pname)");
1503 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1504 if (att
->Type
== GL_TEXTURE
) {
1505 *params
= att
->Zoffset
;
1508 _mesa_error(ctx
, GL_INVALID_ENUM
,
1509 "glGetFramebufferAttachmentParameterivEXT(pname)");
1513 _mesa_error(ctx
, GL_INVALID_ENUM
,
1514 "glGetFramebufferAttachmentParameterivEXT(pname)");
1521 _mesa_GenerateMipmapEXT(GLenum target
)
1523 struct gl_texture_unit
*texUnit
;
1524 struct gl_texture_object
*texObj
;
1525 GET_CURRENT_CONTEXT(ctx
);
1527 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1528 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1534 case GL_TEXTURE_CUBE_MAP
:
1535 /* OK, legal value */
1538 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1542 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1543 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1545 /* XXX this might not handle cube maps correctly */
1546 _mesa_lock_texture(ctx
, texObj
);
1547 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1548 _mesa_unlock_texture(ctx
, texObj
);
1552 #if FEATURE_EXT_framebuffer_blit
1554 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1555 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1556 GLbitfield mask
, GLenum filter
)
1558 GET_CURRENT_CONTEXT(ctx
);
1560 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1561 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1563 if (ctx
->NewState
) {
1564 _mesa_update_state(ctx
);
1567 if (!ctx
->ReadBuffer
) {
1571 /* check for complete framebuffers */
1572 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1573 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1574 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1575 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1579 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1584 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1585 GL_DEPTH_BUFFER_BIT
|
1586 GL_STENCIL_BUFFER_BIT
)) {
1587 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1591 /* depth/stencil must be blitted with nearest filtering */
1592 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1593 && filter
!= GL_NEAREST
) {
1594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1595 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1599 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1600 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1601 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1602 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1604 "glBlitFramebufferEXT(stencil buffer size mismatch");
1609 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1610 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1611 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1612 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "glBlitFramebufferEXT(depth buffer size mismatch");
1619 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1620 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1624 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1625 ctx
->Driver
.BlitFramebuffer(ctx
,
1626 srcX0
, srcY0
, srcX1
, srcY1
,
1627 dstX0
, dstY0
, dstX1
, dstY1
,
1630 #endif /* FEATURE_EXT_framebuffer_blit */