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.
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 * Helper routine for getting a gl_renderbuffer.
72 struct gl_renderbuffer
*
73 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
75 struct gl_renderbuffer
*rb
;
80 rb
= (struct gl_renderbuffer
*)
81 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
87 * Helper routine for getting a gl_framebuffer.
89 struct gl_framebuffer
*
90 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
92 struct gl_framebuffer
*fb
;
97 fb
= (struct gl_framebuffer
*)
98 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
104 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
105 * gl_renderbuffer_attachment object.
107 struct gl_renderbuffer_attachment
*
108 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
113 switch (attachment
) {
114 case GL_COLOR_ATTACHMENT0_EXT
:
115 case GL_COLOR_ATTACHMENT1_EXT
:
116 case GL_COLOR_ATTACHMENT2_EXT
:
117 case GL_COLOR_ATTACHMENT3_EXT
:
118 case GL_COLOR_ATTACHMENT4_EXT
:
119 case GL_COLOR_ATTACHMENT5_EXT
:
120 case GL_COLOR_ATTACHMENT6_EXT
:
121 case GL_COLOR_ATTACHMENT7_EXT
:
122 case GL_COLOR_ATTACHMENT8_EXT
:
123 case GL_COLOR_ATTACHMENT9_EXT
:
124 case GL_COLOR_ATTACHMENT10_EXT
:
125 case GL_COLOR_ATTACHMENT11_EXT
:
126 case GL_COLOR_ATTACHMENT12_EXT
:
127 case GL_COLOR_ATTACHMENT13_EXT
:
128 case GL_COLOR_ATTACHMENT14_EXT
:
129 case GL_COLOR_ATTACHMENT15_EXT
:
130 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
131 if (i
>= ctx
->Const
.MaxColorAttachments
) {
134 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
135 case GL_DEPTH_ATTACHMENT_EXT
:
136 return &fb
->Attachment
[BUFFER_DEPTH
];
137 case GL_STENCIL_ATTACHMENT_EXT
:
138 return &fb
->Attachment
[BUFFER_STENCIL
];
146 * Remove any texture or renderbuffer attached to the given attachment
147 * point. Update reference counts, etc.
150 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
152 if (att
->Type
== GL_TEXTURE
) {
153 ASSERT(att
->Texture
);
154 att
->Texture
->RefCount
--;
155 if (att
->Texture
->RefCount
== 0) {
156 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
159 /* tell driver that we're done rendering to this texture. */
160 if (ctx
->Driver
.FinishRenderTexture
) {
161 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
166 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
167 ASSERT(att
->Renderbuffer
);
168 ASSERT(!att
->Texture
);
169 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
172 att
->Complete
= GL_TRUE
;
177 * Bind a texture object to an attachment point.
178 * The previous binding, if any, will be removed first.
181 _mesa_set_texture_attachment(GLcontext
*ctx
,
182 struct gl_framebuffer
*fb
,
183 struct gl_renderbuffer_attachment
*att
,
184 struct gl_texture_object
*texObj
,
185 GLenum texTarget
, GLuint level
, GLuint zoffset
)
187 if (att
->Texture
== texObj
) {
188 /* re-attaching same texture */
189 ASSERT(att
->Type
== GL_TEXTURE
);
193 _mesa_remove_attachment(ctx
, att
);
194 att
->Type
= GL_TEXTURE
;
195 att
->Texture
= texObj
;
199 /* always update these fields */
200 att
->TextureLevel
= level
;
201 if (IS_CUBE_FACE(texTarget
)) {
202 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
205 att
->CubeMapFace
= 0;
207 att
->Zoffset
= zoffset
;
208 att
->Complete
= GL_FALSE
;
210 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
211 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
217 * Bind a renderbuffer to an attachment point.
218 * The previous binding, if any, will be removed first.
221 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
222 struct gl_renderbuffer_attachment
*att
,
223 struct gl_renderbuffer
*rb
)
225 /* XXX check if re-doing same attachment, exit early */
226 _mesa_remove_attachment(ctx
, att
);
227 att
->Type
= GL_RENDERBUFFER_EXT
;
228 att
->Texture
= NULL
; /* just to be safe */
229 att
->Complete
= GL_FALSE
;
230 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
235 * Fallback for ctx->Driver.FramebufferRenderbuffer()
236 * Attach a renderbuffer object to a framebuffer object.
239 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
240 GLenum attachment
, struct gl_renderbuffer
*rb
)
242 struct gl_renderbuffer_attachment
*att
;
244 _glthread_LOCK_MUTEX(fb
->Mutex
);
246 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
249 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
252 _mesa_remove_attachment(ctx
, att
);
255 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
260 * Test if an attachment point is complete and update its Complete field.
261 * \param format if GL_COLOR, this is a color attachment point,
262 * if GL_DEPTH, this is a depth component attachment point,
263 * if GL_STENCIL, this is a stencil component attachment point.
266 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
267 struct gl_renderbuffer_attachment
*att
)
269 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
271 /* assume complete */
272 att
->Complete
= GL_TRUE
;
274 /* Look for reasons why the attachment might be incomplete */
275 if (att
->Type
== GL_TEXTURE
) {
276 const struct gl_texture_object
*texObj
= att
->Texture
;
277 struct gl_texture_image
*texImage
;
280 att
->Complete
= GL_FALSE
;
284 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
286 att
->Complete
= GL_FALSE
;
289 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
290 att
->Complete
= GL_FALSE
;
293 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
294 att
->Complete
= GL_FALSE
;
298 if (format
== GL_COLOR
) {
299 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
300 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
301 att
->Complete
= GL_FALSE
;
305 else if (format
== GL_DEPTH
) {
306 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
309 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
310 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
314 att
->Complete
= GL_FALSE
;
319 /* no such thing as stencil textures */
320 att
->Complete
= GL_FALSE
;
324 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
325 ASSERT(att
->Renderbuffer
);
326 if (!att
->Renderbuffer
->InternalFormat
||
327 att
->Renderbuffer
->Width
< 1 ||
328 att
->Renderbuffer
->Height
< 1) {
329 att
->Complete
= GL_FALSE
;
332 if (format
== GL_COLOR
) {
333 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
334 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
335 ASSERT(att
->Renderbuffer
->RedBits
);
336 ASSERT(att
->Renderbuffer
->GreenBits
);
337 ASSERT(att
->Renderbuffer
->BlueBits
);
338 att
->Complete
= GL_FALSE
;
342 else if (format
== GL_DEPTH
) {
343 ASSERT(att
->Renderbuffer
->DepthBits
);
344 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
347 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
348 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
352 att
->Complete
= GL_FALSE
;
357 assert(format
== GL_STENCIL
);
358 ASSERT(att
->Renderbuffer
->StencilBits
);
359 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
362 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
363 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
367 att
->Complete
= GL_FALSE
;
373 ASSERT(att
->Type
== GL_NONE
);
381 * Helpful for debugging
384 fbo_incomplete(const char *msg
, int index
)
389 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
395 * Test if the given framebuffer object is complete and update its
396 * Status field with the results.
397 * Also update the framebuffer's Width and Height fields if the
398 * framebuffer is complete.
401 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
403 GLuint numImages
, width
= 0, height
= 0;
404 GLenum intFormat
= GL_NONE
;
409 assert(fb
->Name
!= 0);
415 /* Start at -2 to more easily loop over all attachment points */
416 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
417 struct gl_renderbuffer_attachment
*att
;
421 att
= &fb
->Attachment
[BUFFER_DEPTH
];
422 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
423 if (!att
->Complete
) {
424 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
425 fbo_incomplete("depth attachment incomplete", -1);
430 att
= &fb
->Attachment
[BUFFER_STENCIL
];
431 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
432 if (!att
->Complete
) {
433 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
434 fbo_incomplete("stencil attachment incomplete", -1);
439 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
440 test_attachment_completeness(ctx
, GL_COLOR
, att
);
441 if (!att
->Complete
) {
442 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
443 fbo_incomplete("color attachment incomplete", i
);
448 if (att
->Type
== GL_TEXTURE
) {
449 const struct gl_texture_image
*texImg
450 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
453 f
= texImg
->_BaseFormat
;
455 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
456 && f
!= GL_DEPTH_STENCIL_EXT
) {
457 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
458 fbo_incomplete("texture attachment incomplete", -1);
462 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
463 w
= att
->Renderbuffer
->Width
;
464 h
= att
->Renderbuffer
->Height
;
465 f
= att
->Renderbuffer
->InternalFormat
;
469 assert(att
->Type
== GL_NONE
);
473 if (numImages
== 1) {
474 /* set required width, height and format */
481 /* check that width, height, format are same */
482 if (w
!= width
|| h
!= height
) {
483 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
484 fbo_incomplete("width or height mismatch", -1);
487 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
488 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
489 fbo_incomplete("format mismatch", -1);
495 /* Check that all DrawBuffers are present */
496 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
497 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
498 const struct gl_renderbuffer_attachment
*att
499 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
501 if (att
->Type
== GL_NONE
) {
502 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
503 fbo_incomplete("missing drawbuffer", j
);
509 /* Check that the ReadBuffer is present */
510 if (fb
->ColorReadBuffer
!= GL_NONE
) {
511 const struct gl_renderbuffer_attachment
*att
512 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
514 if (att
->Type
== GL_NONE
) {
515 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
516 fbo_incomplete("missing readbuffer", -1);
521 if (numImages
== 0) {
522 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
523 fbo_incomplete("no attachments", -1);
528 * If we get here, the framebuffer is complete!
530 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
537 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
539 GET_CURRENT_CONTEXT(ctx
);
540 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
542 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
543 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
551 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
553 struct gl_renderbuffer
*newRb
;
554 GET_CURRENT_CONTEXT(ctx
);
556 ASSERT_OUTSIDE_BEGIN_END(ctx
);
558 if (target
!= GL_RENDERBUFFER_EXT
) {
559 _mesa_error(ctx
, GL_INVALID_ENUM
,
560 "glBindRenderbufferEXT(target)");
564 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
565 /* The above doesn't fully flush the drivers in the way that a
566 * glFlush does, but that is required here:
568 if (ctx
->Driver
.Flush
)
569 ctx
->Driver
.Flush(ctx
);
573 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
574 if (newRb
== &DummyRenderbuffer
) {
575 /* ID was reserved, but no real renderbuffer object made yet */
579 /* create new renderbuffer object */
580 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
582 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
585 ASSERT(newRb
->AllocStorage
);
586 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
587 newRb
->RefCount
= 1; /* referenced by hash table */
594 ASSERT(newRb
!= &DummyRenderbuffer
);
596 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
601 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
604 GET_CURRENT_CONTEXT(ctx
);
606 ASSERT_OUTSIDE_BEGIN_END(ctx
);
607 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
609 for (i
= 0; i
< n
; i
++) {
610 if (renderbuffers
[i
] > 0) {
611 struct gl_renderbuffer
*rb
;
612 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
614 /* check if deleting currently bound renderbuffer object */
615 if (rb
== ctx
->CurrentRenderbuffer
) {
617 ASSERT(rb
->RefCount
>= 2);
618 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
621 /* Remove from hash table immediately, to free the ID.
622 * But the object will not be freed until it's no longer
623 * referenced anywhere else.
625 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
627 if (rb
!= &DummyRenderbuffer
) {
628 /* no longer referenced by hash table */
629 _mesa_reference_renderbuffer(&rb
, NULL
);
638 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
640 GET_CURRENT_CONTEXT(ctx
);
644 ASSERT_OUTSIDE_BEGIN_END(ctx
);
647 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
654 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
656 for (i
= 0; i
< n
; i
++) {
657 GLuint name
= first
+ i
;
658 renderbuffers
[i
] = name
;
659 /* insert dummy placeholder into hash table */
660 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
661 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
662 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
668 * Given an internal format token for a render buffer, return the
669 * corresponding base format.
670 * This is very similar to _mesa_base_tex_format() but the set of valid
671 * internal formats is somewhat different.
673 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
674 * GL_DEPTH_STENCIL_EXT or zero if error.
677 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
679 switch (internalFormat
) {
698 case GL_STENCIL_INDEX
:
699 case GL_STENCIL_INDEX1_EXT
:
700 case GL_STENCIL_INDEX4_EXT
:
701 case GL_STENCIL_INDEX8_EXT
:
702 case GL_STENCIL_INDEX16_EXT
:
703 return GL_STENCIL_INDEX
;
704 case GL_DEPTH_COMPONENT
:
705 case GL_DEPTH_COMPONENT16
:
706 case GL_DEPTH_COMPONENT24
:
707 case GL_DEPTH_COMPONENT32
:
708 return GL_DEPTH_COMPONENT
;
709 case GL_DEPTH_STENCIL_EXT
:
710 case GL_DEPTH24_STENCIL8_EXT
:
711 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
712 return GL_DEPTH_STENCIL_EXT
;
715 /* XXX add floating point formats eventually */
723 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
724 GLsizei width
, GLsizei height
)
726 struct gl_renderbuffer
*rb
;
728 GET_CURRENT_CONTEXT(ctx
);
730 ASSERT_OUTSIDE_BEGIN_END(ctx
);
732 if (target
!= GL_RENDERBUFFER_EXT
) {
733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
737 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
738 if (baseFormat
== 0) {
739 _mesa_error(ctx
, GL_INVALID_ENUM
,
740 "glRenderbufferStorageEXT(internalFormat)");
744 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
745 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
749 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
750 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
754 rb
= ctx
->CurrentRenderbuffer
;
757 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
761 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
763 if (rb
->InternalFormat
== internalFormat
&&
764 rb
->Width
== (GLuint
) width
&&
765 rb
->Height
== (GLuint
) height
) {
766 /* no change in allocation needed */
770 /* These MUST get set by the AllocStorage func */
771 rb
->_ActualFormat
= 0;
780 /* Now allocate the storage */
781 ASSERT(rb
->AllocStorage
);
782 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
783 /* No error - check/set fields now */
784 assert(rb
->_ActualFormat
);
785 assert(rb
->Width
== (GLuint
) width
);
786 assert(rb
->Height
== (GLuint
) height
);
787 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
788 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
789 rb
->InternalFormat
= internalFormat
;
790 rb
->_BaseFormat
= baseFormat
;
793 /* Probably ran out of memory - clear the fields */
796 rb
->InternalFormat
= GL_NONE
;
797 rb
->_ActualFormat
= GL_NONE
;
798 rb
->_BaseFormat
= GL_NONE
;
809 test_framebuffer_completeness(ctx, fb);
811 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
818 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
820 GET_CURRENT_CONTEXT(ctx
);
822 ASSERT_OUTSIDE_BEGIN_END(ctx
);
824 if (target
!= GL_RENDERBUFFER_EXT
) {
825 _mesa_error(ctx
, GL_INVALID_ENUM
,
826 "glGetRenderbufferParameterivEXT(target)");
830 if (!ctx
->CurrentRenderbuffer
) {
831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
832 "glGetRenderbufferParameterivEXT");
836 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
839 case GL_RENDERBUFFER_WIDTH_EXT
:
840 *params
= ctx
->CurrentRenderbuffer
->Width
;
842 case GL_RENDERBUFFER_HEIGHT_EXT
:
843 *params
= ctx
->CurrentRenderbuffer
->Height
;
845 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
846 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
848 case GL_RENDERBUFFER_RED_SIZE_EXT
:
849 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
851 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
852 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
854 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
855 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
857 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
858 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
860 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
861 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
863 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
864 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
867 _mesa_error(ctx
, GL_INVALID_ENUM
,
868 "glGetRenderbufferParameterivEXT(target)");
875 _mesa_IsFramebufferEXT(GLuint framebuffer
)
877 GET_CURRENT_CONTEXT(ctx
);
878 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
880 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
881 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
889 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
892 ASSERT(ctx
->Driver
.RenderTexture
);
893 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
894 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
895 struct gl_texture_object
*texObj
= att
->Texture
;
897 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
898 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
905 * Examine all the framebuffer's attachments to see if any are textures.
906 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
907 * notify the device driver that the texture image may have changed.
910 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
912 if (ctx
->Driver
.FinishRenderTexture
) {
914 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
915 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
916 if (att
->Texture
&& att
->Renderbuffer
) {
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.
1004 /* for window-framebuffers, re-initialize the fbo values, as they
1005 could be wrong (makecurrent with a new drawable while still a fbo
1006 was bound will lead to default init fbo values).
1007 note that therefore the context ReadBuffer/DrawBuffer values are not
1008 valid while fbo's are bound!!! */
1010 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1011 if (!newFbread
->Name
) {
1012 _mesa_readbuffer_update_fields(ctx
, ctx
->Pixel
.ReadBuffer
);
1017 /* check if old FB had any texture attachments */
1018 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1019 /* check if time to delete this framebuffer */
1020 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1023 GLenum buffers
[MAX_DRAW_BUFFERS
];
1024 for(i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1025 buffers
[i
] = ctx
->Color
.DrawBuffer
[i
];
1027 _mesa_drawbuffers(ctx
, ctx
->Const
.MaxDrawBuffers
, buffers
, NULL
);
1030 /* check if newly bound framebuffer has any texture attachments */
1031 check_begin_texture_render(ctx
, newFb
);
1035 if (ctx
->Driver
.BindFramebuffer
) {
1036 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1042 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1045 GET_CURRENT_CONTEXT(ctx
);
1047 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1048 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1049 /* The above doesn't fully flush the drivers in the way that a
1050 * glFlush does, but that is required here:
1052 if (ctx
->Driver
.Flush
)
1053 ctx
->Driver
.Flush(ctx
);
1055 for (i
= 0; i
< n
; i
++) {
1056 if (framebuffers
[i
] > 0) {
1057 struct gl_framebuffer
*fb
;
1058 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1060 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1062 /* check if deleting currently bound framebuffer object */
1063 if (fb
== ctx
->DrawBuffer
) {
1065 ASSERT(fb
->RefCount
>= 2);
1066 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1069 /* remove from hash table immediately, to free the ID */
1070 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1072 if (fb
!= &DummyFramebuffer
) {
1073 /* But the object will not be freed until it's no longer
1074 * bound in any context.
1076 _mesa_unreference_framebuffer(&fb
);
1085 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1087 GET_CURRENT_CONTEXT(ctx
);
1091 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1094 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1101 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1103 for (i
= 0; i
< n
; i
++) {
1104 GLuint name
= first
+ i
;
1105 framebuffers
[i
] = name
;
1106 /* insert dummy placeholder into hash table */
1107 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1108 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1109 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1116 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1118 struct gl_framebuffer
*buffer
;
1119 GET_CURRENT_CONTEXT(ctx
);
1121 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1124 #if FEATURE_EXT_framebuffer_blit
1125 case GL_DRAW_FRAMEBUFFER_EXT
:
1126 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1127 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1130 buffer
= ctx
->DrawBuffer
;
1132 case GL_READ_FRAMEBUFFER_EXT
:
1133 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1134 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1137 buffer
= ctx
->ReadBuffer
;
1140 case GL_FRAMEBUFFER_EXT
:
1141 buffer
= ctx
->DrawBuffer
;
1144 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1145 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1148 if (buffer
->Name
== 0) {
1149 /* The window system / default framebuffer is always complete */
1150 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1153 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1155 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1156 return buffer
->_Status
;
1162 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1165 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1166 GLenum attachment
, GLenum textarget
, GLuint texture
,
1167 GLint level
, GLint zoffset
)
1169 struct gl_renderbuffer_attachment
*att
;
1170 struct gl_texture_object
*texObj
= NULL
;
1171 struct gl_framebuffer
*fb
;
1173 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1175 if (target
!= GL_FRAMEBUFFER_EXT
) {
1176 _mesa_error(ctx
, GL_INVALID_ENUM
,
1177 "glFramebufferTexture%sEXT(target)", caller
);
1181 fb
= ctx
->DrawBuffer
;
1184 /* check framebuffer binding */
1185 if (fb
->Name
== 0) {
1186 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1187 "glFramebufferTexture%sEXT", caller
);
1192 /* The textarget, level, and zoffset parameters are only validated if
1193 * texture is non-zero.
1196 GLboolean err
= GL_TRUE
;
1198 texObj
= _mesa_lookup_texture(ctx
, texture
);
1199 if (texObj
!= NULL
) {
1200 if (textarget
== 0) {
1201 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1202 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1203 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1206 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1207 ? !IS_CUBE_FACE(textarget
)
1208 : (texObj
->Target
!= textarget
);
1213 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1214 "glFramebufferTexture%sEXT(texture target mismatch)",
1219 if (texObj
->Target
== GL_TEXTURE_3D
) {
1220 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1221 if (zoffset
< 0 || zoffset
>= maxSize
) {
1222 _mesa_error(ctx
, GL_INVALID_VALUE
,
1223 "glFramebufferTexture%sEXT(zoffset)", caller
);
1227 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1228 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1229 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1230 _mesa_error(ctx
, GL_INVALID_VALUE
,
1231 "glFramebufferTexture%sEXT(layer)", caller
);
1238 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1239 _mesa_error(ctx
, GL_INVALID_VALUE
,
1240 "glFramebufferTexture%sEXT(level)", caller
);
1245 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1247 _mesa_error(ctx
, GL_INVALID_ENUM
,
1248 "glFramebufferTexture%sEXT(attachment)", caller
);
1252 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1253 /* The above doesn't fully flush the drivers in the way that a
1254 * glFlush does, but that is required here:
1256 if (ctx
->Driver
.Flush
)
1257 ctx
->Driver
.Flush(ctx
);
1259 _glthread_LOCK_MUTEX(fb
->Mutex
);
1261 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1265 _mesa_remove_attachment(ctx
, att
);
1267 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1273 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1274 GLenum textarget
, GLuint texture
, GLint level
)
1276 GET_CURRENT_CONTEXT(ctx
);
1278 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1279 _mesa_error(ctx
, GL_INVALID_ENUM
,
1280 "glFramebufferTexture1DEXT(textarget)");
1284 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1290 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1291 GLenum textarget
, GLuint texture
, GLint level
)
1293 GET_CURRENT_CONTEXT(ctx
);
1295 if ((texture
!= 0) &&
1296 (textarget
!= GL_TEXTURE_2D
) &&
1297 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1298 (!IS_CUBE_FACE(textarget
))) {
1299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1300 "glFramebufferTexture2DEXT(textarget)");
1304 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1310 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1311 GLenum textarget
, GLuint texture
,
1312 GLint level
, GLint zoffset
)
1314 GET_CURRENT_CONTEXT(ctx
);
1316 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1317 _mesa_error(ctx
, GL_INVALID_ENUM
,
1318 "glFramebufferTexture3DEXT(textarget)");
1322 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1328 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1329 GLuint texture
, GLint level
, GLint layer
)
1331 GET_CURRENT_CONTEXT(ctx
);
1333 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1339 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1340 GLenum renderbufferTarget
,
1341 GLuint renderbuffer
)
1343 struct gl_renderbuffer_attachment
*att
;
1344 struct gl_framebuffer
*fb
;
1345 struct gl_renderbuffer
*rb
;
1346 GET_CURRENT_CONTEXT(ctx
);
1348 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1351 #if FEATURE_EXT_framebuffer_blit
1352 case GL_DRAW_FRAMEBUFFER_EXT
:
1353 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1354 _mesa_error(ctx
, GL_INVALID_ENUM
,
1355 "glFramebufferRenderbufferEXT(target)");
1358 fb
= ctx
->DrawBuffer
;
1360 case GL_READ_FRAMEBUFFER_EXT
:
1361 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1362 _mesa_error(ctx
, GL_INVALID_ENUM
,
1363 "glFramebufferRenderbufferEXT(target)");
1366 fb
= ctx
->ReadBuffer
;
1369 case GL_FRAMEBUFFER_EXT
:
1370 fb
= ctx
->DrawBuffer
;
1373 _mesa_error(ctx
, GL_INVALID_ENUM
,
1374 "glFramebufferRenderbufferEXT(target)");
1378 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1379 _mesa_error(ctx
, GL_INVALID_ENUM
,
1380 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1384 if (fb
->Name
== 0) {
1385 /* Can't attach new renderbuffers to a window system framebuffer */
1386 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1390 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1392 _mesa_error(ctx
, GL_INVALID_ENUM
,
1393 "glFramebufferRenderbufferEXT(attachment)");
1398 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1400 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1401 "glFramebufferRenderbufferEXT(renderbuffer)");
1406 /* remove renderbuffer attachment */
1410 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1411 /* The above doesn't fully flush the drivers in the way that a
1412 * glFlush does, but that is required here:
1414 if (ctx
->Driver
.Flush
)
1415 ctx
->Driver
.Flush(ctx
);
1417 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1418 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1420 /* Some subsequent GL commands may depend on the framebuffer's visual
1421 * after the binding is updated. Update visual info now.
1423 _mesa_update_framebuffer_visual(fb
);
1428 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1429 GLenum pname
, GLint
*params
)
1431 const struct gl_renderbuffer_attachment
*att
;
1432 struct gl_framebuffer
*buffer
;
1433 GET_CURRENT_CONTEXT(ctx
);
1435 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1438 #if FEATURE_EXT_framebuffer_blit
1439 case GL_DRAW_FRAMEBUFFER_EXT
:
1440 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1441 _mesa_error(ctx
, GL_INVALID_ENUM
,
1442 "glGetFramebufferAttachmentParameterivEXT(target)");
1445 buffer
= ctx
->DrawBuffer
;
1447 case GL_READ_FRAMEBUFFER_EXT
:
1448 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1449 _mesa_error(ctx
, GL_INVALID_ENUM
,
1450 "glGetFramebufferAttachmentParameterivEXT(target)");
1453 buffer
= ctx
->ReadBuffer
;
1456 case GL_FRAMEBUFFER_EXT
:
1457 buffer
= ctx
->DrawBuffer
;
1460 _mesa_error(ctx
, GL_INVALID_ENUM
,
1461 "glGetFramebufferAttachmentParameterivEXT(target)");
1465 if (buffer
->Name
== 0) {
1466 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1467 "glGetFramebufferAttachmentParameterivEXT");
1471 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1473 _mesa_error(ctx
, GL_INVALID_ENUM
,
1474 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1478 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1479 /* The above doesn't fully flush the drivers in the way that a
1480 * glFlush does, but that is required here:
1482 if (ctx
->Driver
.Flush
)
1483 ctx
->Driver
.Flush(ctx
);
1486 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1487 *params
= att
->Type
;
1489 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1490 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1491 *params
= att
->Renderbuffer
->Name
;
1493 else if (att
->Type
== GL_TEXTURE
) {
1494 *params
= att
->Texture
->Name
;
1497 _mesa_error(ctx
, GL_INVALID_ENUM
,
1498 "glGetFramebufferAttachmentParameterivEXT(pname)");
1501 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1502 if (att
->Type
== GL_TEXTURE
) {
1503 *params
= att
->TextureLevel
;
1506 _mesa_error(ctx
, GL_INVALID_ENUM
,
1507 "glGetFramebufferAttachmentParameterivEXT(pname)");
1510 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1511 if (att
->Type
== GL_TEXTURE
) {
1512 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1515 _mesa_error(ctx
, GL_INVALID_ENUM
,
1516 "glGetFramebufferAttachmentParameterivEXT(pname)");
1519 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1520 if (att
->Type
== GL_TEXTURE
) {
1521 *params
= att
->Zoffset
;
1524 _mesa_error(ctx
, GL_INVALID_ENUM
,
1525 "glGetFramebufferAttachmentParameterivEXT(pname)");
1529 _mesa_error(ctx
, GL_INVALID_ENUM
,
1530 "glGetFramebufferAttachmentParameterivEXT(pname)");
1537 _mesa_GenerateMipmapEXT(GLenum target
)
1539 struct gl_texture_unit
*texUnit
;
1540 struct gl_texture_object
*texObj
;
1541 GET_CURRENT_CONTEXT(ctx
);
1543 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1544 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1550 case GL_TEXTURE_CUBE_MAP
:
1551 /* OK, legal value */
1554 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1558 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1559 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1561 /* XXX this might not handle cube maps correctly */
1562 _mesa_lock_texture(ctx
, texObj
);
1563 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
1564 _mesa_unlock_texture(ctx
, texObj
);
1568 #if FEATURE_EXT_framebuffer_blit
1570 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1571 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1572 GLbitfield mask
, GLenum filter
)
1574 GET_CURRENT_CONTEXT(ctx
);
1576 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1577 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1579 if (ctx
->NewState
) {
1580 _mesa_update_state(ctx
);
1583 if (!ctx
->ReadBuffer
) {
1587 /* check for complete framebuffers */
1588 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1589 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1590 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1591 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1595 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1596 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1600 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1601 GL_DEPTH_BUFFER_BIT
|
1602 GL_STENCIL_BUFFER_BIT
)) {
1603 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1607 /* depth/stencil must be blitted with nearest filtering */
1608 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1609 && filter
!= GL_NEAREST
) {
1610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1611 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1615 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1616 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1617 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1618 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1619 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1620 "glBlitFramebufferEXT(stencil buffer size mismatch");
1625 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1626 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1627 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1628 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1629 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1630 "glBlitFramebufferEXT(depth buffer size mismatch");
1635 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1636 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1640 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1641 ctx
->Driver
.BlitFramebuffer(ctx
,
1642 srcX0
, srcY0
, srcX1
, srcY1
,
1643 dstX0
, dstY0
, dstX1
, dstY1
,
1646 #endif /* FEATURE_EXT_framebuffer_blit */