/*
 * (c) Copyright 1995, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED
 * Permission to use, copy, modify, and distribute this software for
 * any purpose and without fee is hereby granted, provided that the above
 * copyright notice appear in all copies and that both the copyright notice
 * and this permission notice appear in supporting documentation, and that
 * the name of Silicon Graphics, Inc. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission.
 *
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * US Government Users Restricted Rights
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
 * clause at DFARS 252.227-7013 and/or in similar or successor
 * clauses in the FAR or the DOD or NASA FAR Supplement.
 * Unpublished-- rights reserved under the copyright laws of the
 * United States.  Contractor/manufacturer is Silicon Graphics,
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
 *
 * Author: John Spitzer, SGI Applied Engineering
 *
 */

/* Define calls if using function pointers or not */
#ifdef FUNCTION_PTRS
  #define COPYPIX_CALL   (*copyPixels)(x, y, width, height, type);
  #if (RASTERPOS_DIM == 2)
    #define RASTERPOS_CALL   (*rasterPos2fv)(dstPtr); dstPtr += 2;
  #else
    #define RASTERPOS_CALL   (*rasterPos3fv)(dstPtr); dstPtr += 3;
  #endif
#else
  #define COPYPIX_CALL   glCopyPixels(x, y, width, height, type);
  #if (RASTERPOS_DIM == 2)
    #define RASTERPOS_CALL   glRasterPos2fv(dstPtr); dstPtr += 2;
  #else
    #define RASTERPOS_CALL   glRasterPos3fv(dstPtr); dstPtr += 3;
  #endif
#endif

void FUNCTION (TestPtr thisTest)
{
    CopyPixelsPtr this = (CopyPixelsPtr)thisTest;
    int iterations = this->iterations;
    int numDrawn = this->numDrawn;
    int width = this->copyPixelsWidth;
    int height = this->copyPixelsHeight;
    int type = this->copyPixelsType;
    int i, j;
    GLint x, y;
    GLfloat *dstData = this->traversalData;
    GLint *srcData = this->subImageData;
    GLfloat *dstPtr = dstData;
    GLint *srcPtr = srcData;
  #ifdef FUNCTION_PTRS
   #ifdef WIN32
     void (APIENTRY *copyPixels)(GLint, GLint, GLsizei, GLsizei, GLenum) = glCopyPixels;
    #if (RASTERPOS_DIM == 2)
     void (APIENTRY *rasterPos2fv)(const GLfloat*) = glRasterPos2fv;
    #else
     void (APIENTRY *rasterPos3fv)(const GLfloat*) = glRasterPos3fv;
    #endif
   #else
    void (*copyPixels)(GLint, GLint, GLsizei, GLsizei, GLenum) = glCopyPixels;
    #if (RASTERPOS_DIM == 2)
     void (*rasterPos2fv)(const GLfloat*) = glRasterPos2fv;
    #else
     void (*rasterPos3fv)(const GLfloat*) = glRasterPos3fv;
    #endif
   #endif
  #endif

    for (i = iterations; i > 0; i--) {
	for (j = numDrawn; j > 0; j--) {
	    RASTERPOS_CALL
	    x = *srcPtr++;
	    y = *srcPtr++;
	    COPYPIX_CALL
	}
	dstPtr = dstData;
	srcPtr = srcData;
    }
}

#undef COPYPIX_CALL
#undef RASTERPOS_CALL
