ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

readpix.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.1
00004  *
00005  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 #include "glheader.h"
00026 #include "imports.h"
00027 #include "bufferobj.h"
00028 #include "context.h"
00029 #include "readpix.h"
00030 #include "framebuffer.h"
00031 #include "image.h"
00032 #include "state.h"
00033 
00034 
00042 GLboolean
00043 _mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
00044                               GLboolean drawing)
00045 {
00046    const char *readDraw = drawing ? "Draw" : "Read";
00047 
00048    if (ctx->Extensions.EXT_packed_depth_stencil
00049        && type == GL_UNSIGNED_INT_24_8_EXT
00050        && format != GL_DEPTH_STENCIL_EXT) {
00051       _mesa_error(ctx, GL_INVALID_OPERATION,
00052                   "gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
00053       return GL_TRUE;
00054    }
00055 
00056    /* basic combinations test */
00057    if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
00058       _mesa_error(ctx, GL_INVALID_ENUM,
00059                   "gl%sPixels(format or type)", readDraw);
00060       return GL_TRUE;
00061    }
00062 
00063    /* additional checks */
00064    switch (format) {
00065    case GL_RED:
00066    case GL_GREEN:
00067    case GL_BLUE:
00068    case GL_ALPHA:
00069    case GL_LUMINANCE:
00070    case GL_LUMINANCE_ALPHA:
00071    case GL_RGB:
00072    case GL_BGR:
00073    case GL_RGBA:
00074    case GL_BGRA:
00075    case GL_ABGR_EXT:
00076       if (drawing && !ctx->Visual.rgbMode) {
00077          _mesa_error(ctx, GL_INVALID_OPERATION,
00078                    "glDrawPixels(drawing RGB pixels into color index buffer)");
00079          return GL_TRUE;
00080       }
00081       if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
00082          _mesa_error(ctx, GL_INVALID_OPERATION,
00083                      "glReadPixels(no color buffer)");
00084          return GL_TRUE;
00085       }
00086       break;
00087    case GL_COLOR_INDEX:
00088       if (!drawing && ctx->Visual.rgbMode) {
00089          _mesa_error(ctx, GL_INVALID_OPERATION,
00090                     "glReadPixels(reading color index format from RGB buffer)");
00091          return GL_TRUE;
00092       }
00093       if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
00094          _mesa_error(ctx, GL_INVALID_OPERATION,
00095                      "glReadPixels(no color buffer)");
00096          return GL_TRUE;
00097       }
00098       break;
00099    case GL_STENCIL_INDEX:
00100       if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
00101           (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
00102          _mesa_error(ctx, GL_INVALID_OPERATION,
00103                      "gl%sPixels(no stencil buffer)", readDraw);
00104          return GL_TRUE;
00105       }
00106       break;
00107    case GL_DEPTH_COMPONENT:
00108       if ((drawing && !_mesa_dest_buffer_exists(ctx, format))) {
00109          _mesa_error(ctx, GL_INVALID_OPERATION,
00110                      "gl%sPixels(no depth buffer)", readDraw);
00111          return GL_TRUE;
00112       }
00113       break;
00114    case GL_DEPTH_STENCIL_EXT:
00115       if (!ctx->Extensions.EXT_packed_depth_stencil ||
00116           type != GL_UNSIGNED_INT_24_8_EXT) {
00117          _mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
00118          return GL_TRUE;
00119       }
00120       if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
00121           (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
00122          _mesa_error(ctx, GL_INVALID_OPERATION,
00123                      "gl%sPixels(no depth or stencil buffer)", readDraw);
00124          return GL_TRUE;
00125       }
00126       break;
00127    default:
00128       /* this should have been caught in _mesa_is_legal_format_type() */
00129       _mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
00130       return GL_TRUE;
00131    }
00132 
00133    /* no errors */
00134    return GL_FALSE;
00135 }
00136       
00137 
00138 
00139 void GLAPIENTRY
00140 _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
00141           GLenum format, GLenum type, GLvoid *pixels )
00142 {
00143    GET_CURRENT_CONTEXT(ctx);
00144    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
00145 
00146    FLUSH_CURRENT(ctx, 0);
00147 
00148    if (width < 0 || height < 0) {
00149       _mesa_error( ctx, GL_INVALID_VALUE,
00150                    "glReadPixels(width=%d height=%d)", width, height );
00151       return;
00152    }
00153 
00154    if (ctx->NewState)
00155       _mesa_update_state(ctx);
00156 
00157    if (_mesa_error_check_format_type(ctx, format, type, GL_FALSE)) {
00158       /* found an error */
00159       return;
00160    }
00161 
00162    if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
00163       _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
00164                   "glReadPixels(incomplete framebuffer)" );
00165       return;
00166    }
00167 
00168    if (!_mesa_source_buffer_exists(ctx, format)) {
00169       _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
00170       return;
00171    }
00172 
00173    if (ctx->Pack.BufferObj->Name) {
00174       if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
00175                                      format, type, pixels)) {
00176          _mesa_error(ctx, GL_INVALID_OPERATION,
00177                      "glReadPixels(invalid PBO access)");
00178          return;
00179       }
00180 
00181       if (ctx->Pack.BufferObj->Pointer) {
00182          /* buffer is mapped - that's an error */
00183          _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
00184          return;
00185       }
00186    }
00187 
00188    ctx->Driver.ReadPixels(ctx, x, y, width, height,
00189               format, type, &ctx->Pack, pixels);
00190 }

Generated on Sat May 26 2012 04:19:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.