texstore.c revision 19d1e432612cf7db797da11793b13a6c1c6aac16
119d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes/* $Id: texstore.c,v 1.19 2001/03/27 19:18:02 gareth Exp $ */
28e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
38e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
48e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Mesa 3-D graphics library
58e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Version:  3.5
68e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
78e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
88e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
98e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a
108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * copy of this software and associated documentation files (the "Software"),
118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * to deal in the Software without restriction, including without limitation
128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense,
138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * and/or sell copies of the Software, and to permit persons to whom the
148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Software is furnished to do so, subject to the following conditions:
158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The above copyright notice and this permission notice shall be included
178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * in all copies or substantial portions of the Software.
188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Authors:
298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   Brian Paul
308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The functions in this file are mostly related to software texture fallbacks.
358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This includes texture image transfer/packing and texel fetching.
368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Hardware drivers will likely override most of this.
378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
41e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul#include "colormac.h"
428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "context.h"
438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "convolve.h"
448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "image.h"
458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "macros.h"
468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "mem.h"
47371ef9c058b0d59bfb62689b64af1b29a2214d9eGareth Hughes#include "texformat.h"
488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "teximage.h"
498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "texstore.h"
508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Given an internal texture format enum or 1, 2, 3, 4 return the
548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * corresponding _base_ internal format:  GL_ALPHA, GL_LUMINANCE,
558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA.  Return the
568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * number of components for the format.  Return -1 if invalid enum.
576b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes *
586b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes * GH: Do we really need this?  We have the number of bytes per texel
596b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes * in the texture format structures, so why don't we just use that?
608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLint
628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulcomponents_in_intformat( GLint format )
638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   switch (format) {
658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_ALPHA:
668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_ALPHA4:
678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_ALPHA8:
688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_ALPHA12:
698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_ALPHA16:
708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 1;
718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case 1:
728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE:
738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE4:
748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE8:
758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE12:
768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE16:
778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 1;
788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case 2:
798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE_ALPHA:
808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE4_ALPHA4:
818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE6_ALPHA2:
828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE8_ALPHA8:
838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE12_ALPHA4:
848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE12_ALPHA12:
858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_LUMINANCE16_ALPHA16:
868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 2;
878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_INTENSITY:
888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_INTENSITY4:
898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_INTENSITY8:
908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_INTENSITY12:
918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_INTENSITY16:
928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 1;
938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case 3:
948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB:
958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_R3_G3_B2:
968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB4:
978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB5:
988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB8:
998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB10:
1008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB12:
1018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB16:
1028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 3;
1038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case 4:
1048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA:
1058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA2:
1068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA4:
1078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB5_A1:
1088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA8:
1098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGB10_A2:
1108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA12:
1118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_RGBA16:
1128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 4;
1138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX:
1148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX1_EXT:
1158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX2_EXT:
1168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX4_EXT:
1178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX8_EXT:
1188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX12_EXT:
1198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      case GL_COLOR_INDEX16_EXT:
1208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return 1;
121f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      case GL_DEPTH_COMPONENT:
122f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      case GL_DEPTH_COMPONENT16_SGIX:
123f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      case GL_DEPTH_COMPONENT24_SGIX:
124f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      case GL_DEPTH_COMPONENT32_SGIX:
125f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul         return 1;
1268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      default:
1278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return -1;  /* error */
1288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
1298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
1308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
1338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This function is used to transfer the user's image data into a texture
1348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * image buffer.  We handle both full texture images and subtexture images.
1358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * We also take care of all image transfer operations here, including
1368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convolution, scale/bias, colortables, etc.
1378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
1388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The destination texel channel type is always GLchan.
1398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
1408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * A hardware driver may use this as a helper routine to unpack and
1418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * apply pixel transfer ops into a temporary image buffer.  Then,
1428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convert the temporary image into the special hardware format.
1438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
1448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Input:
1458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   dimensions - 1, 2, or 3
1468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
1478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *               GL_RGB or GL_RGBA
14856671022f97cfbc199a47b3338125431e42030eeBrian Paul *   texDestAddr - destination image address
1498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images
1508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   dstXoffset, dstYoffset, dstZoffset - position to store the image within
1518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *      the destination 3D texture
15256671022f97cfbc199a47b3338125431e42030eeBrian Paul *   dstRowStride, dstImageStride - dest image strides in bytes
1538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc)
1548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc
1558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *   srcPacking - describes packing of incoming image.
1568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
1578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
1588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
1590299ad753224372c7a6147f598fdad33f576a714Brian Paul                        GLenum texDestFormat, GLvoid *texDestAddr,
1608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        GLint srcWidth, GLint srcHeight, GLint srcDepth,
1618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
1628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        GLint dstRowStride, GLint dstImageStride,
1638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        GLenum srcFormat, GLenum srcType,
1648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        const GLvoid *srcAddr,
1658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                        const struct gl_pixelstore_attrib *srcPacking)
1668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
1678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   GLint texComponents;
1688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(ctx);
1708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dimensions >= 1 && dimensions <= 3);
17156671022f97cfbc199a47b3338125431e42030eeBrian Paul   ASSERT(texDestAddr);
1728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(srcWidth >= 1);
1738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(srcHeight >= 1);
1748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(srcDepth >= 1);
1758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dstXoffset >= 0);
1768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dstYoffset >= 0);
1778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dstZoffset >= 0);
1788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dstRowStride >= 0);
1798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(dstImageStride >= 0);
1808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(srcAddr);
1818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   ASSERT(srcPacking);
1828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1830299ad753224372c7a6147f598fdad33f576a714Brian Paul   texComponents = components_in_intformat(texDestFormat);
1848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* try common 2D texture cases first */
186f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul   if (!ctx->_ImageTransferState && dimensions == 2 && srcType == CHAN_TYPE) {
1878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
1880299ad753224372c7a6147f598fdad33f576a714Brian Paul      if (srcFormat == texDestFormat) {
1898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
1908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          * GL_LUMINANCE_ALPHA, etc. texture formats.  Use memcpy().
1918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          */
1928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         const GLchan *src = (const GLchan *) _mesa_image_address(
1938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                   srcPacking, srcAddr, srcWidth, srcHeight,
1948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                   srcFormat, srcType, 0, 0, 0);
1958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
1968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                               srcWidth, srcFormat, srcType);
1978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         const GLint widthInBytes = srcWidth * texComponents * sizeof(GLchan);
19856671022f97cfbc199a47b3338125431e42030eeBrian Paul         GLchan *dst = (GLchan *) texDestAddr + dstYoffset * dstRowStride
1998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                      + dstXoffset * texComponents;
2008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) {
2018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            MEMCPY(dst, src, srcHeight * widthInBytes);
2028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
2038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         else {
2048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLint i;
2058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (i = 0; i < srcHeight; i++) {
2068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               MEMCPY(dst, src, widthInBytes);
2078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               src += srcRowStride;
2088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               dst += dstRowStride;
2098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
2108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
2118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return;  /* all done */
2128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      }
2130299ad753224372c7a6147f598fdad33f576a714Brian Paul      else if (srcFormat == GL_RGBA && texDestFormat == GL_RGB) {
2148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         /* commonly used by Quake */
2158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         const GLchan *src = (const GLchan *) _mesa_image_address(
2168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                   srcPacking, srcAddr, srcWidth, srcHeight,
2178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                   srcFormat, srcType, 0, 0, 0);
2188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
2198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                               srcWidth, srcFormat, srcType);
22056671022f97cfbc199a47b3338125431e42030eeBrian Paul         GLchan *dst = (GLchan *) texDestAddr + dstYoffset * dstRowStride
2218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                      + dstXoffset * texComponents;
2228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLint i, j;
2238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         for (i = 0; i < srcHeight; i++) {
2248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            const GLchan *s = src;
2258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLchan *d = dst;
2268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (j = 0; j < srcWidth; j++) {
2278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               *d++ = *s++;  /*red*/
2288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               *d++ = *s++;  /*green*/
2298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               *d++ = *s++;  /*blue*/
2308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               s++;          /*alpha*/
2318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
2328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            src += srcRowStride;
2338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            dst += dstRowStride;
2348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
2358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return;  /* all done */
2368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      }
2378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
2388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
2398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /*
2408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * General case solutions
2418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    */
2420299ad753224372c7a6147f598fdad33f576a714Brian Paul   if (texDestFormat == GL_COLOR_INDEX) {
2438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* color index texture */
2441ceda0f84fdfe07951071fdf4fa643d07f09a4d7Brian Paul      const GLenum texType = CHAN_TYPE;
2458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      GLint img, row;
24656671022f97cfbc199a47b3338125431e42030eeBrian Paul      GLchan *dest = (GLchan *) texDestAddr + dstZoffset * dstImageStride
2478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                    + dstYoffset * dstRowStride
2488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                    + dstXoffset * texComponents;
2498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      for (img = 0; img < srcDepth; img++) {
2508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLchan *destRow = dest;
2518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         for (row = 0; row < srcHeight; row++) {
2528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            const GLvoid *src = _mesa_image_address(srcPacking,
2538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
2548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            _mesa_unpack_index_span(ctx, srcWidth, texType, destRow,
2558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                    srcType, src, srcPacking,
2568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                    ctx->_ImageTransferState);
2578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            destRow += dstRowStride;
2588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
2598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         dest += dstImageStride;
2608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      }
2618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
2620299ad753224372c7a6147f598fdad33f576a714Brian Paul   else if (texDestFormat == GL_DEPTH_COMPONENT) {
263f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      /* Depth texture (shadow maps) */
264f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      GLint img, row;
26556671022f97cfbc199a47b3338125431e42030eeBrian Paul      GLubyte *dest = (GLubyte *) texDestAddr
26656671022f97cfbc199a47b3338125431e42030eeBrian Paul                    + dstZoffset * dstImageStride
267f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                    + dstYoffset * dstRowStride
268f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                    + dstXoffset * texComponents;
269f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      for (img = 0; img < srcDepth; img++) {
27056671022f97cfbc199a47b3338125431e42030eeBrian Paul         GLubyte *destRow = dest;
271f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul         for (row = 0; row < srcHeight; row++) {
272f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul            const GLvoid *src = _mesa_image_address(srcPacking,
273f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
27456671022f97cfbc199a47b3338125431e42030eeBrian Paul            _mesa_unpack_depth_span(ctx, srcWidth, (GLfloat *) destRow,
275e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul                                    srcType, src, srcPacking);
276f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul            destRow += dstRowStride;
277f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul         }
278f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul         dest += dstImageStride;
279f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul      }
280f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul   }
2818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   else {
2828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* regular, color texture */
2838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) ||
2848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) ||
2858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) {
2868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         /*
2878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          * Fill texture image with convolution
2888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          */
2898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLint img, row;
2908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLint convWidth = srcWidth, convHeight = srcHeight;
2918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLfloat *tmpImage, *convImage;
2928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
2938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         if (!tmpImage) {
29408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
2958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            return;
2968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
2978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
2988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         if (!convImage) {
29908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
3008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            FREE(tmpImage);
3018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            return;
3028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
3038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         for (img = 0; img < srcDepth; img++) {
3058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            const GLfloat *srcf;
3068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLfloat *dstf = tmpImage;
3078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLchan *dest;
3088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            /* unpack and do transfer ops up to convolution */
3108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (row = 0; row < srcHeight; row++) {
3118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               const GLvoid *src = _mesa_image_address(srcPacking,
3128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                              srcAddr, srcWidth, srcHeight,
3138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                              srcFormat, srcType, img, row, 0);
3148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf,
3158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                         srcFormat, srcType, src, srcPacking,
3168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                         ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
3178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                         GL_TRUE);
3188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               dstf += srcWidth * 4;
3198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
3208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            /* convolve */
3228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            if (dimensions == 1) {
3238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               ASSERT(ctx->Pixel.Convolution1DEnabled);
3248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
3258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
3268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            else {
3278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               if (ctx->Pixel.Convolution2DEnabled) {
3288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                  _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
3298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                          tmpImage, convImage);
3308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               }
3318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               else {
3328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                  ASSERT(ctx->Pixel.Separable2DEnabled);
3338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                  _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
3348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                           tmpImage, convImage);
3358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               }
3368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
3378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            /* packing and transfer ops after convolution */
3398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            srcf = convImage;
34056671022f97cfbc199a47b3338125431e42030eeBrian Paul            dest = (GLchan *) texDestAddr + (dstZoffset + img) * dstImageStride
3418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                 + dstYoffset * dstRowStride;
3428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (row = 0; row < convHeight; row++) {
3438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               _mesa_pack_float_rgba_span(ctx, convWidth,
3448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                          (const GLfloat (*)[4]) srcf,
3450299ad753224372c7a6147f598fdad33f576a714Brian Paul                                          texDestFormat, CHAN_TYPE,
3468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                          dest, &_mesa_native_packing,
3478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                          ctx->_ImageTransferState
3488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                          & IMAGE_POST_CONVOLUTION_BITS);
3498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               srcf += convWidth * 4;
3508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               dest += dstRowStride;
3518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
3528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
3538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         FREE(convImage);
3558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         FREE(tmpImage);
3568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      }
3578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      else {
3588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         /*
3598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          * no convolution
3608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul          */
3618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         GLint img, row;
36256671022f97cfbc199a47b3338125431e42030eeBrian Paul         GLchan *dest = (GLchan *) texDestAddr + dstZoffset * dstImageStride
3638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       + dstYoffset * dstRowStride
3648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       + dstXoffset * texComponents;
3658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         for (img = 0; img < srcDepth; img++) {
3668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLchan *destRow = dest;
3678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (row = 0; row < srcHeight; row++) {
3688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               const GLvoid *srcRow = _mesa_image_address(srcPacking,
3698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                              srcAddr, srcWidth, srcHeight,
3708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                              srcFormat, srcType, img, row, 0);
3710299ad753224372c7a6147f598fdad33f576a714Brian Paul               _mesa_unpack_chan_color_span(ctx, srcWidth, texDestFormat,
3720299ad753224372c7a6147f598fdad33f576a714Brian Paul                                       destRow, srcFormat, srcType, srcRow,
3730299ad753224372c7a6147f598fdad33f576a714Brian Paul                                       srcPacking, ctx->_ImageTransferState);
3748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               destRow += dstRowStride;
3758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            }
3768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            dest += dstImageStride;
3778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         }
3788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      }
3798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
3808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
3818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
3848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
3858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage1D().
3868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan.
3878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
3888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
3898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
3908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
3918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
3928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
3938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint internalFormat,
3948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint width, GLint border,
3958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLenum format, GLenum type, const GLvoid *pixels,
3968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       const struct gl_pixelstore_attrib *packing,
3978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_object *texObj,
3988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_image *texImage)
3998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
4008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   GLint postConvWidth = width;
40119d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   GLint texelBytes;
4028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
4048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
4058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
4068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* setup the teximage struct's fields */
4082c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   _mesa_init_tex_format( ctx, internalFormat, texImage );
4092c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   texImage->FetchTexel = texImage->TexFormat->FetchTexel1D;
4108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
41119d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texelBytes = texImage->TexFormat->TexelBytes;
41219d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes
4138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* allocate memory */
41419d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texImage->Data = (GLchan *) MALLOC(postConvWidth * texelBytes);
4158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (!texImage->Data)
4168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;      /* out of memory */
4178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* unpack image, apply transfer ops and store in texImage->Data */
41956671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 1, texImage->Format, texImage->Data,
4208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, 1, 1, 0, 0, 0,
4218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstRowStride */
4228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstImageStride */
4238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
4248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
4258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
4288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage2D().
4298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan.
4308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
4318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
4328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
4338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
4348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
4358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
4368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint internalFormat,
4378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint width, GLint height, GLint border,
4388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLenum format, GLenum type, const void *pixels,
4398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       const struct gl_pixelstore_attrib *packing,
4408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_object *texObj,
4418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_image *texImage)
4428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
4438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   GLint postConvWidth = width, postConvHeight = height;
4442c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   GLint texelBytes;
4458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
4478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
4488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                         &postConvHeight);
4498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   }
4508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* setup the teximage struct's fields */
4522c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   _mesa_init_tex_format( ctx, internalFormat, texImage );
4532c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   texImage->FetchTexel = texImage->TexFormat->FetchTexel2D;
4542c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes
4552c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   texelBytes = texImage->TexFormat->TexelBytes;
4568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* allocate memory */
4582c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   texImage->Data = (GLchan *) MALLOC(postConvWidth * postConvHeight *
4592c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes                                      texelBytes);
4608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (!texImage->Data)
4618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;      /* out of memory */
4628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* unpack image, apply transfer ops and store in texImage->Data */
46456671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 2, texImage->Format, texImage->Data,
4658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, height, 1, 0, 0, 0,
4662c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes                           texImage->Width * texelBytes,
4678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstImageStride */
4688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
4698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
4708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
4748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage3D().
4758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan.
4768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
4778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
4788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *
4798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
4808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
4818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
4828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint internalFormat,
4838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLint width, GLint height, GLint depth, GLint border,
4848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       GLenum format, GLenum type, const void *pixels,
4858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       const struct gl_pixelstore_attrib *packing,
4868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_object *texObj,
4878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                       struct gl_texture_image *texImage)
4888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
48919d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   const struct gl_texture_format *texFormat;
4902c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   GLint texelBytes;
4918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* setup the teximage struct's fields */
4932c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   _mesa_init_tex_format( ctx, internalFormat, texImage );
49419d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texImage->FetchTexel = texFormat->FetchTexel3D;
4952c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes
49619d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texelBytes = texFormat->TexelBytes;
4978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
4988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* allocate memory */
4992c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   texImage->Data = (GLchan *) MALLOC(width * height * depth * texelBytes);
5008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (!texImage->Data)
5018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;      /* out of memory */
5028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* unpack image, apply transfer ops and store in texImage->Data */
50456671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 3, texImage->Format, texImage->Data,
5058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, height, depth, 0, 0, 0,
5062c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes                           texImage->Width * texelBytes,
5072c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes                           texImage->Width * texImage->Height * texelBytes,
5088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
5098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
5108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
5158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage1D().
5168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
5178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
5188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
5198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint xoffset, GLint width,
5208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLenum format, GLenum type, const void *pixels,
5218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          const struct gl_pixelstore_attrib *packing,
5228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_object *texObj,
5238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_image *texImage)
5248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
52556671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 1, texImage->Format, texImage->Data,
5268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, 1, 1, /* src size */
5278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           xoffset, 0, 0, /* dest offsets */
5288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstRowStride */
5298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstImageStride */
5308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
5328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
5358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage2D().
5368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
5378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
5388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level,
5398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint xoffset, GLint yoffset,
5408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint width, GLint height,
5418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLenum format, GLenum type, const void *pixels,
5428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          const struct gl_pixelstore_attrib *packing,
5438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_object *texObj,
5448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_image *texImage)
5458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
5468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   const GLint components = components_in_intformat(texImage->IntFormat);
547f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul   const GLint compSize = _mesa_sizeof_type(texImage->Type);
54856671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 2, texImage->Format, texImage->Data,
5498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, height, 1, /* src size */
5508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           xoffset, yoffset, 0, /* dest offsets */
551f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                           texImage->Width * components * compSize,
5528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           0, /* dstImageStride */
5538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
5548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
5558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
5588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage3D().
5598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
5608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
5618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
5628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint xoffset, GLint yoffset, GLint zoffset,
5638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint width, GLint height, GLint depth,
5648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLenum format, GLenum type, const void *pixels,
5658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          const struct gl_pixelstore_attrib *packing,
5668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_object *texObj,
5678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          struct gl_texture_image *texImage)
5688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
5698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   const GLint components = components_in_intformat(texImage->IntFormat);
570f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul   const GLint compSize = _mesa_sizeof_type(texImage->Type);
57156671022f97cfbc199a47b3338125431e42030eeBrian Paul   _mesa_transfer_teximage(ctx, 3, texImage->Format, texImage->Data,
5728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           width, height, depth, /* src size */
5738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           xoffset, yoffset, xoffset, /* dest offsets */
574f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                           texImage->Width * components * compSize,
5758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           texImage->Width * texImage->Height * components
576f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul                           * compSize,
5778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                           format, type, pixels, packing);
5788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
5798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul
5832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/*
5848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage1D()
5858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
5868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
5878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage1d(GLcontext *ctx, GLenum target, GLint level,
5888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint internalFormat,
5898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint width, GLint border,
5908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLsizei imageSize, const GLvoid *data,
5918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_object *texObj,
5928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_image *texImage)
5938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
5948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* Nothing here.
5958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * The device driver has to do it all.
5968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    */
5978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
5988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
5998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
6028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage2D()
6038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
6048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
6058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
6068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint internalFormat,
6078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint width, GLint height, GLint border,
6088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLsizei imageSize, const GLvoid *data,
6098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_object *texObj,
6108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_image *texImage)
6118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
6128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* Nothing here.
6138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * The device driver has to do it all.
6148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    */
6158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
6168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
6208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage3D()
6218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
6228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid
6238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage3d(GLcontext *ctx, GLenum target, GLint level,
6248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint internalFormat,
6258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint width, GLint height, GLint depth,
6268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLint border,
6278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  GLsizei imageSize, const GLvoid *data,
6288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_object *texObj,
6298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                                  struct gl_texture_image *texImage)
6308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
6318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* Nothing here.
6328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * The device driver has to do it all.
6338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    */
6348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
6358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/*
6428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the fallback for Driver.TestProxyTexImage().
6438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */
6448e39ad2cd67d49be40ff0822f3269affdf83d601Brian PaulGLboolean
6458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
6468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint internalFormat, GLenum format, GLenum type,
6478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                          GLint width, GLint height, GLint depth, GLint border)
6488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{
6498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   struct gl_texture_unit *texUnit;
6508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   struct gl_texture_object *texObj;
6518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   struct gl_texture_image *texImage;
65219d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   const struct gl_texture_format *texFormat;
6538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   (void) format;
6558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   (void) type;
6568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
6588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   texObj = _mesa_select_tex_object(ctx, texUnit, target);
6598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
6608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
6618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   /* We always pass.
6628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * The core Mesa code will have already tested the image size, etc.
6638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * Drivers may have more stringent texture limits to enforce and will
6648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    * have to override this function.
6658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul    */
6666628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   /* setup the teximage struct's fields */
6672c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   _mesa_init_tex_format( ctx, internalFormat, texImage );
6688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
66919d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texFormat = texImage->TexFormat;
67019d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texImage->Format = texFormat->BaseFormat;
67119d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes   texImage->Type = texFormat->BaseType;
67219d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes
6738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   return GL_TRUE;
6748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}
675