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.
27 * Functions for allocating/managing framebuffers and renderbuffers.
28 * Also, routines for reading/writing renderbuffer data as ubytes,
29 * ushorts, uints, etc.
36 #include "depthstencil.h"
39 #include "framebuffer.h"
40 #include "renderbuffer.h"
45 * Compute/set the _DepthMax field for the given framebuffer.
46 * This value depends on the Z buffer resolution.
49 compute_depth_max(struct gl_framebuffer
*fb
)
51 if (fb
->Visual
.depthBits
== 0) {
52 /* Special case. Even if we don't have a depth buffer we need
53 * good values for DepthMax for Z vertex transformation purposes
54 * and for per-fragment fog computation.
56 fb
->_DepthMax
= (1 << 16) - 1;
58 else if (fb
->Visual
.depthBits
< 32) {
59 fb
->_DepthMax
= (1 << fb
->Visual
.depthBits
) - 1;
62 /* Special case since shift values greater than or equal to the
63 * number of bits in the left hand expression's type are undefined.
65 fb
->_DepthMax
= 0xffffffff;
67 fb
->_DepthMaxF
= (GLfloat
) fb
->_DepthMax
;
69 /* Minimum resolvable depth value, for polygon offset */
70 fb
->_MRD
= (GLfloat
)1.0 / fb
->_DepthMaxF
;
75 * Create and initialize a gl_framebuffer object.
76 * This is intended for creating _window_system_ framebuffers, not generic
77 * framebuffer objects ala GL_EXT_framebuffer_object.
79 * \sa _mesa_new_framebuffer
81 struct gl_framebuffer
*
82 _mesa_create_framebuffer(const GLvisual
*visual
)
84 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
87 _mesa_initialize_framebuffer(fb
, visual
);
94 * Allocate a new gl_framebuffer object.
95 * This is the default function for ctx->Driver.NewFramebuffer().
96 * This is for allocating user-created framebuffers, not window-system
98 * \sa _mesa_create_framebuffer
100 struct gl_framebuffer
*
101 _mesa_new_framebuffer(GLcontext
*ctx
, GLuint name
)
103 struct gl_framebuffer
*fb
;
106 fb
= CALLOC_STRUCT(gl_framebuffer
);
110 fb
->ColorDrawBuffer
[0] = GL_COLOR_ATTACHMENT0_EXT
;
111 fb
->_ColorDrawBufferMask
[0] = BUFFER_BIT_COLOR0
;
112 fb
->ColorReadBuffer
= GL_COLOR_ATTACHMENT0_EXT
;
113 fb
->_ColorReadBufferIndex
= BUFFER_COLOR0
;
114 fb
->Delete
= _mesa_destroy_framebuffer
;
121 * Initialize a gl_framebuffer object. Typically used to initialize
122 * window system-created framebuffers, not user-created framebuffers.
123 * \sa _mesa_create_framebuffer
126 _mesa_initialize_framebuffer(struct gl_framebuffer
*fb
, const GLvisual
*visual
)
131 _mesa_bzero(fb
, sizeof(struct gl_framebuffer
));
133 _glthread_INIT_MUTEX(fb
->Mutex
);
137 /* save the visual */
138 fb
->Visual
= *visual
;
140 /* Init glRead/DrawBuffer state */
141 if (visual
->doubleBufferMode
) {
142 fb
->ColorDrawBuffer
[0] = GL_BACK
;
143 fb
->_ColorDrawBufferMask
[0] = BUFFER_BIT_BACK_LEFT
;
144 fb
->ColorReadBuffer
= GL_BACK
;
145 fb
->_ColorReadBufferIndex
= BUFFER_BACK_LEFT
;
148 fb
->ColorDrawBuffer
[0] = GL_FRONT
;
149 fb
->_ColorDrawBufferMask
[0] = BUFFER_BIT_FRONT_LEFT
;
150 fb
->ColorReadBuffer
= GL_FRONT
;
151 fb
->_ColorReadBufferIndex
= BUFFER_FRONT_LEFT
;
154 fb
->Delete
= _mesa_destroy_framebuffer
;
155 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
157 compute_depth_max(fb
);
162 * Deallocate buffer and everything attached to it.
163 * Typically called via the gl_framebuffer->Delete() method.
166 _mesa_destroy_framebuffer(struct gl_framebuffer
*fb
)
169 _mesa_free_framebuffer_data(fb
);
176 * Free all the data hanging off the given gl_framebuffer, but don't free
177 * the gl_framebuffer object itself.
180 _mesa_free_framebuffer_data(struct gl_framebuffer
*fb
)
185 assert(fb
->RefCount
== 0);
187 _glthread_DESTROY_MUTEX(fb
->Mutex
);
189 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
190 struct gl_renderbuffer_attachment
*att
= &fb
->Attachment
[i
];
191 if (att
->Renderbuffer
) {
192 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
195 /* render to texture */
196 att
->Texture
->RefCount
--;
197 if (att
->Texture
->RefCount
== 0) {
198 GET_CURRENT_CONTEXT(ctx
);
200 ctx
->Driver
.DeleteTexture(ctx
, att
->Texture
);
208 /* unbind _Depth/_StencilBuffer to decr ref counts */
209 _mesa_reference_renderbuffer(&fb
->_DepthBuffer
, NULL
);
210 _mesa_reference_renderbuffer(&fb
->_StencilBuffer
, NULL
);
215 * Set *ptr to point to fb, with refcounting and locking.
218 _mesa_reference_framebuffer(struct gl_framebuffer
**ptr
,
219 struct gl_framebuffer
*fb
)
227 _mesa_unreference_framebuffer(ptr
);
231 _glthread_LOCK_MUTEX(fb
->Mutex
);
233 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
239 * Undo/remove a reference to a framebuffer object.
240 * Decrement the framebuffer object's reference count and delete it when
241 * the refcount hits zero.
242 * Note: we pass the address of a pointer and set it to NULL.
245 _mesa_unreference_framebuffer(struct gl_framebuffer
**fb
)
249 GLboolean deleteFlag
= GL_FALSE
;
251 _glthread_LOCK_MUTEX((*fb
)->Mutex
);
252 ASSERT((*fb
)->RefCount
> 0);
254 deleteFlag
= ((*fb
)->RefCount
== 0);
255 _glthread_UNLOCK_MUTEX((*fb
)->Mutex
);
268 * Resize the given framebuffer's renderbuffers to the new width and height.
269 * This should only be used for window-system framebuffers, not
270 * user-created renderbuffers (i.e. made with GL_EXT_framebuffer_object).
271 * This will typically be called via ctx->Driver.ResizeBuffers() or directly
272 * from a device driver.
274 * \note it's possible for ctx to be null since a window can be resized
275 * without a currently bound rendering context.
278 _mesa_resize_framebuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
279 GLuint width
, GLuint height
)
283 /* XXX I think we could check if the size is not changing
287 /* For window system framebuffers, Name is zero */
288 assert(fb
->Name
== 0);
290 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
291 struct gl_renderbuffer_attachment
*att
= &fb
->Attachment
[i
];
292 if (att
->Type
== GL_RENDERBUFFER_EXT
&& att
->Renderbuffer
) {
293 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
294 /* only resize if size is changing */
295 if (rb
->Width
!= width
|| rb
->Height
!= height
) {
296 /* could just as well pass rb->_ActualFormat here */
297 if (rb
->AllocStorage(ctx
, rb
, rb
->InternalFormat
, width
, height
)) {
298 ASSERT(rb
->Width
== width
);
299 ASSERT(rb
->Height
== height
);
302 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Resizing framebuffer");
309 if (fb
->_DepthBuffer
) {
310 struct gl_renderbuffer
*rb
= fb
->_DepthBuffer
;
311 if (rb
->Width
!= width
|| rb
->Height
!= height
) {
312 if (!rb
->AllocStorage(ctx
, rb
, rb
->InternalFormat
, width
, height
)) {
313 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Resizing framebuffer");
318 if (fb
->_StencilBuffer
) {
319 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
320 if (rb
->Width
!= width
|| rb
->Height
!= height
) {
321 if (!rb
->AllocStorage(ctx
, rb
, rb
->InternalFormat
, width
, height
)) {
322 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "Resizing framebuffer");
331 /* update scissor / window bounds */
332 _mesa_update_draw_buffer_bounds(ctx
);
333 /* Signal new buffer state so that swrast will update its clipping
334 * info (the CLIP_BIT flag).
336 ctx
->NewState
|= _NEW_BUFFERS
;
343 * XXX THIS IS OBSOLETE - drivers should take care of detecting window
344 * size changes and act accordingly, likely calling _mesa_resize_framebuffer().
346 * GL_MESA_resize_buffers extension.
348 * When this function is called, we'll ask the window system how large
349 * the current window is. If it's a new size, we'll call the driver's
350 * ResizeBuffers function. The driver will then resize its color buffers
351 * as needed, and maybe call the swrast's routine for reallocating
352 * swrast-managed depth/stencil/accum/etc buffers.
353 * \note This function should only be called through the GL API, not
354 * from device drivers (as was done in the past).
357 _mesa_resizebuffers( GLcontext
*ctx
)
359 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx
);
361 if (MESA_VERBOSE
& VERBOSE_API
)
362 _mesa_debug(ctx
, "glResizeBuffersMESA\n");
364 if (!ctx
->Driver
.GetBufferSize
) {
368 if (ctx
->WinSysDrawBuffer
) {
369 GLuint newWidth
, newHeight
;
370 GLframebuffer
*buffer
= ctx
->WinSysDrawBuffer
;
372 assert(buffer
->Name
== 0);
374 /* ask device driver for size of output buffer */
375 ctx
->Driver
.GetBufferSize( buffer
, &newWidth
, &newHeight
);
377 /* see if size of device driver's color buffer (window) has changed */
378 if (buffer
->Width
!= newWidth
|| buffer
->Height
!= newHeight
) {
379 if (ctx
->Driver
.ResizeBuffers
)
380 ctx
->Driver
.ResizeBuffers(ctx
, buffer
, newWidth
, newHeight
);
384 if (ctx
->WinSysReadBuffer
385 && ctx
->WinSysReadBuffer
!= ctx
->WinSysDrawBuffer
) {
386 GLuint newWidth
, newHeight
;
387 GLframebuffer
*buffer
= ctx
->WinSysReadBuffer
;
389 assert(buffer
->Name
== 0);
391 /* ask device driver for size of read buffer */
392 ctx
->Driver
.GetBufferSize( buffer
, &newWidth
, &newHeight
);
394 /* see if size of device driver's color buffer (window) has changed */
395 if (buffer
->Width
!= newWidth
|| buffer
->Height
!= newHeight
) {
396 if (ctx
->Driver
.ResizeBuffers
)
397 ctx
->Driver
.ResizeBuffers(ctx
, buffer
, newWidth
, newHeight
);
401 ctx
->NewState
|= _NEW_BUFFERS
; /* to update scissor / window bounds */
406 * XXX THIS IS OBSOLETE
409 _mesa_ResizeBuffersMESA( void )
411 GET_CURRENT_CONTEXT(ctx
);
413 if (ctx
->Extensions
.MESA_resize_buffers
)
414 _mesa_resizebuffers( ctx
);
420 * Examine all the framebuffer's renderbuffers to update the Width/Height
421 * fields of the framebuffer. If we have renderbuffers with different
422 * sizes, set the framebuffer's width and height to zero.
423 * Note: this is only intended for user-created framebuffers, not
424 * window-system framebuffes.
427 update_framebuffer_size(struct gl_framebuffer
*fb
)
429 GLboolean haveSize
= GL_FALSE
;
432 /* user-created framebuffers only */
435 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
436 struct gl_renderbuffer_attachment
*att
= &fb
->Attachment
[i
];
437 const struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
440 if (rb
->Width
!= fb
->Width
&& rb
->Height
!= fb
->Height
) {
448 fb
->Width
= rb
->Width
;
449 fb
->Height
= rb
->Height
;
458 * Update the context's current drawing buffer's Xmin, Xmax, Ymin, Ymax fields.
459 * These values are computed from the buffer's width and height and
460 * the scissor box, if it's enabled.
461 * \param ctx the GL context.
464 _mesa_update_draw_buffer_bounds(GLcontext
*ctx
)
466 struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
472 /* user-created framebuffer size depends on the renderbuffers */
473 update_framebuffer_size(buffer
);
478 buffer
->_Xmax
= buffer
->Width
;
479 buffer
->_Ymax
= buffer
->Height
;
481 if (ctx
->Scissor
.Enabled
) {
482 if (ctx
->Scissor
.X
> buffer
->_Xmin
) {
483 buffer
->_Xmin
= ctx
->Scissor
.X
;
485 if (ctx
->Scissor
.Y
> buffer
->_Ymin
) {
486 buffer
->_Ymin
= ctx
->Scissor
.Y
;
488 if (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
< buffer
->_Xmax
) {
489 buffer
->_Xmax
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
;
491 if (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
< buffer
->_Ymax
) {
492 buffer
->_Ymax
= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
;
494 /* finally, check for empty region */
495 if (buffer
->_Xmin
> buffer
->_Xmax
) {
496 buffer
->_Xmin
= buffer
->_Xmax
;
498 if (buffer
->_Ymin
> buffer
->_Ymax
) {
499 buffer
->_Ymin
= buffer
->_Ymax
;
503 ASSERT(buffer
->_Xmin
<= buffer
->_Xmax
);
504 ASSERT(buffer
->_Ymin
<= buffer
->_Ymax
);
509 * The glGet queries of the framebuffer red/green/blue size, stencil size,
510 * etc. are satisfied by the fields of ctx->DrawBuffer->Visual. These can
511 * change depending on the renderbuffer bindings. This function updates
512 * the given framebuffer's Visual from the current renderbuffer bindings.
514 * This may apply to user-created framebuffers or window system framebuffers.
516 * Also note: ctx->DrawBuffer->Visual.depthBits might not equal
517 * ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer.DepthBits.
518 * The former one is used to convert floating point depth values into
522 _mesa_update_framebuffer_visual(struct gl_framebuffer
*fb
)
526 _mesa_bzero(&fb
->Visual
, sizeof(fb
->Visual
));
527 fb
->Visual
.rgbMode
= GL_TRUE
; /* assume this */
529 #if 0 /* this _might_ be needed */
530 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
531 /* leave visual fields zero'd */
536 /* find first RGB or CI renderbuffer */
537 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
538 if (fb
->Attachment
[i
].Renderbuffer
) {
539 const struct gl_renderbuffer
*rb
= fb
->Attachment
[i
].Renderbuffer
;
540 if (rb
->_BaseFormat
== GL_RGBA
|| rb
->_BaseFormat
== GL_RGB
) {
541 fb
->Visual
.redBits
= rb
->RedBits
;
542 fb
->Visual
.greenBits
= rb
->GreenBits
;
543 fb
->Visual
.blueBits
= rb
->BlueBits
;
544 fb
->Visual
.alphaBits
= rb
->AlphaBits
;
545 fb
->Visual
.rgbBits
= fb
->Visual
.redBits
546 + fb
->Visual
.greenBits
+ fb
->Visual
.blueBits
;
547 fb
->Visual
.floatMode
= GL_FALSE
;
550 else if (rb
->_BaseFormat
== GL_COLOR_INDEX
) {
551 fb
->Visual
.indexBits
= rb
->IndexBits
;
552 fb
->Visual
.rgbMode
= GL_FALSE
;
558 if (fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
) {
559 fb
->Visual
.haveDepthBuffer
= GL_TRUE
;
561 = fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
->DepthBits
;
564 if (fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
) {
565 fb
->Visual
.haveStencilBuffer
= GL_TRUE
;
566 fb
->Visual
.stencilBits
567 = fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
->StencilBits
;
570 if (fb
->Attachment
[BUFFER_ACCUM
].Renderbuffer
) {
571 fb
->Visual
.haveAccumBuffer
= GL_TRUE
;
572 fb
->Visual
.accumRedBits
573 = fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
->RedBits
;
574 fb
->Visual
.accumGreenBits
575 = fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
->GreenBits
;
576 fb
->Visual
.accumBlueBits
577 = fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
->BlueBits
;
578 fb
->Visual
.accumAlphaBits
579 = fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
->AlphaBits
;
582 compute_depth_max(fb
);
587 * Update the framebuffer's _DepthBuffer field using the renderbuffer
588 * found at the given attachment index.
590 * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
591 * create and install a depth wrapper/adaptor.
593 * \param fb the framebuffer whose _DepthBuffer field to update
594 * \param attIndex indicates the renderbuffer to possibly wrap
597 _mesa_update_depth_buffer(GLcontext
*ctx
,
598 struct gl_framebuffer
*fb
,
601 struct gl_renderbuffer
*depthRb
;
603 /* only one possiblity for now */
604 ASSERT(attIndex
== BUFFER_DEPTH
);
606 depthRb
= fb
->Attachment
[attIndex
].Renderbuffer
;
608 if (depthRb
&& depthRb
->_ActualFormat
== GL_DEPTH24_STENCIL8_EXT
) {
609 /* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */
610 if (!fb
->_DepthBuffer
611 || fb
->_DepthBuffer
->Wrapped
!= depthRb
612 || fb
->_DepthBuffer
->_BaseFormat
!= GL_DEPTH_COMPONENT
) {
613 /* need to update wrapper */
614 struct gl_renderbuffer
*wrapper
615 = _mesa_new_z24_renderbuffer_wrapper(ctx
, depthRb
);
616 _mesa_reference_renderbuffer(&fb
->_DepthBuffer
, wrapper
);
617 ASSERT(fb
->_DepthBuffer
->Wrapped
== depthRb
);
621 /* depthRb may be null */
622 _mesa_reference_renderbuffer(&fb
->_DepthBuffer
, depthRb
);
628 * Update the framebuffer's _StencilBuffer field using the renderbuffer
629 * found at the given attachment index.
631 * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
632 * create and install a stencil wrapper/adaptor.
634 * \param fb the framebuffer whose _StencilBuffer field to update
635 * \param attIndex indicates the renderbuffer to possibly wrap
638 _mesa_update_stencil_buffer(GLcontext
*ctx
,
639 struct gl_framebuffer
*fb
,
642 struct gl_renderbuffer
*stencilRb
;
644 ASSERT(attIndex
== BUFFER_DEPTH
||
645 attIndex
== BUFFER_STENCIL
);
647 stencilRb
= fb
->Attachment
[attIndex
].Renderbuffer
;
649 if (stencilRb
&& stencilRb
->_ActualFormat
== GL_DEPTH24_STENCIL8_EXT
) {
650 /* The attached stencil buffer is a GL_DEPTH_STENCIL renderbuffer */
651 if (!fb
->_StencilBuffer
652 || fb
->_StencilBuffer
->Wrapped
!= stencilRb
653 || fb
->_StencilBuffer
->_BaseFormat
!= GL_STENCIL_INDEX
) {
654 /* need to update wrapper */
655 struct gl_renderbuffer
*wrapper
656 = _mesa_new_s8_renderbuffer_wrapper(ctx
, stencilRb
);
657 _mesa_reference_renderbuffer(&fb
->_StencilBuffer
, wrapper
);
658 ASSERT(fb
->_StencilBuffer
->Wrapped
== stencilRb
);
662 /* stencilRb may be null */
663 _mesa_reference_renderbuffer(&fb
->_StencilBuffer
, stencilRb
);
669 * Update the list of color drawing renderbuffer pointers.
670 * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers
674 update_color_draw_buffers(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
679 * Fragment programs can write to multiple colorbuffers with
680 * the GL_ARB_draw_buffers extension.
682 for (output
= 0; output
< ctx
->Const
.MaxDrawBuffers
; output
++) {
683 GLbitfield bufferMask
= fb
->_ColorDrawBufferMask
[output
];
686 if (!fb
->DeletePending
) {
687 /* We need the inner loop here because glDrawBuffer(GL_FRONT_AND_BACK)
688 * can specify writing to two or four color buffers (for example).
690 for (i
= 0; bufferMask
&& i
< BUFFER_COUNT
; i
++) {
691 const GLuint bufferBit
= 1 << i
;
692 if (bufferBit
& bufferMask
) {
693 struct gl_renderbuffer
*rb
= fb
->Attachment
[i
].Renderbuffer
;
694 if (rb
&& rb
->Width
> 0 && rb
->Height
> 0) {
695 fb
->_ColorDrawBuffers
[output
][count
] = rb
;
700 _mesa_warning(ctx, "DrawBuffer names a missing buffer!\n");
703 bufferMask
&= ~bufferBit
;
707 fb
->_NumColorDrawBuffers
[output
] = count
;
713 * Update the color read renderbuffer pointer.
714 * Unlike the DrawBuffer, we can only read from one (or zero) color buffers.
717 update_color_read_buffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
720 if (fb
->_ColorReadBufferIndex
== -1 ||
724 fb
->_ColorReadBuffer
= NULL
; /* legal! */
727 ASSERT(fb
->_ColorReadBufferIndex
>= 0);
728 ASSERT(fb
->_ColorReadBufferIndex
< BUFFER_COUNT
);
730 = fb
->Attachment
[fb
->_ColorReadBufferIndex
].Renderbuffer
;
736 update_framebuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
738 /* Completeness only matters for user-created framebuffers */
740 /* XXX: EXT_framebuffer_blit:
741 framebuffer must still be complete wrt read/draw? */
742 _mesa_test_framebuffer_completeness(ctx
, fb
);
743 _mesa_update_framebuffer_visual(fb
);
746 /* update_color_draw/read_buffers not needed for
747 read/draw only fb, but shouldn't hurt ??? */
748 update_color_draw_buffers(ctx
, fb
);
749 update_color_read_buffer(ctx
, fb
);
750 _mesa_update_depth_buffer(ctx
, fb
, BUFFER_DEPTH
);
751 _mesa_update_stencil_buffer(ctx
, fb
, BUFFER_STENCIL
);
753 compute_depth_max(fb
);
757 * Update state related to the current draw/read framebuffers.
758 * Specifically, update these framebuffer fields:
760 * _NumColorDrawBuffers
764 * If the current framebuffer is user-created, make sure it's complete.
765 * The following functions can effect this state: glReadBuffer,
766 * glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT,
767 * glRenderbufferStorageEXT.
770 _mesa_update_framebuffer(GLcontext
*ctx
)
772 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
773 struct gl_framebuffer
*fbread
= ctx
->ReadBuffer
;
775 update_framebuffer(ctx
, fb
);
777 update_framebuffer(ctx
, fbread
);
782 * Check if the renderbuffer for a read operation (glReadPixels, glCopyPixels,
783 * glCopyTex[Sub]Image, etc. exists.
784 * \param format a basic image format such as GL_RGB, GL_RGBA, GL_ALPHA,
785 * GL_DEPTH_COMPONENT, etc. or GL_COLOR, GL_DEPTH, GL_STENCIL.
786 * \return GL_TRUE if buffer exists, GL_FALSE otherwise
789 _mesa_source_buffer_exists(GLcontext
*ctx
, GLenum format
)
791 const struct gl_renderbuffer_attachment
*att
792 = ctx
->ReadBuffer
->Attachment
;
794 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
805 case GL_LUMINANCE_ALPHA
:
813 if (ctx
->ReadBuffer
->_ColorReadBuffer
== NULL
) {
816 /* XXX enable this post 6.5 release:
817 ASSERT(ctx->ReadBuffer->_ColorReadBuffer->RedBits > 0 ||
818 ctx->ReadBuffer->_ColorReadBuffer->IndexBits > 0);
822 case GL_DEPTH_COMPONENT
:
823 if (!att
[BUFFER_DEPTH
].Renderbuffer
) {
826 ASSERT(att
[BUFFER_DEPTH
].Renderbuffer
->DepthBits
> 0);
829 case GL_STENCIL_INDEX
:
830 if (!att
[BUFFER_STENCIL
].Renderbuffer
) {
833 ASSERT(att
[BUFFER_STENCIL
].Renderbuffer
->StencilBits
> 0);
835 case GL_DEPTH_STENCIL_EXT
:
836 if (!att
[BUFFER_DEPTH
].Renderbuffer
||
837 !att
[BUFFER_STENCIL
].Renderbuffer
) {
840 ASSERT(att
[BUFFER_DEPTH
].Renderbuffer
->DepthBits
> 0);
841 ASSERT(att
[BUFFER_STENCIL
].Renderbuffer
->StencilBits
> 0);
845 "Unexpected format 0x%x in _mesa_source_buffer_exists",
856 * As above, but for drawing operations.
857 * XXX code do some code merging w/ above function.
860 _mesa_dest_buffer_exists(GLcontext
*ctx
, GLenum format
)
862 const struct gl_renderbuffer_attachment
*att
863 = ctx
->ReadBuffer
->Attachment
;
865 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
876 case GL_LUMINANCE_ALPHA
:
884 /* nothing special */
885 /* Could assert that colorbuffer has RedBits > 0 */
888 case GL_DEPTH_COMPONENT
:
889 if (!att
[BUFFER_DEPTH
].Renderbuffer
) {
892 ASSERT(att
[BUFFER_DEPTH
].Renderbuffer
->DepthBits
> 0);
895 case GL_STENCIL_INDEX
:
896 if (!att
[BUFFER_STENCIL
].Renderbuffer
) {
899 ASSERT(att
[BUFFER_STENCIL
].Renderbuffer
->StencilBits
> 0);
901 case GL_DEPTH_STENCIL_EXT
:
902 if (!att
[BUFFER_DEPTH
].Renderbuffer
||
903 !att
[BUFFER_STENCIL
].Renderbuffer
) {
906 ASSERT(att
[BUFFER_DEPTH
].Renderbuffer
->DepthBits
> 0);
907 ASSERT(att
[BUFFER_STENCIL
].Renderbuffer
->StencilBits
> 0);
911 "Unexpected format 0x%x in _mesa_source_buffer_exists",