Skip to content
Snippets Groups Projects
Commit 7275d4d0 authored by Brian Paul's avatar Brian Paul
Browse files

added _mesa_source/dest_buffer_exists() function to easily test if particular...

added _mesa_source/dest_buffer_exists() function to easily test if particular renderbuffers are present
parent f1038f81
No related branches found
No related tags found
Loading
......@@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.5
*
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -550,3 +550,124 @@ _mesa_update_framebuffer(GLcontext *ctx)
compute_depth_max(fb);
}
/**
* 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(GLcontext *ctx, GLenum format)
{
const struct gl_renderbuffer_attachment *att
= ctx->ReadBuffer->Attachment;
if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
return GL_FALSE;
}
switch (format) {
case GL_COLOR:
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
case GL_RGB:
case GL_RGBA:
case GL_COLOR_INDEX:
if (ctx->ReadBuffer->_ColorReadBuffer == NULL) {
return GL_FALSE;
}
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_source_buffer_exists");
return GL_FALSE;
}
/* OK */
return GL_TRUE;
}
/**
* As above, but for drawing operations.
* XXX code do some code merging w/ above function.
*/
GLboolean
_mesa_dest_buffer_exists(GLcontext *ctx, GLenum format)
{
const struct gl_renderbuffer_attachment *att
= ctx->ReadBuffer->Attachment;
if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
return GL_FALSE;
}
switch (format) {
case GL_COLOR:
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
case GL_RGB:
case GL_RGBA:
case GL_COLOR_INDEX:
/* nothing special */
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_source_buffer_exists");
return GL_FALSE;
}
/* OK */
return GL_TRUE;
}
......@@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.5
*
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -55,4 +55,11 @@ _mesa_update_framebuffer_visual(struct gl_framebuffer *fb);
extern void
_mesa_update_framebuffer(GLcontext *ctx);
extern GLboolean
_mesa_source_buffer_exists(GLcontext *ctx, GLenum format);
extern GLboolean
_mesa_dest_buffer_exists(GLcontext *ctx, GLenum format);
#endif /* FRAMEBUFFER_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment