mesa: refactor: move glReadPixels code into new readpix.c file

This commit is contained in:
Brian Paul
2008-06-09 14:22:15 -06:00
parent f26baad2e1
commit d960a0621d
7 changed files with 244 additions and 172 deletions

View File

@@ -30,114 +30,10 @@
#include "feedback.h"
#include "framebuffer.h"
#include "image.h"
#include "readpix.h"
#include "state.h"
/**
* Do error checking of the format/type parameters to glReadPixels and
* glDrawPixels.
* \param drawing if GL_TRUE do checking for DrawPixels, else do checking
* for ReadPixels.
* \return GL_TRUE if error detected, GL_FALSE if no errors
*/
static GLboolean
error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
GLboolean drawing)
{
const char *readDraw = drawing ? "Draw" : "Read";
if (ctx->Extensions.EXT_packed_depth_stencil
&& type == GL_UNSIGNED_INT_24_8_EXT
&& format != GL_DEPTH_STENCIL_EXT) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
return GL_TRUE;
}
/* basic combinations test */
if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"gl%sPixels(format or type)", readDraw);
return GL_TRUE;
}
/* additional checks */
switch (format) {
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_RGB:
case GL_BGR:
case GL_RGBA:
case GL_BGRA:
case GL_ABGR_EXT:
if (drawing && !ctx->Visual.rgbMode) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"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)");
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 ((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 ((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;
}
break;
case GL_DEPTH_STENCIL_EXT:
if (!ctx->Extensions.EXT_packed_depth_stencil ||
type != GL_UNSIGNED_INT_24_8_EXT) {
_mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
return GL_TRUE;
}
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;
}
break;
default:
/* this should have been caught in _mesa_is_legal_format_type() */
_mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
return GL_TRUE;
}
/* no errors */
return GL_FALSE;
}
#if _HAVE_FULL_GL
/*
@@ -165,7 +61,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
return;
}
if (error_check_format_type(ctx, format, type, GL_TRUE)) {
if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
/* found an error */
return;
}
@@ -287,61 +183,6 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
void GLAPIENTRY
_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels )
{
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
FLUSH_CURRENT(ctx, 0);
if (width < 0 || height < 0) {
_mesa_error( ctx, GL_INVALID_VALUE,
"glReadPixels(width=%d height=%d)", width, height );
return;
}
if (ctx->NewState)
_mesa_update_state(ctx);
if (error_check_format_type(ctx, format, type, GL_FALSE)) {
/* found an error */
return;
}
if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
_mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
"glReadPixels(incomplete framebuffer)" );
return;
}
if (!_mesa_source_buffer_exists(ctx, format)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
return;
}
if (ctx->Pack.BufferObj->Name) {
if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
format, type, pixels)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glReadPixels(invalid PBO access)");
return;
}
if (ctx->Pack.BufferObj->Pointer) {
/* buffer is mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
return;
}
}
ctx->Driver.ReadPixels(ctx, x, y, width, height,
format, type, &ctx->Pack, pixels);
}
void GLAPIENTRY
_mesa_Bitmap( GLsizei width, GLsizei height,
GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,

View File

@@ -1,9 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 3.5
* Version: 7.1
*
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2008 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"),
@@ -28,7 +27,7 @@
#define DRAWPIXELS_H
#include "mtypes.h"
#include "main/glheader.h"
extern void GLAPIENTRY
@@ -36,11 +35,6 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
GLenum format, GLenum type, const GLvoid *pixels );
extern void GLAPIENTRY
_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels );
extern void GLAPIENTRY
_mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
GLenum type );

191
src/mesa/main/readpix.c Normal file
View File

@@ -0,0 +1,191 @@
/*
* Mesa 3-D graphics library
* Version: 7.1
*
* Copyright (C) 1999-2008 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "glheader.h"
#include "imports.h"
#include "bufferobj.h"
#include "context.h"
#include "readpix.h"
#include "framebuffer.h"
#include "image.h"
#include "state.h"
/**
* Do error checking of the format/type parameters to glReadPixels and
* glDrawPixels.
* \param drawing if GL_TRUE do checking for DrawPixels, else do checking
* for ReadPixels.
* \return GL_TRUE if error detected, GL_FALSE if no errors
*/
GLboolean
_mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
GLboolean drawing)
{
const char *readDraw = drawing ? "Draw" : "Read";
if (ctx->Extensions.EXT_packed_depth_stencil
&& type == GL_UNSIGNED_INT_24_8_EXT
&& format != GL_DEPTH_STENCIL_EXT) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
return GL_TRUE;
}
/* basic combinations test */
if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"gl%sPixels(format or type)", readDraw);
return GL_TRUE;
}
/* additional checks */
switch (format) {
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_RGB:
case GL_BGR:
case GL_RGBA:
case GL_BGRA:
case GL_ABGR_EXT:
if (drawing && !ctx->Visual.rgbMode) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"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)");
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 ((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 ((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;
}
break;
case GL_DEPTH_STENCIL_EXT:
if (!ctx->Extensions.EXT_packed_depth_stencil ||
type != GL_UNSIGNED_INT_24_8_EXT) {
_mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
return GL_TRUE;
}
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;
}
break;
default:
/* this should have been caught in _mesa_is_legal_format_type() */
_mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
return GL_TRUE;
}
/* no errors */
return GL_FALSE;
}
void GLAPIENTRY
_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels )
{
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
FLUSH_CURRENT(ctx, 0);
if (width < 0 || height < 0) {
_mesa_error( ctx, GL_INVALID_VALUE,
"glReadPixels(width=%d height=%d)", width, height );
return;
}
if (ctx->NewState)
_mesa_update_state(ctx);
if (_mesa_error_check_format_type(ctx, format, type, GL_FALSE)) {
/* found an error */
return;
}
if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
_mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
"glReadPixels(incomplete framebuffer)" );
return;
}
if (!_mesa_source_buffer_exists(ctx, format)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
return;
}
if (ctx->Pack.BufferObj->Name) {
if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
format, type, pixels)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glReadPixels(invalid PBO access)");
return;
}
if (ctx->Pack.BufferObj->Pointer) {
/* buffer is mapped - that's an error */
_mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
return;
}
}
ctx->Driver.ReadPixels(ctx, x, y, width, height,
format, type, &ctx->Pack, pixels);
}

42
src/mesa/main/readpix.h Normal file
View File

@@ -0,0 +1,42 @@
/*
* Mesa 3-D graphics library
* Version: 7.1
*
* Copyright (C) 1999-2008 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef READPIXELS_H
#define READPIXELS_H
#include "main/mtypes.h"
extern GLboolean
_mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
GLboolean drawing);
extern void GLAPIENTRY
_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels );
#endif

View File

@@ -45,6 +45,7 @@ pixel.c \
pixelstore.c \
points.c \
polygon.c \
readpix.c \
rastpos.c \
rbadaptors.c \
renderbuffer.c \
@@ -121,6 +122,7 @@ points.h \
polygon.h \
rastpos.h \
rbadaptors.h \
readpix.h \
renderbuffer.h \
simple_list.h \
state.h \

View File

@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.5.1
* Version: 7.1
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2008 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"),
@@ -79,6 +79,7 @@
#include "queryobj.h"
#endif
#include "rastpos.h"
#include "readpix.h"
#include "state.h"
#include "stencil.h"
#include "teximage.h"

View File

@@ -49,6 +49,7 @@ MAIN_SOURCES = \
main/queryobj.c \
main/rastpos.c \
main/rbadaptors.c \
main/readpix.c \
main/renderbuffer.c \
main/shaders.c \
main/state.c \