#include "context.h"
#include "drawpix.h"
#include "feedback.h"
+#include "framebuffer.h"
#include "image.h"
#include "state.h"
GLboolean drawing)
{
const char *readDraw = drawing ? "Draw" : "Read";
- struct gl_framebuffer *fb = drawing ? ctx->DrawBuffer : ctx->ReadBuffer;
if (ctx->Extensions.EXT_packed_depth_stencil
&& type == GL_UNSIGNED_INT_24_8_EXT
"glDrawPixels(drawing RGB pixels into color index buffer)");
return GL_TRUE;
}
+ if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(no color buffer)");
+ return GL_TRUE;
+ }
break;
case GL_COLOR_INDEX:
if (!drawing && ctx->Visual.rgbMode) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(reading color index format from RGB buffer");
+ "glReadPixels(reading color index format from RGB buffer)");
+ return GL_TRUE;
+ }
+ if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(no color buffer)");
return GL_TRUE;
}
break;
case GL_STENCIL_INDEX:
- if (fb->Visual.stencilBits == 0) {
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
+ (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sPixels(no stencil buffer)", readDraw);
return GL_TRUE;
}
break;
case GL_DEPTH_COMPONENT:
- if (fb->Visual.depthBits == 0) {
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
+ (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sPixels(no depth buffer)", readDraw);
return GL_TRUE;
_mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
return GL_TRUE;
}
- if (fb->Visual.depthBits == 0 || fb->Visual.stencilBits == 0) {
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
+ (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sPixels(no depth or stencil buffer)", readDraw);
return GL_TRUE;
}
- ASSERT(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
- ASSERT(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
break;
default:
/* this should have been caught in _mesa_is_legal_format_type() */
return;
}
- switch (type) {
- case GL_COLOR:
- /* OK */
- break;
- case GL_DEPTH:
- if (ctx->DrawBuffer->Visual.depthBits == 0 ||
- ctx->ReadBuffer->Visual.depthBits == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyPixels(no depth buffer)");
- return;
- }
- break;
- case GL_STENCIL:
- if (ctx->DrawBuffer->Visual.stencilBits == 0 ||
- ctx->ReadBuffer->Visual.stencilBits == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyPixels(no stencil buffer)");
- return;
- }
- break;
- case GL_DEPTH_STENCIL_EXT:
- if (!ctx->Extensions.EXT_packed_depth_stencil) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels");
- return;
- }
- if (ctx->DrawBuffer->Visual.depthBits == 0 ||
- ctx->ReadBuffer->Visual.depthBits == 0 ||
- ctx->DrawBuffer->Visual.stencilBits == 0 ||
- ctx->ReadBuffer->Visual.stencilBits == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyPixels(no depth or stencil buffer)");
- return;
- }
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels");
- return;
- }
-
if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
_mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
return;
}
+ if (!_mesa_source_buffer_exists(ctx, type) ||
+ !_mesa_dest_buffer_exists(ctx, type)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyPixels(missing source or dest buffer)");
+ return;
+ }
+
if (!ctx->Current.RasterPosValid) {
return;
}
GLenum format, GLenum type, GLvoid *pixels )
{
GET_CURRENT_CONTEXT(ctx);
- const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (width < 0 || height < 0) {
return;
}
- if (!rb) {
+ if (!_mesa_source_buffer_exists(ctx, format)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
return;
}