summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/framebuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/framebuffer.c')
-rw-r--r--src/mesa/main/framebuffer.c130
1 files changed, 43 insertions, 87 deletions
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 8beda31815b..834328b82e8 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -839,23 +839,27 @@ _mesa_update_framebuffer(struct gl_context *ctx)
/**
- * Check if the renderbuffer for a read operation (glReadPixels, glCopyPixels,
- * glCopyTex[Sub]Image, etc) exists.
+ * Check if the renderbuffer for a read/draw operation exists.
* \param format a basic image format such as GL_RGB, GL_RGBA, GL_ALPHA,
* GL_DEPTH_COMPONENT, etc. or GL_COLOR, GL_DEPTH, GL_STENCIL.
+ * \param reading if TRUE, we're going to read from the buffer,
+ if FALSE, we're going to write to the buffer.
* \return GL_TRUE if buffer exists, GL_FALSE otherwise
*/
-GLboolean
-_mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
+static GLboolean
+renderbuffer_exists(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ GLenum format,
+ GLboolean reading)
{
- const struct gl_renderbuffer_attachment *att = ctx->ReadBuffer->Attachment;
+ const struct gl_renderbuffer_attachment *att = fb->Attachment;
/* If we don't know the framebuffer status, update it now */
- if (ctx->ReadBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
+ if (fb->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, fb);
}
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
return GL_FALSE;
}
@@ -884,14 +888,22 @@ _mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
case GL_BGRA_INTEGER_EXT:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- if (ctx->ReadBuffer->_ColorReadBuffer == NULL) {
- return GL_FALSE;
+ if (reading) {
+ /* about to read from a color buffer */
+ const struct gl_renderbuffer *readBuf = fb->_ColorReadBuffer;
+ if (!readBuf) {
+ return GL_FALSE;
+ }
+ ASSERT(_mesa_get_format_bits(readBuf->Format, GL_RED_BITS) > 0 ||
+ _mesa_get_format_bits(readBuf->Format, GL_ALPHA_BITS) > 0 ||
+ _mesa_get_format_bits(readBuf->Format, GL_TEXTURE_LUMINANCE_SIZE) > 0 ||
+ _mesa_get_format_bits(readBuf->Format, GL_TEXTURE_INTENSITY_SIZE) > 0 ||
+ _mesa_get_format_bits(readBuf->Format, GL_INDEX_BITS) > 0);
+ }
+ else {
+ /* about to draw to zero or more color buffers (none is OK) */
+ return GL_TRUE;
}
- ASSERT(_mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_RED_BITS) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_ALPHA_BITS) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_TEXTURE_LUMINANCE_SIZE) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_TEXTURE_INTENSITY_SIZE) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_INDEX_BITS) > 0);
break;
case GL_DEPTH:
case GL_DEPTH_COMPONENT:
@@ -919,7 +931,7 @@ _mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
break;
default:
_mesa_problem(ctx,
- "Unexpected format 0x%x in _mesa_source_buffer_exists",
+ "Unexpected format 0x%x in renderbuffer_exists",
format);
return GL_FALSE;
}
@@ -930,83 +942,27 @@ _mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
/**
+ * Check if the renderbuffer for a read operation (glReadPixels, glCopyPixels,
+ * glCopyTex[Sub]Image, etc) exists.
+ * \param format a basic image format such as GL_RGB, GL_RGBA, GL_ALPHA,
+ * GL_DEPTH_COMPONENT, etc. or GL_COLOR, GL_DEPTH, GL_STENCIL.
+ * \return GL_TRUE if buffer exists, GL_FALSE otherwise
+ */
+GLboolean
+_mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
+{
+ return renderbuffer_exists(ctx, ctx->ReadBuffer, format, GL_TRUE);
+}
+
+
+/**
* As above, but for drawing operations.
* XXX could do some code merging w/ above function.
*/
GLboolean
_mesa_dest_buffer_exists(struct gl_context *ctx, GLenum format)
{
- const struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment;
-
- /* If we don't know the framebuffer status, update it now */
- if (ctx->DrawBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->DrawBuffer);
- }
-
- if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- return GL_FALSE;
- }
-
- switch (format) {
- case GL_COLOR:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_RGB:
- case GL_BGR:
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RGB_INTEGER_EXT:
- case GL_RGBA_INTEGER_EXT:
- case GL_BGR_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- /* Nothing special since GL_DRAW_BUFFER could be GL_NONE. */
- /* Could assert that colorbuffer has RedBits > 0 */
- break;
- case GL_DEPTH:
- case GL_DEPTH_COMPONENT:
- if (!att[BUFFER_DEPTH].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
- break;
- case GL_STENCIL:
- case GL_STENCIL_INDEX:
- if (!att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
- break;
- case GL_DEPTH_STENCIL_EXT:
- if (!att[BUFFER_DEPTH].Renderbuffer ||
- !att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*
- ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
- ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
- */
- break;
- default:
- _mesa_problem(ctx,
- "Unexpected format 0x%x in _mesa_dest_buffer_exists",
- format);
- return GL_FALSE;
- }
-
- /* OK */
- return GL_TRUE;
+ return renderbuffer_exists(ctx, ctx->DrawBuffer, format, GL_FALSE);
}