2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #include "framebuffer.h"
38 #include "renderbuffer.h"
48 * None of the GL_EXT_framebuffer_object functions are compiled into
55 * When glGenRender/FramebuffersEXT() is called we insert pointers to
56 * these placeholder objects into the hash table.
57 * Later, when the object ID is first bound, we replace the placeholder
58 * with the real frame/renderbuffer.
60 static struct gl_framebuffer DummyFramebuffer
;
61 static struct gl_renderbuffer DummyRenderbuffer
;
64 #define IS_CUBE_FACE(TARGET) \
65 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
66 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
70 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
76 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
83 _mesa_init_fbobjects(GLcontext
*ctx
)
85 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
86 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
91 * Helper routine for getting a gl_renderbuffer.
93 struct gl_renderbuffer
*
94 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
96 struct gl_renderbuffer
*rb
;
101 rb
= (struct gl_renderbuffer
*)
102 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
108 * Helper routine for getting a gl_framebuffer.
110 struct gl_framebuffer
*
111 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
113 struct gl_framebuffer
*fb
;
118 fb
= (struct gl_framebuffer
*)
119 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
125 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
126 * gl_renderbuffer_attachment object.
128 struct gl_renderbuffer_attachment
*
129 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
134 switch (attachment
) {
135 case GL_COLOR_ATTACHMENT0_EXT
:
136 case GL_COLOR_ATTACHMENT1_EXT
:
137 case GL_COLOR_ATTACHMENT2_EXT
:
138 case GL_COLOR_ATTACHMENT3_EXT
:
139 case GL_COLOR_ATTACHMENT4_EXT
:
140 case GL_COLOR_ATTACHMENT5_EXT
:
141 case GL_COLOR_ATTACHMENT6_EXT
:
142 case GL_COLOR_ATTACHMENT7_EXT
:
143 case GL_COLOR_ATTACHMENT8_EXT
:
144 case GL_COLOR_ATTACHMENT9_EXT
:
145 case GL_COLOR_ATTACHMENT10_EXT
:
146 case GL_COLOR_ATTACHMENT11_EXT
:
147 case GL_COLOR_ATTACHMENT12_EXT
:
148 case GL_COLOR_ATTACHMENT13_EXT
:
149 case GL_COLOR_ATTACHMENT14_EXT
:
150 case GL_COLOR_ATTACHMENT15_EXT
:
151 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
152 if (i
>= ctx
->Const
.MaxColorAttachments
) {
155 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
156 case GL_DEPTH_ATTACHMENT_EXT
:
157 return &fb
->Attachment
[BUFFER_DEPTH
];
158 case GL_STENCIL_ATTACHMENT_EXT
:
159 return &fb
->Attachment
[BUFFER_STENCIL
];
167 * Remove any texture or renderbuffer attached to the given attachment
168 * point. Update reference counts, etc.
171 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
173 if (att
->Type
== GL_TEXTURE
) {
174 ASSERT(att
->Texture
);
175 if (ctx
->Driver
.FinishRenderTexture
) {
176 /* tell driver we're done rendering to this texobj */
177 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
179 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
180 ASSERT(!att
->Texture
);
182 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
183 ASSERT(att
->Renderbuffer
);
184 ASSERT(!att
->Texture
);
185 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
186 ASSERT(!att
->Renderbuffer
);
189 att
->Complete
= GL_TRUE
;
194 * Bind a texture object to an attachment point.
195 * The previous binding, if any, will be removed first.
198 _mesa_set_texture_attachment(GLcontext
*ctx
,
199 struct gl_framebuffer
*fb
,
200 struct gl_renderbuffer_attachment
*att
,
201 struct gl_texture_object
*texObj
,
202 GLenum texTarget
, GLuint level
, GLuint zoffset
)
204 if (att
->Texture
== texObj
) {
205 /* re-attaching same texture */
206 ASSERT(att
->Type
== GL_TEXTURE
);
210 _mesa_remove_attachment(ctx
, att
);
211 att
->Type
= GL_TEXTURE
;
212 assert(!att
->Texture
);
213 _mesa_reference_texobj(&att
->Texture
, texObj
);
216 /* always update these fields */
217 att
->TextureLevel
= level
;
218 if (IS_CUBE_FACE(texTarget
)) {
219 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
222 att
->CubeMapFace
= 0;
224 att
->Zoffset
= zoffset
;
225 att
->Complete
= GL_FALSE
;
227 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
228 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
234 * Bind a renderbuffer to an attachment point.
235 * The previous binding, if any, will be removed first.
238 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
239 struct gl_renderbuffer_attachment
*att
,
240 struct gl_renderbuffer
*rb
)
242 /* XXX check if re-doing same attachment, exit early */
243 _mesa_remove_attachment(ctx
, att
);
244 att
->Type
= GL_RENDERBUFFER_EXT
;
245 att
->Texture
= NULL
; /* just to be safe */
246 att
->Complete
= GL_FALSE
;
247 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
252 * Fallback for ctx->Driver.FramebufferRenderbuffer()
253 * Attach a renderbuffer object to a framebuffer object.
256 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
257 GLenum attachment
, struct gl_renderbuffer
*rb
)
259 struct gl_renderbuffer_attachment
*att
;
261 _glthread_LOCK_MUTEX(fb
->Mutex
);
263 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
266 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
269 _mesa_remove_attachment(ctx
, att
);
272 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
277 * Test if an attachment point is complete and update its Complete field.
278 * \param format if GL_COLOR, this is a color attachment point,
279 * if GL_DEPTH, this is a depth component attachment point,
280 * if GL_STENCIL, this is a stencil component attachment point.
283 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
284 struct gl_renderbuffer_attachment
*att
)
286 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
288 /* assume complete */
289 att
->Complete
= GL_TRUE
;
291 /* Look for reasons why the attachment might be incomplete */
292 if (att
->Type
== GL_TEXTURE
) {
293 const struct gl_texture_object
*texObj
= att
->Texture
;
294 struct gl_texture_image
*texImage
;
297 att
->Complete
= GL_FALSE
;
301 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
303 att
->Complete
= GL_FALSE
;
306 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
307 att
->Complete
= GL_FALSE
;
310 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
311 att
->Complete
= GL_FALSE
;
315 if (format
== GL_COLOR
) {
316 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
317 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
318 att
->Complete
= GL_FALSE
;
322 else if (format
== GL_DEPTH
) {
323 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
326 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
327 texImage
->TexFormat
->BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
331 att
->Complete
= GL_FALSE
;
336 /* no such thing as stencil textures */
337 att
->Complete
= GL_FALSE
;
341 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
342 ASSERT(att
->Renderbuffer
);
343 if (!att
->Renderbuffer
->InternalFormat
||
344 att
->Renderbuffer
->Width
< 1 ||
345 att
->Renderbuffer
->Height
< 1) {
346 att
->Complete
= GL_FALSE
;
349 if (format
== GL_COLOR
) {
350 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
351 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
352 ASSERT(att
->Renderbuffer
->RedBits
);
353 ASSERT(att
->Renderbuffer
->GreenBits
);
354 ASSERT(att
->Renderbuffer
->BlueBits
);
355 att
->Complete
= GL_FALSE
;
359 else if (format
== GL_DEPTH
) {
360 ASSERT(att
->Renderbuffer
->DepthBits
);
361 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
364 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
365 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
369 att
->Complete
= GL_FALSE
;
374 assert(format
== GL_STENCIL
);
375 ASSERT(att
->Renderbuffer
->StencilBits
);
376 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
379 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
380 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
384 att
->Complete
= GL_FALSE
;
390 ASSERT(att
->Type
== GL_NONE
);
398 * Helpful for debugging
401 fbo_incomplete(const char *msg
, int index
)
406 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
412 * Test if the given framebuffer object is complete and update its
413 * Status field with the results.
414 * Also update the framebuffer's Width and Height fields if the
415 * framebuffer is complete.
418 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
420 GLuint numImages
, width
= 0, height
= 0;
421 GLenum intFormat
= GL_NONE
;
426 assert(fb
->Name
!= 0);
432 /* Start at -2 to more easily loop over all attachment points */
433 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
434 struct gl_renderbuffer_attachment
*att
;
438 att
= &fb
->Attachment
[BUFFER_DEPTH
];
439 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
440 if (!att
->Complete
) {
441 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
442 fbo_incomplete("depth attachment incomplete", -1);
447 att
= &fb
->Attachment
[BUFFER_STENCIL
];
448 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
449 if (!att
->Complete
) {
450 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
451 fbo_incomplete("stencil attachment incomplete", -1);
456 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
457 test_attachment_completeness(ctx
, GL_COLOR
, att
);
458 if (!att
->Complete
) {
459 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
460 fbo_incomplete("color attachment incomplete", i
);
465 if (att
->Type
== GL_TEXTURE
) {
466 const struct gl_texture_image
*texImg
467 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
470 f
= texImg
->_BaseFormat
;
472 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
473 && f
!= GL_DEPTH_STENCIL_EXT
) {
474 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
475 fbo_incomplete("texture attachment incomplete", -1);
479 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
480 w
= att
->Renderbuffer
->Width
;
481 h
= att
->Renderbuffer
->Height
;
482 f
= att
->Renderbuffer
->InternalFormat
;
486 assert(att
->Type
== GL_NONE
);
490 if (numImages
== 1) {
491 /* set required width, height and format */
498 /* check that width, height, format are same */
499 if (w
!= width
|| h
!= height
) {
500 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
501 fbo_incomplete("width or height mismatch", -1);
504 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
505 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
506 fbo_incomplete("format mismatch", -1);
512 /* Check that all DrawBuffers are present */
513 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
514 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
515 const struct gl_renderbuffer_attachment
*att
516 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
518 if (att
->Type
== GL_NONE
) {
519 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
520 fbo_incomplete("missing drawbuffer", j
);
526 /* Check that the ReadBuffer is present */
527 if (fb
->ColorReadBuffer
!= GL_NONE
) {
528 const struct gl_renderbuffer_attachment
*att
529 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
531 if (att
->Type
== GL_NONE
) {
532 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
533 fbo_incomplete("missing readbuffer", -1);
538 if (numImages
== 0) {
539 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
540 fbo_incomplete("no attachments", -1);
545 * If we get here, the framebuffer is complete!
547 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
554 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
556 GET_CURRENT_CONTEXT(ctx
);
557 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
559 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
560 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
568 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
570 struct gl_renderbuffer
*newRb
;
571 GET_CURRENT_CONTEXT(ctx
);
573 ASSERT_OUTSIDE_BEGIN_END(ctx
);
575 if (target
!= GL_RENDERBUFFER_EXT
) {
576 _mesa_error(ctx
, GL_INVALID_ENUM
,
577 "glBindRenderbufferEXT(target)");
581 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
582 /* The above doesn't fully flush the drivers in the way that a
583 * glFlush does, but that is required here:
585 if (ctx
->Driver
.Flush
)
586 ctx
->Driver
.Flush(ctx
);
590 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
591 if (newRb
== &DummyRenderbuffer
) {
592 /* ID was reserved, but no real renderbuffer object made yet */
596 /* create new renderbuffer object */
597 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
599 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
602 ASSERT(newRb
->AllocStorage
);
603 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
604 newRb
->RefCount
= 1; /* referenced by hash table */
611 ASSERT(newRb
!= &DummyRenderbuffer
);
613 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
618 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
621 GET_CURRENT_CONTEXT(ctx
);
623 ASSERT_OUTSIDE_BEGIN_END(ctx
);
624 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
626 for (i
= 0; i
< n
; i
++) {
627 if (renderbuffers
[i
] > 0) {
628 struct gl_renderbuffer
*rb
;
629 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
631 /* check if deleting currently bound renderbuffer object */
632 if (rb
== ctx
->CurrentRenderbuffer
) {
634 ASSERT(rb
->RefCount
>= 2);
635 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
638 /* Remove from hash table immediately, to free the ID.
639 * But the object will not be freed until it's no longer
640 * referenced anywhere else.
642 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
644 if (rb
!= &DummyRenderbuffer
) {
645 /* no longer referenced by hash table */
646 _mesa_reference_renderbuffer(&rb
, NULL
);
655 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
657 GET_CURRENT_CONTEXT(ctx
);
661 ASSERT_OUTSIDE_BEGIN_END(ctx
);
664 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
671 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
673 for (i
= 0; i
< n
; i
++) {
674 GLuint name
= first
+ i
;
675 renderbuffers
[i
] = name
;
676 /* insert dummy placeholder into hash table */
677 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
678 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
679 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
685 * Given an internal format token for a render buffer, return the
686 * corresponding base format.
687 * This is very similar to _mesa_base_tex_format() but the set of valid
688 * internal formats is somewhat different.
690 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
691 * GL_DEPTH_STENCIL_EXT or zero if error.
694 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
696 switch (internalFormat
) {
715 case GL_STENCIL_INDEX
:
716 case GL_STENCIL_INDEX1_EXT
:
717 case GL_STENCIL_INDEX4_EXT
:
718 case GL_STENCIL_INDEX8_EXT
:
719 case GL_STENCIL_INDEX16_EXT
:
720 return GL_STENCIL_INDEX
;
721 case GL_DEPTH_COMPONENT
:
722 case GL_DEPTH_COMPONENT16
:
723 case GL_DEPTH_COMPONENT24
:
724 case GL_DEPTH_COMPONENT32
:
725 return GL_DEPTH_COMPONENT
;
726 case GL_DEPTH_STENCIL_EXT
:
727 case GL_DEPTH24_STENCIL8_EXT
:
728 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
729 return GL_DEPTH_STENCIL_EXT
;
732 /* XXX add floating point formats eventually */
740 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
741 GLsizei width
, GLsizei height
)
743 struct gl_renderbuffer
*rb
;
745 GET_CURRENT_CONTEXT(ctx
);
747 ASSERT_OUTSIDE_BEGIN_END(ctx
);
749 if (target
!= GL_RENDERBUFFER_EXT
) {
750 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
754 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
755 if (baseFormat
== 0) {
756 _mesa_error(ctx
, GL_INVALID_ENUM
,
757 "glRenderbufferStorageEXT(internalFormat)");
761 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
762 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
766 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
767 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
771 rb
= ctx
->CurrentRenderbuffer
;
774 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
778 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
780 if (rb
->InternalFormat
== internalFormat
&&
781 rb
->Width
== (GLuint
) width
&&
782 rb
->Height
== (GLuint
) height
) {
783 /* no change in allocation needed */
787 /* These MUST get set by the AllocStorage func */
788 rb
->_ActualFormat
= 0;
797 /* Now allocate the storage */
798 ASSERT(rb
->AllocStorage
);
799 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
800 /* No error - check/set fields now */
801 assert(rb
->_ActualFormat
);
802 assert(rb
->Width
== (GLuint
) width
);
803 assert(rb
->Height
== (GLuint
) height
);
804 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
805 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
806 rb
->InternalFormat
= internalFormat
;
807 rb
->_BaseFormat
= baseFormat
;
810 /* Probably ran out of memory - clear the fields */
813 rb
->InternalFormat
= GL_NONE
;
814 rb
->_ActualFormat
= GL_NONE
;
815 rb
->_BaseFormat
= GL_NONE
;
826 test_framebuffer_completeness(ctx, fb);
828 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
835 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
837 GET_CURRENT_CONTEXT(ctx
);
839 ASSERT_OUTSIDE_BEGIN_END(ctx
);
841 if (target
!= GL_RENDERBUFFER_EXT
) {
842 _mesa_error(ctx
, GL_INVALID_ENUM
,
843 "glGetRenderbufferParameterivEXT(target)");
847 if (!ctx
->CurrentRenderbuffer
) {
848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
849 "glGetRenderbufferParameterivEXT");
853 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
856 case GL_RENDERBUFFER_WIDTH_EXT
:
857 *params
= ctx
->CurrentRenderbuffer
->Width
;
859 case GL_RENDERBUFFER_HEIGHT_EXT
:
860 *params
= ctx
->CurrentRenderbuffer
->Height
;
862 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
863 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
865 case GL_RENDERBUFFER_RED_SIZE_EXT
:
866 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
868 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
869 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
871 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
872 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
874 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
875 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
877 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
878 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
880 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
881 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
884 _mesa_error(ctx
, GL_INVALID_ENUM
,
885 "glGetRenderbufferParameterivEXT(target)");
892 _mesa_IsFramebufferEXT(GLuint framebuffer
)
894 GET_CURRENT_CONTEXT(ctx
);
895 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
897 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
898 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
906 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
909 ASSERT(ctx
->Driver
.RenderTexture
);
910 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
911 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
912 struct gl_texture_object
*texObj
= att
->Texture
;
914 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
915 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
922 * Examine all the framebuffer's attachments to see if any are textures.
923 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
924 * notify the device driver that the texture image may have changed.
927 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
929 if (ctx
->Driver
.FinishRenderTexture
) {
931 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
932 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
933 if (att
->Texture
&& att
->Renderbuffer
) {
934 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
942 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
944 struct gl_framebuffer
*newFb
, *newFbread
;
945 GLboolean bindReadBuf
, bindDrawBuf
;
946 GET_CURRENT_CONTEXT(ctx
);
948 ASSERT_OUTSIDE_BEGIN_END(ctx
);
950 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
951 _mesa_error(ctx
, GL_INVALID_OPERATION
,
952 "glBindFramebufferEXT(unsupported)");
957 #if FEATURE_EXT_framebuffer_blit
958 case GL_DRAW_FRAMEBUFFER_EXT
:
959 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
960 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
963 bindDrawBuf
= GL_TRUE
;
964 bindReadBuf
= GL_FALSE
;
966 case GL_READ_FRAMEBUFFER_EXT
:
967 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
968 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
971 bindDrawBuf
= GL_FALSE
;
972 bindReadBuf
= GL_TRUE
;
975 case GL_FRAMEBUFFER_EXT
:
976 bindDrawBuf
= GL_TRUE
;
977 bindReadBuf
= GL_TRUE
;
980 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
984 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
986 if (ctx
->Driver
.Flush
) {
987 ctx
->Driver
.Flush(ctx
);
991 /* Binding a user-created framebuffer object */
992 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
993 if (newFb
== &DummyFramebuffer
) {
994 /* ID was reserved, but no real framebuffer object made yet */
998 /* create new framebuffer object */
999 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1001 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1004 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
1009 /* Binding the window system framebuffer (which was originally set
1010 * with MakeCurrent).
1012 newFb
= ctx
->WinSysDrawBuffer
;
1013 newFbread
= ctx
->WinSysReadBuffer
;
1017 ASSERT(newFb
!= &DummyFramebuffer
);
1020 * XXX check if re-binding same buffer and skip some of this code.
1024 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1028 /* check if old FB had any texture attachments */
1029 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1031 /* check if time to delete this framebuffer */
1032 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1034 if (newFb
->Name
!= 0) {
1035 /* check if newly bound framebuffer has any texture attachments */
1036 check_begin_texture_render(ctx
, newFb
);
1040 if (ctx
->Driver
.BindFramebuffer
) {
1041 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1047 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1050 GET_CURRENT_CONTEXT(ctx
);
1052 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1053 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1054 /* The above doesn't fully flush the drivers in the way that a
1055 * glFlush does, but that is required here:
1057 if (ctx
->Driver
.Flush
)
1058 ctx
->Driver
.Flush(ctx
);
1060 for (i
= 0; i
< n
; i
++) {
1061 if (framebuffers
[i
] > 0) {
1062 struct gl_framebuffer
*fb
;
1063 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1065 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1067 /* check if deleting currently bound framebuffer object */
1068 if (fb
== ctx
->DrawBuffer
) {
1070 ASSERT(fb
->RefCount
>= 2);
1071 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1074 /* remove from hash table immediately, to free the ID */
1075 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1077 if (fb
!= &DummyFramebuffer
) {
1078 /* But the object will not be freed until it's no longer
1079 * bound in any context.
1081 _mesa_unreference_framebuffer(&fb
);
1090 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1092 GET_CURRENT_CONTEXT(ctx
);
1096 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1099 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1106 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1108 for (i
= 0; i
< n
; i
++) {
1109 GLuint name
= first
+ i
;
1110 framebuffers
[i
] = name
;
1111 /* insert dummy placeholder into hash table */
1112 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1113 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1114 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1121 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1123 struct gl_framebuffer
*buffer
;
1124 GET_CURRENT_CONTEXT(ctx
);
1126 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1129 #if FEATURE_EXT_framebuffer_blit
1130 case GL_DRAW_FRAMEBUFFER_EXT
:
1131 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1132 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1135 buffer
= ctx
->DrawBuffer
;
1137 case GL_READ_FRAMEBUFFER_EXT
:
1138 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1139 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1142 buffer
= ctx
->ReadBuffer
;
1145 case GL_FRAMEBUFFER_EXT
:
1146 buffer
= ctx
->DrawBuffer
;
1149 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1150 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1153 if (buffer
->Name
== 0) {
1154 /* The window system / default framebuffer is always complete */
1155 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1158 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1160 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1161 return buffer
->_Status
;
1167 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1170 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1171 GLenum attachment
, GLenum textarget
, GLuint texture
,
1172 GLint level
, GLint zoffset
)
1174 struct gl_renderbuffer_attachment
*att
;
1175 struct gl_texture_object
*texObj
= NULL
;
1176 struct gl_framebuffer
*fb
;
1178 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1180 if (target
!= GL_FRAMEBUFFER_EXT
) {
1181 _mesa_error(ctx
, GL_INVALID_ENUM
,
1182 "glFramebufferTexture%sEXT(target)", caller
);
1186 fb
= ctx
->DrawBuffer
;
1189 /* check framebuffer binding */
1190 if (fb
->Name
== 0) {
1191 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1192 "glFramebufferTexture%sEXT", caller
);
1197 /* The textarget, level, and zoffset parameters are only validated if
1198 * texture is non-zero.
1201 GLboolean err
= GL_TRUE
;
1203 texObj
= _mesa_lookup_texture(ctx
, texture
);
1204 if (texObj
!= NULL
) {
1205 if (textarget
== 0) {
1206 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1207 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1208 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1211 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1212 ? !IS_CUBE_FACE(textarget
)
1213 : (texObj
->Target
!= textarget
);
1218 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1219 "glFramebufferTexture%sEXT(texture target mismatch)",
1224 if (texObj
->Target
== GL_TEXTURE_3D
) {
1225 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1226 if (zoffset
< 0 || zoffset
>= maxSize
) {
1227 _mesa_error(ctx
, GL_INVALID_VALUE
,
1228 "glFramebufferTexture%sEXT(zoffset)", caller
);
1232 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1233 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1234 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1235 _mesa_error(ctx
, GL_INVALID_VALUE
,
1236 "glFramebufferTexture%sEXT(layer)", caller
);
1243 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1244 _mesa_error(ctx
, GL_INVALID_VALUE
,
1245 "glFramebufferTexture%sEXT(level)", caller
);
1250 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1252 _mesa_error(ctx
, GL_INVALID_ENUM
,
1253 "glFramebufferTexture%sEXT(attachment)", caller
);
1257 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1258 /* The above doesn't fully flush the drivers in the way that a
1259 * glFlush does, but that is required here:
1261 if (ctx
->Driver
.Flush
)
1262 ctx
->Driver
.Flush(ctx
);
1264 _glthread_LOCK_MUTEX(fb
->Mutex
);
1266 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1270 _mesa_remove_attachment(ctx
, att
);
1272 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1278 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1279 GLenum textarget
, GLuint texture
, GLint level
)
1281 GET_CURRENT_CONTEXT(ctx
);
1283 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1284 _mesa_error(ctx
, GL_INVALID_ENUM
,
1285 "glFramebufferTexture1DEXT(textarget)");
1289 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1295 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1296 GLenum textarget
, GLuint texture
, GLint level
)
1298 GET_CURRENT_CONTEXT(ctx
);
1300 if ((texture
!= 0) &&
1301 (textarget
!= GL_TEXTURE_2D
) &&
1302 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1303 (!IS_CUBE_FACE(textarget
))) {
1304 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1305 "glFramebufferTexture2DEXT(textarget)");
1309 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1315 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1316 GLenum textarget
, GLuint texture
,
1317 GLint level
, GLint zoffset
)
1319 GET_CURRENT_CONTEXT(ctx
);
1321 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1322 _mesa_error(ctx
, GL_INVALID_ENUM
,
1323 "glFramebufferTexture3DEXT(textarget)");
1327 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1333 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1334 GLuint texture
, GLint level
, GLint layer
)
1336 GET_CURRENT_CONTEXT(ctx
);
1338 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1344 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1345 GLenum renderbufferTarget
,
1346 GLuint renderbuffer
)
1348 struct gl_renderbuffer_attachment
*att
;
1349 struct gl_framebuffer
*fb
;
1350 struct gl_renderbuffer
*rb
;
1351 GET_CURRENT_CONTEXT(ctx
);
1353 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1356 #if FEATURE_EXT_framebuffer_blit
1357 case GL_DRAW_FRAMEBUFFER_EXT
:
1358 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1359 _mesa_error(ctx
, GL_INVALID_ENUM
,
1360 "glFramebufferRenderbufferEXT(target)");
1363 fb
= ctx
->DrawBuffer
;
1365 case GL_READ_FRAMEBUFFER_EXT
:
1366 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1367 _mesa_error(ctx
, GL_INVALID_ENUM
,
1368 "glFramebufferRenderbufferEXT(target)");
1371 fb
= ctx
->ReadBuffer
;
1374 case GL_FRAMEBUFFER_EXT
:
1375 fb
= ctx
->DrawBuffer
;
1378 _mesa_error(ctx
, GL_INVALID_ENUM
,
1379 "glFramebufferRenderbufferEXT(target)");
1383 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1384 _mesa_error(ctx
, GL_INVALID_ENUM
,
1385 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1389 if (fb
->Name
== 0) {
1390 /* Can't attach new renderbuffers to a window system framebuffer */
1391 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1395 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1397 _mesa_error(ctx
, GL_INVALID_ENUM
,
1398 "glFramebufferRenderbufferEXT(attachment)");
1403 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1406 "glFramebufferRenderbufferEXT(renderbuffer)");
1411 /* remove renderbuffer attachment */
1415 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1416 /* The above doesn't fully flush the drivers in the way that a
1417 * glFlush does, but that is required here:
1419 if (ctx
->Driver
.Flush
)
1420 ctx
->Driver
.Flush(ctx
);
1422 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1423 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1425 /* Some subsequent GL commands may depend on the framebuffer's visual
1426 * after the binding is updated. Update visual info now.
1428 _mesa_update_framebuffer_visual(fb
);
1433 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1434 GLenum pname
, GLint
*params
)
1436 const struct gl_renderbuffer_attachment
*att
;
1437 struct gl_framebuffer
*buffer
;
1438 GET_CURRENT_CONTEXT(ctx
);
1440 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1443 #if FEATURE_EXT_framebuffer_blit
1444 case GL_DRAW_FRAMEBUFFER_EXT
:
1445 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glGetFramebufferAttachmentParameterivEXT(target)");
1450 buffer
= ctx
->DrawBuffer
;
1452 case GL_READ_FRAMEBUFFER_EXT
:
1453 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1454 _mesa_error(ctx
, GL_INVALID_ENUM
,
1455 "glGetFramebufferAttachmentParameterivEXT(target)");
1458 buffer
= ctx
->ReadBuffer
;
1461 case GL_FRAMEBUFFER_EXT
:
1462 buffer
= ctx
->DrawBuffer
;
1465 _mesa_error(ctx
, GL_INVALID_ENUM
,
1466 "glGetFramebufferAttachmentParameterivEXT(target)");
1470 if (buffer
->Name
== 0) {
1471 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1472 "glGetFramebufferAttachmentParameterivEXT");
1476 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1478 _mesa_error(ctx
, GL_INVALID_ENUM
,
1479 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1483 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1484 /* The above doesn't fully flush the drivers in the way that a
1485 * glFlush does, but that is required here:
1487 if (ctx
->Driver
.Flush
)
1488 ctx
->Driver
.Flush(ctx
);
1491 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1492 *params
= att
->Type
;
1494 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1495 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1496 *params
= att
->Renderbuffer
->Name
;
1498 else if (att
->Type
== GL_TEXTURE
) {
1499 *params
= att
->Texture
->Name
;
1502 _mesa_error(ctx
, GL_INVALID_ENUM
,
1503 "glGetFramebufferAttachmentParameterivEXT(pname)");
1506 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1507 if (att
->Type
== GL_TEXTURE
) {
1508 *params
= att
->TextureLevel
;
1511 _mesa_error(ctx
, GL_INVALID_ENUM
,
1512 "glGetFramebufferAttachmentParameterivEXT(pname)");
1515 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1516 if (att
->Type
== GL_TEXTURE
) {
1517 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1520 _mesa_error(ctx
, GL_INVALID_ENUM
,
1521 "glGetFramebufferAttachmentParameterivEXT(pname)");
1524 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1525 if (att
->Type
== GL_TEXTURE
) {
1526 *params
= att
->Zoffset
;
1529 _mesa_error(ctx
, GL_INVALID_ENUM
,
1530 "glGetFramebufferAttachmentParameterivEXT(pname)");
1534 _mesa_error(ctx
, GL_INVALID_ENUM
,
1535 "glGetFramebufferAttachmentParameterivEXT(pname)");
1542 _mesa_GenerateMipmapEXT(GLenum target
)
1544 struct gl_texture_unit
*texUnit
;
1545 struct gl_texture_object
*texObj
;
1546 GET_CURRENT_CONTEXT(ctx
);
1548 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1549 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1555 case GL_TEXTURE_CUBE_MAP
:
1556 /* OK, legal value */
1559 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1563 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1564 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1566 /* XXX this might not handle cube maps correctly */
1567 _mesa_lock_texture(ctx
, texObj
);
1568 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
1569 _mesa_unlock_texture(ctx
, texObj
);
1573 #if FEATURE_EXT_framebuffer_blit
1575 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1576 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1577 GLbitfield mask
, GLenum filter
)
1579 GET_CURRENT_CONTEXT(ctx
);
1581 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1582 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1584 if (ctx
->NewState
) {
1585 _mesa_update_state(ctx
);
1588 if (!ctx
->ReadBuffer
) {
1592 /* check for complete framebuffers */
1593 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1594 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1595 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1596 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1600 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1605 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1606 GL_DEPTH_BUFFER_BIT
|
1607 GL_STENCIL_BUFFER_BIT
)) {
1608 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1612 /* depth/stencil must be blitted with nearest filtering */
1613 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1614 && filter
!= GL_NEAREST
) {
1615 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1616 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1620 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1621 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1622 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1623 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1624 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1625 "glBlitFramebufferEXT(stencil buffer size mismatch");
1630 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1631 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1632 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1633 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1634 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1635 "glBlitFramebufferEXT(depth buffer size mismatch");
1640 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1641 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1645 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1646 ctx
->Driver
.BlitFramebuffer(ctx
,
1647 srcX0
, srcY0
, srcX1
, srcY1
,
1648 dstX0
, dstY0
, dstX1
, dstY1
,
1651 #endif /* FEATURE_EXT_framebuffer_blit */