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 struct gl_texture_object
*texObj
= att
->Texture
;
918 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
926 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
928 struct gl_framebuffer
*newFb
, *newFbread
;
929 GLboolean bindReadBuf
, bindDrawBuf
;
930 GET_CURRENT_CONTEXT(ctx
);
932 ASSERT_OUTSIDE_BEGIN_END(ctx
);
934 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
936 "glBindFramebufferEXT(unsupported)");
941 #if FEATURE_EXT_framebuffer_blit
942 case GL_DRAW_FRAMEBUFFER_EXT
:
943 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
944 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
947 bindDrawBuf
= GL_TRUE
;
948 bindReadBuf
= GL_FALSE
;
950 case GL_READ_FRAMEBUFFER_EXT
:
951 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
952 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
955 bindDrawBuf
= GL_FALSE
;
956 bindReadBuf
= GL_TRUE
;
959 case GL_FRAMEBUFFER_EXT
:
960 bindDrawBuf
= GL_TRUE
;
961 bindReadBuf
= GL_TRUE
;
964 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
968 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
969 if (ctx
->Driver
.Flush
) {
970 ctx
->Driver
.Flush(ctx
);
973 /* Binding a user-created framebuffer object */
974 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
975 if (newFb
== &DummyFramebuffer
) {
976 /* ID was reserved, but no real framebuffer object made yet */
980 /* create new framebuffer object */
981 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
983 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
986 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
991 /* Binding the window system framebuffer (which was originally set
994 newFb
= ctx
->WinSysDrawBuffer
;
995 newFbread
= ctx
->WinSysReadBuffer
;
999 ASSERT(newFb
!= &DummyFramebuffer
);
1002 * XXX check if re-binding same buffer and skip some of this code.
1005 /* for window-framebuffers, re-initialize the fbo values, as they
1006 could be wrong (makecurrent with a new drawable while still a fbo
1007 was bound will lead to default init fbo values).
1008 note that therefore the context ReadBuffer/DrawBuffer values are not
1009 valid while fbo's are bound!!! */
1011 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1012 if (!newFbread
->Name
) {
1013 _mesa_readbuffer_update_fields(ctx
, ctx
->Pixel
.ReadBuffer
);
1018 /* check if old FB had any texture attachments */
1019 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1020 /* check if time to delete this framebuffer */
1021 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1024 GLenum buffers
[MAX_DRAW_BUFFERS
];
1025 for(i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1026 buffers
[i
] = ctx
->Color
.DrawBuffer
[i
];
1028 _mesa_drawbuffers(ctx
, ctx
->Const
.MaxDrawBuffers
, buffers
, NULL
);
1031 /* check if newly bound framebuffer has any texture attachments */
1032 check_begin_texture_render(ctx
, newFb
);
1036 if (ctx
->Driver
.BindFramebuffer
) {
1037 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1043 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1046 GET_CURRENT_CONTEXT(ctx
);
1048 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1049 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1050 /* The above doesn't fully flush the drivers in the way that a
1051 * glFlush does, but that is required here:
1053 if (ctx
->Driver
.Flush
)
1054 ctx
->Driver
.Flush(ctx
);
1056 for (i
= 0; i
< n
; i
++) {
1057 if (framebuffers
[i
] > 0) {
1058 struct gl_framebuffer
*fb
;
1059 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1061 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1063 /* check if deleting currently bound framebuffer object */
1064 if (fb
== ctx
->DrawBuffer
) {
1066 ASSERT(fb
->RefCount
>= 2);
1067 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1070 /* remove from hash table immediately, to free the ID */
1071 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1073 if (fb
!= &DummyFramebuffer
) {
1074 /* But the object will not be freed until it's no longer
1075 * bound in any context.
1077 _mesa_unreference_framebuffer(&fb
);
1086 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1088 GET_CURRENT_CONTEXT(ctx
);
1092 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1095 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1102 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1104 for (i
= 0; i
< n
; i
++) {
1105 GLuint name
= first
+ i
;
1106 framebuffers
[i
] = name
;
1107 /* insert dummy placeholder into hash table */
1108 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1109 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1110 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1117 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1119 struct gl_framebuffer
*buffer
;
1120 GET_CURRENT_CONTEXT(ctx
);
1122 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1125 #if FEATURE_EXT_framebuffer_blit
1126 case GL_DRAW_FRAMEBUFFER_EXT
:
1127 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1128 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1131 buffer
= ctx
->DrawBuffer
;
1133 case GL_READ_FRAMEBUFFER_EXT
:
1134 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1135 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1138 buffer
= ctx
->ReadBuffer
;
1141 case GL_FRAMEBUFFER_EXT
:
1142 buffer
= ctx
->DrawBuffer
;
1145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1146 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1149 if (buffer
->Name
== 0) {
1150 /* The window system / default framebuffer is always complete */
1151 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1154 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1156 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1157 return buffer
->_Status
;
1163 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1166 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1167 GLenum attachment
, GLenum textarget
, GLuint texture
,
1168 GLint level
, GLint zoffset
)
1170 struct gl_renderbuffer_attachment
*att
;
1171 struct gl_texture_object
*texObj
= NULL
;
1172 struct gl_framebuffer
*fb
;
1174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1176 if (target
!= GL_FRAMEBUFFER_EXT
) {
1177 _mesa_error(ctx
, GL_INVALID_ENUM
,
1178 "glFramebufferTexture%sEXT(target)", caller
);
1182 fb
= ctx
->DrawBuffer
;
1185 /* check framebuffer binding */
1186 if (fb
->Name
== 0) {
1187 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1188 "glFramebufferTexture%sEXT", caller
);
1193 /* The textarget, level, and zoffset parameters are only validated if
1194 * texture is non-zero.
1197 GLboolean err
= GL_TRUE
;
1199 texObj
= _mesa_lookup_texture(ctx
, texture
);
1200 if (texObj
!= NULL
) {
1201 if (textarget
== 0) {
1202 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1203 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1204 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1207 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1208 ? !IS_CUBE_FACE(textarget
)
1209 : (texObj
->Target
!= textarget
);
1214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1215 "glFramebufferTexture%sEXT(texture target mismatch)",
1220 if (texObj
->Target
== GL_TEXTURE_3D
) {
1221 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1222 if (zoffset
< 0 || zoffset
>= maxSize
) {
1223 _mesa_error(ctx
, GL_INVALID_VALUE
,
1224 "glFramebufferTexture%sEXT(zoffset)", caller
);
1228 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1229 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1230 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1231 _mesa_error(ctx
, GL_INVALID_VALUE
,
1232 "glFramebufferTexture%sEXT(layer)", caller
);
1239 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1240 _mesa_error(ctx
, GL_INVALID_VALUE
,
1241 "glFramebufferTexture%sEXT(level)", caller
);
1246 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1248 _mesa_error(ctx
, GL_INVALID_ENUM
,
1249 "glFramebufferTexture%sEXT(attachment)", caller
);
1253 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1254 /* The above doesn't fully flush the drivers in the way that a
1255 * glFlush does, but that is required here:
1257 if (ctx
->Driver
.Flush
)
1258 ctx
->Driver
.Flush(ctx
);
1260 _glthread_LOCK_MUTEX(fb
->Mutex
);
1262 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1266 _mesa_remove_attachment(ctx
, att
);
1268 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1274 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1275 GLenum textarget
, GLuint texture
, GLint level
)
1277 GET_CURRENT_CONTEXT(ctx
);
1279 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1280 _mesa_error(ctx
, GL_INVALID_ENUM
,
1281 "glFramebufferTexture1DEXT(textarget)");
1285 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1291 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1292 GLenum textarget
, GLuint texture
, GLint level
)
1294 GET_CURRENT_CONTEXT(ctx
);
1296 if ((texture
!= 0) &&
1297 (textarget
!= GL_TEXTURE_2D
) &&
1298 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1299 (!IS_CUBE_FACE(textarget
))) {
1300 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1301 "glFramebufferTexture2DEXT(textarget)");
1305 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1311 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1312 GLenum textarget
, GLuint texture
,
1313 GLint level
, GLint zoffset
)
1315 GET_CURRENT_CONTEXT(ctx
);
1317 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1318 _mesa_error(ctx
, GL_INVALID_ENUM
,
1319 "glFramebufferTexture3DEXT(textarget)");
1323 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1329 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1330 GLuint texture
, GLint level
, GLint layer
)
1332 GET_CURRENT_CONTEXT(ctx
);
1334 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1340 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1341 GLenum renderbufferTarget
,
1342 GLuint renderbuffer
)
1344 struct gl_renderbuffer_attachment
*att
;
1345 struct gl_framebuffer
*fb
;
1346 struct gl_renderbuffer
*rb
;
1347 GET_CURRENT_CONTEXT(ctx
);
1349 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1352 #if FEATURE_EXT_framebuffer_blit
1353 case GL_DRAW_FRAMEBUFFER_EXT
:
1354 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1355 _mesa_error(ctx
, GL_INVALID_ENUM
,
1356 "glFramebufferRenderbufferEXT(target)");
1359 fb
= ctx
->DrawBuffer
;
1361 case GL_READ_FRAMEBUFFER_EXT
:
1362 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1363 _mesa_error(ctx
, GL_INVALID_ENUM
,
1364 "glFramebufferRenderbufferEXT(target)");
1367 fb
= ctx
->ReadBuffer
;
1370 case GL_FRAMEBUFFER_EXT
:
1371 fb
= ctx
->DrawBuffer
;
1374 _mesa_error(ctx
, GL_INVALID_ENUM
,
1375 "glFramebufferRenderbufferEXT(target)");
1379 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1380 _mesa_error(ctx
, GL_INVALID_ENUM
,
1381 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1385 if (fb
->Name
== 0) {
1386 /* Can't attach new renderbuffers to a window system framebuffer */
1387 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1391 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1393 _mesa_error(ctx
, GL_INVALID_ENUM
,
1394 "glFramebufferRenderbufferEXT(attachment)");
1399 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1401 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1402 "glFramebufferRenderbufferEXT(renderbuffer)");
1407 /* remove renderbuffer attachment */
1411 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1412 /* The above doesn't fully flush the drivers in the way that a
1413 * glFlush does, but that is required here:
1415 if (ctx
->Driver
.Flush
)
1416 ctx
->Driver
.Flush(ctx
);
1418 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1419 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1421 /* Some subsequent GL commands may depend on the framebuffer's visual
1422 * after the binding is updated. Update visual info now.
1424 _mesa_update_framebuffer_visual(fb
);
1429 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1430 GLenum pname
, GLint
*params
)
1432 const struct gl_renderbuffer_attachment
*att
;
1433 struct gl_framebuffer
*buffer
;
1434 GET_CURRENT_CONTEXT(ctx
);
1436 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1439 #if FEATURE_EXT_framebuffer_blit
1440 case GL_DRAW_FRAMEBUFFER_EXT
:
1441 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1442 _mesa_error(ctx
, GL_INVALID_ENUM
,
1443 "glGetFramebufferAttachmentParameterivEXT(target)");
1446 buffer
= ctx
->DrawBuffer
;
1448 case GL_READ_FRAMEBUFFER_EXT
:
1449 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glGetFramebufferAttachmentParameterivEXT(target)");
1454 buffer
= ctx
->ReadBuffer
;
1457 case GL_FRAMEBUFFER_EXT
:
1458 buffer
= ctx
->DrawBuffer
;
1461 _mesa_error(ctx
, GL_INVALID_ENUM
,
1462 "glGetFramebufferAttachmentParameterivEXT(target)");
1466 if (buffer
->Name
== 0) {
1467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1468 "glGetFramebufferAttachmentParameterivEXT");
1472 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1474 _mesa_error(ctx
, GL_INVALID_ENUM
,
1475 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1479 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1480 /* The above doesn't fully flush the drivers in the way that a
1481 * glFlush does, but that is required here:
1483 if (ctx
->Driver
.Flush
)
1484 ctx
->Driver
.Flush(ctx
);
1487 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1488 *params
= att
->Type
;
1490 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1491 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1492 *params
= att
->Renderbuffer
->Name
;
1494 else if (att
->Type
== GL_TEXTURE
) {
1495 *params
= att
->Texture
->Name
;
1498 _mesa_error(ctx
, GL_INVALID_ENUM
,
1499 "glGetFramebufferAttachmentParameterivEXT(pname)");
1502 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1503 if (att
->Type
== GL_TEXTURE
) {
1504 *params
= att
->TextureLevel
;
1507 _mesa_error(ctx
, GL_INVALID_ENUM
,
1508 "glGetFramebufferAttachmentParameterivEXT(pname)");
1511 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1512 if (att
->Type
== GL_TEXTURE
) {
1513 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1516 _mesa_error(ctx
, GL_INVALID_ENUM
,
1517 "glGetFramebufferAttachmentParameterivEXT(pname)");
1520 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1521 if (att
->Type
== GL_TEXTURE
) {
1522 *params
= att
->Zoffset
;
1525 _mesa_error(ctx
, GL_INVALID_ENUM
,
1526 "glGetFramebufferAttachmentParameterivEXT(pname)");
1530 _mesa_error(ctx
, GL_INVALID_ENUM
,
1531 "glGetFramebufferAttachmentParameterivEXT(pname)");
1538 _mesa_GenerateMipmapEXT(GLenum target
)
1540 struct gl_texture_unit
*texUnit
;
1541 struct gl_texture_object
*texObj
;
1542 GET_CURRENT_CONTEXT(ctx
);
1544 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1545 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1551 case GL_TEXTURE_CUBE_MAP
:
1552 /* OK, legal value */
1555 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1559 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1560 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1562 /* XXX this might not handle cube maps correctly */
1563 _mesa_lock_texture(ctx
, texObj
);
1564 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1565 _mesa_unlock_texture(ctx
, texObj
);
1569 #if FEATURE_EXT_framebuffer_blit
1571 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1572 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1573 GLbitfield mask
, GLenum filter
)
1575 GET_CURRENT_CONTEXT(ctx
);
1577 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1578 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1580 if (ctx
->NewState
) {
1581 _mesa_update_state(ctx
);
1584 if (!ctx
->ReadBuffer
) {
1588 /* check for complete framebuffers */
1589 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1590 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1591 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1592 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1596 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1597 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1601 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1602 GL_DEPTH_BUFFER_BIT
|
1603 GL_STENCIL_BUFFER_BIT
)) {
1604 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1608 /* depth/stencil must be blitted with nearest filtering */
1609 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1610 && filter
!= GL_NEAREST
) {
1611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1612 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1616 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1617 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1618 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1619 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1620 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1621 "glBlitFramebufferEXT(stencil buffer size mismatch");
1626 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1627 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1628 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1629 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1631 "glBlitFramebufferEXT(depth buffer size mismatch");
1636 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1637 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1641 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1642 ctx
->Driver
.BlitFramebuffer(ctx
,
1643 srcX0
, srcY0
, srcX1
, srcY1
,
1644 dstX0
, dstY0
, dstX1
, dstY1
,
1647 #endif /* FEATURE_EXT_framebuffer_blit */