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 if (ctx
->Driver
.FinishRenderTexture
) {
155 /* tell driver we're done rendering to this texobj */
156 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
158 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
159 ASSERT(!att
->Texture
);
161 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
162 ASSERT(att
->Renderbuffer
);
163 ASSERT(!att
->Texture
);
164 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
165 ASSERT(!att
->Renderbuffer
);
168 att
->Complete
= GL_TRUE
;
173 * Bind a texture object to an attachment point.
174 * The previous binding, if any, will be removed first.
177 _mesa_set_texture_attachment(GLcontext
*ctx
,
178 struct gl_framebuffer
*fb
,
179 struct gl_renderbuffer_attachment
*att
,
180 struct gl_texture_object
*texObj
,
181 GLenum texTarget
, GLuint level
, GLuint zoffset
)
183 if (att
->Texture
== texObj
) {
184 /* re-attaching same texture */
185 ASSERT(att
->Type
== GL_TEXTURE
);
189 _mesa_remove_attachment(ctx
, att
);
190 att
->Type
= GL_TEXTURE
;
191 assert(!att
->Texture
);
192 _mesa_reference_texobj(&att
->Texture
, texObj
);
195 /* always update these fields */
196 att
->TextureLevel
= level
;
197 if (IS_CUBE_FACE(texTarget
)) {
198 att
->CubeMapFace
= texTarget
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
201 att
->CubeMapFace
= 0;
203 att
->Zoffset
= zoffset
;
204 att
->Complete
= GL_FALSE
;
206 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
207 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
213 * Bind a renderbuffer to an attachment point.
214 * The previous binding, if any, will be removed first.
217 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
218 struct gl_renderbuffer_attachment
*att
,
219 struct gl_renderbuffer
*rb
)
221 /* XXX check if re-doing same attachment, exit early */
222 _mesa_remove_attachment(ctx
, att
);
223 att
->Type
= GL_RENDERBUFFER_EXT
;
224 att
->Texture
= NULL
; /* just to be safe */
225 att
->Complete
= GL_FALSE
;
226 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
231 * Fallback for ctx->Driver.FramebufferRenderbuffer()
232 * Attach a renderbuffer object to a framebuffer object.
235 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
236 GLenum attachment
, struct gl_renderbuffer
*rb
)
238 struct gl_renderbuffer_attachment
*att
;
240 _glthread_LOCK_MUTEX(fb
->Mutex
);
242 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
245 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
248 _mesa_remove_attachment(ctx
, att
);
251 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
256 * Test if an attachment point is complete and update its Complete field.
257 * \param format if GL_COLOR, this is a color attachment point,
258 * if GL_DEPTH, this is a depth component attachment point,
259 * if GL_STENCIL, this is a stencil component attachment point.
262 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
263 struct gl_renderbuffer_attachment
*att
)
265 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
267 /* assume complete */
268 att
->Complete
= GL_TRUE
;
270 /* Look for reasons why the attachment might be incomplete */
271 if (att
->Type
== GL_TEXTURE
) {
272 const struct gl_texture_object
*texObj
= att
->Texture
;
273 struct gl_texture_image
*texImage
;
276 att
->Complete
= GL_FALSE
;
280 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
282 att
->Complete
= GL_FALSE
;
285 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
286 att
->Complete
= GL_FALSE
;
289 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
290 att
->Complete
= GL_FALSE
;
294 if (format
== GL_COLOR
) {
295 if (texImage
->TexFormat
->BaseFormat
!= GL_RGB
&&
296 texImage
->TexFormat
->BaseFormat
!= GL_RGBA
) {
297 att
->Complete
= GL_FALSE
;
301 else if (format
== GL_DEPTH
) {
302 if (texImage
->TexFormat
->BaseFormat
== GL_DEPTH_COMPONENT
) {
305 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
306 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
310 att
->Complete
= GL_FALSE
;
315 /* no such thing as stencil textures */
316 att
->Complete
= GL_FALSE
;
320 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
321 ASSERT(att
->Renderbuffer
);
322 if (!att
->Renderbuffer
->InternalFormat
||
323 att
->Renderbuffer
->Width
< 1 ||
324 att
->Renderbuffer
->Height
< 1) {
325 att
->Complete
= GL_FALSE
;
328 if (format
== GL_COLOR
) {
329 if (att
->Renderbuffer
->_BaseFormat
!= GL_RGB
&&
330 att
->Renderbuffer
->_BaseFormat
!= GL_RGBA
) {
331 ASSERT(att
->Renderbuffer
->RedBits
);
332 ASSERT(att
->Renderbuffer
->GreenBits
);
333 ASSERT(att
->Renderbuffer
->BlueBits
);
334 att
->Complete
= GL_FALSE
;
338 else if (format
== GL_DEPTH
) {
339 ASSERT(att
->Renderbuffer
->DepthBits
);
340 if (att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
343 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
344 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
348 att
->Complete
= GL_FALSE
;
353 assert(format
== GL_STENCIL
);
354 ASSERT(att
->Renderbuffer
->StencilBits
);
355 if (att
->Renderbuffer
->_BaseFormat
== GL_STENCIL_INDEX
) {
358 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
359 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
363 att
->Complete
= GL_FALSE
;
369 ASSERT(att
->Type
== GL_NONE
);
377 * Helpful for debugging
380 fbo_incomplete(const char *msg
, int index
)
385 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
391 * Test if the given framebuffer object is complete and update its
392 * Status field with the results.
393 * Also update the framebuffer's Width and Height fields if the
394 * framebuffer is complete.
397 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
399 GLuint numImages
, width
= 0, height
= 0;
400 GLenum intFormat
= GL_NONE
;
405 assert(fb
->Name
!= 0);
411 /* Start at -2 to more easily loop over all attachment points */
412 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
413 struct gl_renderbuffer_attachment
*att
;
417 att
= &fb
->Attachment
[BUFFER_DEPTH
];
418 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
419 if (!att
->Complete
) {
420 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
421 fbo_incomplete("depth attachment incomplete", -1);
426 att
= &fb
->Attachment
[BUFFER_STENCIL
];
427 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
428 if (!att
->Complete
) {
429 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
430 fbo_incomplete("stencil attachment incomplete", -1);
435 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
436 test_attachment_completeness(ctx
, GL_COLOR
, att
);
437 if (!att
->Complete
) {
438 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
439 fbo_incomplete("color attachment incomplete", i
);
444 if (att
->Type
== GL_TEXTURE
) {
445 const struct gl_texture_image
*texImg
446 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
449 f
= texImg
->_BaseFormat
;
451 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
452 && f
!= GL_DEPTH_STENCIL_EXT
) {
453 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
454 fbo_incomplete("texture attachment incomplete", -1);
458 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
459 w
= att
->Renderbuffer
->Width
;
460 h
= att
->Renderbuffer
->Height
;
461 f
= att
->Renderbuffer
->InternalFormat
;
465 assert(att
->Type
== GL_NONE
);
469 if (numImages
== 1) {
470 /* set required width, height and format */
477 /* check that width, height, format are same */
478 if (w
!= width
|| h
!= height
) {
479 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
480 fbo_incomplete("width or height mismatch", -1);
483 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
484 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
485 fbo_incomplete("format mismatch", -1);
491 /* Check that all DrawBuffers are present */
492 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
493 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
494 const struct gl_renderbuffer_attachment
*att
495 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
497 if (att
->Type
== GL_NONE
) {
498 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
499 fbo_incomplete("missing drawbuffer", j
);
505 /* Check that the ReadBuffer is present */
506 if (fb
->ColorReadBuffer
!= GL_NONE
) {
507 const struct gl_renderbuffer_attachment
*att
508 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
510 if (att
->Type
== GL_NONE
) {
511 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
512 fbo_incomplete("missing readbuffer", -1);
517 if (numImages
== 0) {
518 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
519 fbo_incomplete("no attachments", -1);
524 * If we get here, the framebuffer is complete!
526 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
533 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
535 GET_CURRENT_CONTEXT(ctx
);
536 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
538 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
539 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
547 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
549 struct gl_renderbuffer
*newRb
;
550 GET_CURRENT_CONTEXT(ctx
);
552 ASSERT_OUTSIDE_BEGIN_END(ctx
);
554 if (target
!= GL_RENDERBUFFER_EXT
) {
555 _mesa_error(ctx
, GL_INVALID_ENUM
,
556 "glBindRenderbufferEXT(target)");
560 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
561 /* The above doesn't fully flush the drivers in the way that a
562 * glFlush does, but that is required here:
564 if (ctx
->Driver
.Flush
)
565 ctx
->Driver
.Flush(ctx
);
569 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
570 if (newRb
== &DummyRenderbuffer
) {
571 /* ID was reserved, but no real renderbuffer object made yet */
575 /* create new renderbuffer object */
576 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
578 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
581 ASSERT(newRb
->AllocStorage
);
582 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
583 newRb
->RefCount
= 1; /* referenced by hash table */
590 ASSERT(newRb
!= &DummyRenderbuffer
);
592 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
597 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
600 GET_CURRENT_CONTEXT(ctx
);
602 ASSERT_OUTSIDE_BEGIN_END(ctx
);
603 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
605 for (i
= 0; i
< n
; i
++) {
606 if (renderbuffers
[i
] > 0) {
607 struct gl_renderbuffer
*rb
;
608 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
610 /* check if deleting currently bound renderbuffer object */
611 if (rb
== ctx
->CurrentRenderbuffer
) {
613 ASSERT(rb
->RefCount
>= 2);
614 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
617 /* Remove from hash table immediately, to free the ID.
618 * But the object will not be freed until it's no longer
619 * referenced anywhere else.
621 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
623 if (rb
!= &DummyRenderbuffer
) {
624 /* no longer referenced by hash table */
625 _mesa_reference_renderbuffer(&rb
, NULL
);
634 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
636 GET_CURRENT_CONTEXT(ctx
);
640 ASSERT_OUTSIDE_BEGIN_END(ctx
);
643 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
650 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
652 for (i
= 0; i
< n
; i
++) {
653 GLuint name
= first
+ i
;
654 renderbuffers
[i
] = name
;
655 /* insert dummy placeholder into hash table */
656 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
657 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
658 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
664 * Given an internal format token for a render buffer, return the
665 * corresponding base format.
666 * This is very similar to _mesa_base_tex_format() but the set of valid
667 * internal formats is somewhat different.
669 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
670 * GL_DEPTH_STENCIL_EXT or zero if error.
673 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
675 switch (internalFormat
) {
694 case GL_STENCIL_INDEX
:
695 case GL_STENCIL_INDEX1_EXT
:
696 case GL_STENCIL_INDEX4_EXT
:
697 case GL_STENCIL_INDEX8_EXT
:
698 case GL_STENCIL_INDEX16_EXT
:
699 return GL_STENCIL_INDEX
;
700 case GL_DEPTH_COMPONENT
:
701 case GL_DEPTH_COMPONENT16
:
702 case GL_DEPTH_COMPONENT24
:
703 case GL_DEPTH_COMPONENT32
:
704 return GL_DEPTH_COMPONENT
;
705 case GL_DEPTH_STENCIL_EXT
:
706 case GL_DEPTH24_STENCIL8_EXT
:
707 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
708 return GL_DEPTH_STENCIL_EXT
;
711 /* XXX add floating point formats eventually */
719 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
720 GLsizei width
, GLsizei height
)
722 struct gl_renderbuffer
*rb
;
724 GET_CURRENT_CONTEXT(ctx
);
726 ASSERT_OUTSIDE_BEGIN_END(ctx
);
728 if (target
!= GL_RENDERBUFFER_EXT
) {
729 _mesa_error(ctx
, GL_INVALID_ENUM
, "glRenderbufferStorageEXT(target)");
733 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
734 if (baseFormat
== 0) {
735 _mesa_error(ctx
, GL_INVALID_ENUM
,
736 "glRenderbufferStorageEXT(internalFormat)");
740 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
741 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(width)");
745 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
746 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRenderbufferStorageEXT(height)");
750 rb
= ctx
->CurrentRenderbuffer
;
753 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferStorageEXT");
757 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
759 if (rb
->InternalFormat
== internalFormat
&&
760 rb
->Width
== (GLuint
) width
&&
761 rb
->Height
== (GLuint
) height
) {
762 /* no change in allocation needed */
766 /* These MUST get set by the AllocStorage func */
767 rb
->_ActualFormat
= 0;
776 /* Now allocate the storage */
777 ASSERT(rb
->AllocStorage
);
778 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
779 /* No error - check/set fields now */
780 assert(rb
->_ActualFormat
);
781 assert(rb
->Width
== (GLuint
) width
);
782 assert(rb
->Height
== (GLuint
) height
);
783 assert(rb
->RedBits
|| rb
->GreenBits
|| rb
->BlueBits
|| rb
->AlphaBits
||
784 rb
->DepthBits
|| rb
->StencilBits
|| rb
->IndexBits
);
785 rb
->InternalFormat
= internalFormat
;
786 rb
->_BaseFormat
= baseFormat
;
789 /* Probably ran out of memory - clear the fields */
792 rb
->InternalFormat
= GL_NONE
;
793 rb
->_ActualFormat
= GL_NONE
;
794 rb
->_BaseFormat
= GL_NONE
;
805 test_framebuffer_completeness(ctx, fb);
807 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
814 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
816 GET_CURRENT_CONTEXT(ctx
);
818 ASSERT_OUTSIDE_BEGIN_END(ctx
);
820 if (target
!= GL_RENDERBUFFER_EXT
) {
821 _mesa_error(ctx
, GL_INVALID_ENUM
,
822 "glGetRenderbufferParameterivEXT(target)");
826 if (!ctx
->CurrentRenderbuffer
) {
827 _mesa_error(ctx
, GL_INVALID_OPERATION
,
828 "glGetRenderbufferParameterivEXT");
832 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
835 case GL_RENDERBUFFER_WIDTH_EXT
:
836 *params
= ctx
->CurrentRenderbuffer
->Width
;
838 case GL_RENDERBUFFER_HEIGHT_EXT
:
839 *params
= ctx
->CurrentRenderbuffer
->Height
;
841 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
842 *params
= ctx
->CurrentRenderbuffer
->InternalFormat
;
844 case GL_RENDERBUFFER_RED_SIZE_EXT
:
845 *params
= ctx
->CurrentRenderbuffer
->RedBits
;
847 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
848 *params
= ctx
->CurrentRenderbuffer
->GreenBits
;
850 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
851 *params
= ctx
->CurrentRenderbuffer
->BlueBits
;
853 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
854 *params
= ctx
->CurrentRenderbuffer
->AlphaBits
;
856 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
857 *params
= ctx
->CurrentRenderbuffer
->DepthBits
;
859 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
860 *params
= ctx
->CurrentRenderbuffer
->StencilBits
;
863 _mesa_error(ctx
, GL_INVALID_ENUM
,
864 "glGetRenderbufferParameterivEXT(target)");
871 _mesa_IsFramebufferEXT(GLuint framebuffer
)
873 GET_CURRENT_CONTEXT(ctx
);
874 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
876 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
877 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
885 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
888 ASSERT(ctx
->Driver
.RenderTexture
);
889 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
890 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
891 struct gl_texture_object
*texObj
= att
->Texture
;
893 && att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
894 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
901 * Examine all the framebuffer's attachments to see if any are textures.
902 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
903 * notify the device driver that the texture image may have changed.
906 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
908 if (ctx
->Driver
.FinishRenderTexture
) {
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 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
922 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
924 struct gl_framebuffer
*newFb
, *newFbread
;
925 GLboolean bindReadBuf
, bindDrawBuf
;
926 GET_CURRENT_CONTEXT(ctx
);
928 ASSERT_OUTSIDE_BEGIN_END(ctx
);
930 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
932 "glBindFramebufferEXT(unsupported)");
937 #if FEATURE_EXT_framebuffer_blit
938 case GL_DRAW_FRAMEBUFFER_EXT
:
939 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
940 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
943 bindDrawBuf
= GL_TRUE
;
944 bindReadBuf
= GL_FALSE
;
946 case GL_READ_FRAMEBUFFER_EXT
:
947 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
948 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
951 bindDrawBuf
= GL_FALSE
;
952 bindReadBuf
= GL_TRUE
;
955 case GL_FRAMEBUFFER_EXT
:
956 bindDrawBuf
= GL_TRUE
;
957 bindReadBuf
= GL_TRUE
;
960 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
964 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
966 if (ctx
->Driver
.Flush
) {
967 ctx
->Driver
.Flush(ctx
);
971 /* Binding a user-created framebuffer object */
972 newFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
973 if (newFb
== &DummyFramebuffer
) {
974 /* ID was reserved, but no real framebuffer object made yet */
978 /* create new framebuffer object */
979 newFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
981 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
984 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newFb
);
989 /* Binding the window system framebuffer (which was originally set
992 newFb
= ctx
->WinSysDrawBuffer
;
993 newFbread
= ctx
->WinSysReadBuffer
;
997 ASSERT(newFb
!= &DummyFramebuffer
);
1000 * XXX check if re-binding same buffer and skip some of this code.
1004 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newFbread
);
1008 /* check if old FB had any texture attachments */
1009 check_end_texture_render(ctx
, ctx
->DrawBuffer
);
1011 /* check if time to delete this framebuffer */
1012 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newFb
);
1014 if (newFb
->Name
!= 0) {
1015 /* check if newly bound framebuffer has any texture attachments */
1016 check_begin_texture_render(ctx
, newFb
);
1020 if (ctx
->Driver
.BindFramebuffer
) {
1021 ctx
->Driver
.BindFramebuffer(ctx
, target
, newFb
, newFbread
);
1027 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1030 GET_CURRENT_CONTEXT(ctx
);
1032 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1033 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1034 /* The above doesn't fully flush the drivers in the way that a
1035 * glFlush does, but that is required here:
1037 if (ctx
->Driver
.Flush
)
1038 ctx
->Driver
.Flush(ctx
);
1040 for (i
= 0; i
< n
; i
++) {
1041 if (framebuffers
[i
] > 0) {
1042 struct gl_framebuffer
*fb
;
1043 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1045 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1047 /* check if deleting currently bound framebuffer object */
1048 if (fb
== ctx
->DrawBuffer
) {
1050 ASSERT(fb
->RefCount
>= 2);
1051 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1054 /* remove from hash table immediately, to free the ID */
1055 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1057 if (fb
!= &DummyFramebuffer
) {
1058 /* But the object will not be freed until it's no longer
1059 * bound in any context.
1061 _mesa_unreference_framebuffer(&fb
);
1070 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1072 GET_CURRENT_CONTEXT(ctx
);
1076 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1079 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1086 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1088 for (i
= 0; i
< n
; i
++) {
1089 GLuint name
= first
+ i
;
1090 framebuffers
[i
] = name
;
1091 /* insert dummy placeholder into hash table */
1092 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1093 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1094 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1101 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1103 struct gl_framebuffer
*buffer
;
1104 GET_CURRENT_CONTEXT(ctx
);
1106 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1109 #if FEATURE_EXT_framebuffer_blit
1110 case GL_DRAW_FRAMEBUFFER_EXT
:
1111 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1112 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1115 buffer
= ctx
->DrawBuffer
;
1117 case GL_READ_FRAMEBUFFER_EXT
:
1118 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1119 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1122 buffer
= ctx
->ReadBuffer
;
1125 case GL_FRAMEBUFFER_EXT
:
1126 buffer
= ctx
->DrawBuffer
;
1129 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1130 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1133 if (buffer
->Name
== 0) {
1134 /* The window system / default framebuffer is always complete */
1135 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1138 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1140 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1141 return buffer
->_Status
;
1147 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1150 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1151 GLenum attachment
, GLenum textarget
, GLuint texture
,
1152 GLint level
, GLint zoffset
)
1154 struct gl_renderbuffer_attachment
*att
;
1155 struct gl_texture_object
*texObj
= NULL
;
1156 struct gl_framebuffer
*fb
;
1158 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1160 if (target
!= GL_FRAMEBUFFER_EXT
) {
1161 _mesa_error(ctx
, GL_INVALID_ENUM
,
1162 "glFramebufferTexture%sEXT(target)", caller
);
1166 fb
= ctx
->DrawBuffer
;
1169 /* check framebuffer binding */
1170 if (fb
->Name
== 0) {
1171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1172 "glFramebufferTexture%sEXT", caller
);
1177 /* The textarget, level, and zoffset parameters are only validated if
1178 * texture is non-zero.
1181 GLboolean err
= GL_TRUE
;
1183 texObj
= _mesa_lookup_texture(ctx
, texture
);
1184 if (texObj
!= NULL
) {
1185 if (textarget
== 0) {
1186 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1187 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1188 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1191 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1192 ? !IS_CUBE_FACE(textarget
)
1193 : (texObj
->Target
!= textarget
);
1198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1199 "glFramebufferTexture%sEXT(texture target mismatch)",
1204 if (texObj
->Target
== GL_TEXTURE_3D
) {
1205 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1206 if (zoffset
< 0 || zoffset
>= maxSize
) {
1207 _mesa_error(ctx
, GL_INVALID_VALUE
,
1208 "glFramebufferTexture%sEXT(zoffset)", caller
);
1212 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1213 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1214 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1215 _mesa_error(ctx
, GL_INVALID_VALUE
,
1216 "glFramebufferTexture%sEXT(layer)", caller
);
1223 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1224 _mesa_error(ctx
, GL_INVALID_VALUE
,
1225 "glFramebufferTexture%sEXT(level)", caller
);
1230 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1232 _mesa_error(ctx
, GL_INVALID_ENUM
,
1233 "glFramebufferTexture%sEXT(attachment)", caller
);
1237 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1238 /* The above doesn't fully flush the drivers in the way that a
1239 * glFlush does, but that is required here:
1241 if (ctx
->Driver
.Flush
)
1242 ctx
->Driver
.Flush(ctx
);
1244 _glthread_LOCK_MUTEX(fb
->Mutex
);
1246 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1250 _mesa_remove_attachment(ctx
, att
);
1252 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1258 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1259 GLenum textarget
, GLuint texture
, GLint level
)
1261 GET_CURRENT_CONTEXT(ctx
);
1263 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1264 _mesa_error(ctx
, GL_INVALID_ENUM
,
1265 "glFramebufferTexture1DEXT(textarget)");
1269 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1275 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1276 GLenum textarget
, GLuint texture
, GLint level
)
1278 GET_CURRENT_CONTEXT(ctx
);
1280 if ((texture
!= 0) &&
1281 (textarget
!= GL_TEXTURE_2D
) &&
1282 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1283 (!IS_CUBE_FACE(textarget
))) {
1284 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1285 "glFramebufferTexture2DEXT(textarget)");
1289 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1295 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1296 GLenum textarget
, GLuint texture
,
1297 GLint level
, GLint zoffset
)
1299 GET_CURRENT_CONTEXT(ctx
);
1301 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1302 _mesa_error(ctx
, GL_INVALID_ENUM
,
1303 "glFramebufferTexture3DEXT(textarget)");
1307 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1313 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1314 GLuint texture
, GLint level
, GLint layer
)
1316 GET_CURRENT_CONTEXT(ctx
);
1318 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1324 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1325 GLenum renderbufferTarget
,
1326 GLuint renderbuffer
)
1328 struct gl_renderbuffer_attachment
*att
;
1329 struct gl_framebuffer
*fb
;
1330 struct gl_renderbuffer
*rb
;
1331 GET_CURRENT_CONTEXT(ctx
);
1333 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1336 #if FEATURE_EXT_framebuffer_blit
1337 case GL_DRAW_FRAMEBUFFER_EXT
:
1338 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1339 _mesa_error(ctx
, GL_INVALID_ENUM
,
1340 "glFramebufferRenderbufferEXT(target)");
1343 fb
= ctx
->DrawBuffer
;
1345 case GL_READ_FRAMEBUFFER_EXT
:
1346 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1347 _mesa_error(ctx
, GL_INVALID_ENUM
,
1348 "glFramebufferRenderbufferEXT(target)");
1351 fb
= ctx
->ReadBuffer
;
1354 case GL_FRAMEBUFFER_EXT
:
1355 fb
= ctx
->DrawBuffer
;
1358 _mesa_error(ctx
, GL_INVALID_ENUM
,
1359 "glFramebufferRenderbufferEXT(target)");
1363 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1364 _mesa_error(ctx
, GL_INVALID_ENUM
,
1365 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1369 if (fb
->Name
== 0) {
1370 /* Can't attach new renderbuffers to a window system framebuffer */
1371 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1375 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1377 _mesa_error(ctx
, GL_INVALID_ENUM
,
1378 "glFramebufferRenderbufferEXT(attachment)");
1383 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1386 "glFramebufferRenderbufferEXT(renderbuffer)");
1391 /* remove renderbuffer attachment */
1395 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1396 /* The above doesn't fully flush the drivers in the way that a
1397 * glFlush does, but that is required here:
1399 if (ctx
->Driver
.Flush
)
1400 ctx
->Driver
.Flush(ctx
);
1402 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1403 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1405 /* Some subsequent GL commands may depend on the framebuffer's visual
1406 * after the binding is updated. Update visual info now.
1408 _mesa_update_framebuffer_visual(fb
);
1413 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1414 GLenum pname
, GLint
*params
)
1416 const struct gl_renderbuffer_attachment
*att
;
1417 struct gl_framebuffer
*buffer
;
1418 GET_CURRENT_CONTEXT(ctx
);
1420 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1423 #if FEATURE_EXT_framebuffer_blit
1424 case GL_DRAW_FRAMEBUFFER_EXT
:
1425 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1426 _mesa_error(ctx
, GL_INVALID_ENUM
,
1427 "glGetFramebufferAttachmentParameterivEXT(target)");
1430 buffer
= ctx
->DrawBuffer
;
1432 case GL_READ_FRAMEBUFFER_EXT
:
1433 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1434 _mesa_error(ctx
, GL_INVALID_ENUM
,
1435 "glGetFramebufferAttachmentParameterivEXT(target)");
1438 buffer
= ctx
->ReadBuffer
;
1441 case GL_FRAMEBUFFER_EXT
:
1442 buffer
= ctx
->DrawBuffer
;
1445 _mesa_error(ctx
, GL_INVALID_ENUM
,
1446 "glGetFramebufferAttachmentParameterivEXT(target)");
1450 if (buffer
->Name
== 0) {
1451 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1452 "glGetFramebufferAttachmentParameterivEXT");
1456 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1458 _mesa_error(ctx
, GL_INVALID_ENUM
,
1459 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1463 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1464 /* The above doesn't fully flush the drivers in the way that a
1465 * glFlush does, but that is required here:
1467 if (ctx
->Driver
.Flush
)
1468 ctx
->Driver
.Flush(ctx
);
1471 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1472 *params
= att
->Type
;
1474 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1475 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1476 *params
= att
->Renderbuffer
->Name
;
1478 else if (att
->Type
== GL_TEXTURE
) {
1479 *params
= att
->Texture
->Name
;
1482 _mesa_error(ctx
, GL_INVALID_ENUM
,
1483 "glGetFramebufferAttachmentParameterivEXT(pname)");
1486 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1487 if (att
->Type
== GL_TEXTURE
) {
1488 *params
= att
->TextureLevel
;
1491 _mesa_error(ctx
, GL_INVALID_ENUM
,
1492 "glGetFramebufferAttachmentParameterivEXT(pname)");
1495 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1496 if (att
->Type
== GL_TEXTURE
) {
1497 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1500 _mesa_error(ctx
, GL_INVALID_ENUM
,
1501 "glGetFramebufferAttachmentParameterivEXT(pname)");
1504 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1505 if (att
->Type
== GL_TEXTURE
) {
1506 *params
= att
->Zoffset
;
1509 _mesa_error(ctx
, GL_INVALID_ENUM
,
1510 "glGetFramebufferAttachmentParameterivEXT(pname)");
1514 _mesa_error(ctx
, GL_INVALID_ENUM
,
1515 "glGetFramebufferAttachmentParameterivEXT(pname)");
1522 _mesa_GenerateMipmapEXT(GLenum target
)
1524 struct gl_texture_unit
*texUnit
;
1525 struct gl_texture_object
*texObj
;
1526 GET_CURRENT_CONTEXT(ctx
);
1528 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1529 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1535 case GL_TEXTURE_CUBE_MAP
:
1536 /* OK, legal value */
1539 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
1543 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1544 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1546 /* XXX this might not handle cube maps correctly */
1547 _mesa_lock_texture(ctx
, texObj
);
1548 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
1549 _mesa_unlock_texture(ctx
, texObj
);
1553 #if FEATURE_EXT_framebuffer_blit
1555 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1556 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1557 GLbitfield mask
, GLenum filter
)
1559 GET_CURRENT_CONTEXT(ctx
);
1561 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1562 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1564 if (ctx
->NewState
) {
1565 _mesa_update_state(ctx
);
1568 if (!ctx
->ReadBuffer
) {
1572 /* check for complete framebuffers */
1573 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
1574 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1575 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1576 "glBlitFramebufferEXT(incomplete draw/read buffers)");
1580 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
1581 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
1585 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
1586 GL_DEPTH_BUFFER_BIT
|
1587 GL_STENCIL_BUFFER_BIT
)) {
1588 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
1592 /* depth/stencil must be blitted with nearest filtering */
1593 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
1594 && filter
!= GL_NEAREST
) {
1595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1596 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
1600 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1601 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_StencilBuffer
;
1602 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_StencilBuffer
;
1603 if (readRb
->StencilBits
!= drawRb
->StencilBits
) {
1604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1605 "glBlitFramebufferEXT(stencil buffer size mismatch");
1610 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1611 struct gl_renderbuffer
*readRb
= ctx
->ReadBuffer
->_DepthBuffer
;
1612 struct gl_renderbuffer
*drawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
1613 if (readRb
->DepthBits
!= drawRb
->DepthBits
) {
1614 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1615 "glBlitFramebufferEXT(depth buffer size mismatch");
1620 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1621 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
1625 ASSERT(ctx
->Driver
.BlitFramebuffer
);
1626 ctx
->Driver
.BlitFramebuffer(ctx
,
1627 srcX0
, srcY0
, srcX1
, srcY1
,
1628 dstX0
, dstY0
, dstX1
, dstY1
,
1631 #endif /* FEATURE_EXT_framebuffer_blit */