texstore.c revision cd1cefae9146fc14b35ee93a04bdb1b1590fba7b
1cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul/* $Id: texstore.c,v 1.28 2001/06/13 14:56:14 brianp 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 32e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul#include "colormac.h" 338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "context.h" 348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "convolve.h" 358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "image.h" 368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "macros.h" 378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "mem.h" 38371ef9c058b0d59bfb62689b64af1b29a2214d9eGareth Hughes#include "texformat.h" 398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "teximage.h" 408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "texstore.h" 417d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul#include "texutil.h" 428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Given an internal texture format enum or 1, 2, 3, 4 return the 468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, 478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the 488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * number of components for the format. Return -1 if invalid enum. 496b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes * 506b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes * GH: Do we really need this? We have the number of bytes per texel 516b406bf09dc18f4d84ccb636d043c990a30da4e1Gareth Hughes * in the texture format structures, so why don't we just use that? 528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLint 548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulcomponents_in_intformat( GLint format ) 558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (format) { 578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA: 588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA4: 598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA8: 608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA12: 618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA16: 628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 1: 648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE: 658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE4: 668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE8: 678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12: 688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE16: 698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 2: 718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE_ALPHA: 728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE4_ALPHA4: 738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE6_ALPHA2: 748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE8_ALPHA8: 758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12_ALPHA4: 768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12_ALPHA12: 778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE16_ALPHA16: 788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 2; 798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY: 808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY4: 818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY8: 828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY12: 838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY16: 848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 3: 868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB: 878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_R3_G3_B2: 888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB4: 898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB5: 908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB8: 918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB10: 928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB12: 938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB16: 948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 3; 958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 4: 968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA: 978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA2: 988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA4: 998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB5_A1: 1008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA8: 1018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB10_A2: 1028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA12: 1038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA16: 1048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 4; 1058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX: 1068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX1_EXT: 1078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX2_EXT: 1088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX4_EXT: 1098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX8_EXT: 1108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX12_EXT: 1118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX16_EXT: 1128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 113f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT: 114f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT16_SGIX: 115f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT24_SGIX: 116f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT32_SGIX: 117f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return 1; 1188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul default: 1198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return -1; /* error */ 1208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 1228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 1258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This function is used to transfer the user's image data into a texture 1268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * image buffer. We handle both full texture images and subtexture images. 1278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * We also take care of all image transfer operations here, including 1288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convolution, scale/bias, colortables, etc. 1298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 1308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The destination texel channel type is always GLchan. 1318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 1328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * A hardware driver may use this as a helper routine to unpack and 1338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * apply pixel transfer ops into a temporary image buffer. Then, 1348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convert the temporary image into the special hardware format. 1358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 1368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Input: 1378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * dimensions - 1, 2, or 3 1388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA, 1398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_RGB or GL_RGBA 14056671022f97cfbc199a47b3338125431e42030eeBrian Paul * texDestAddr - destination image address 1418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images 1428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * dstXoffset, dstYoffset, dstZoffset - position to store the image within 1438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * the destination 3D texture 14456671022f97cfbc199a47b3338125431e42030eeBrian Paul * dstRowStride, dstImageStride - dest image strides in bytes 1458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc) 1468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc 1478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcPacking - describes packing of incoming image. 1481c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * transferOps - mask of pixel transfer operations 1498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 1507d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paulstatic void 1517d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paultransfer_teximage(GLcontext *ctx, GLuint dimensions, 1527d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLenum texDestFormat, GLvoid *texDestAddr, 1537d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint srcWidth, GLint srcHeight, GLint srcDepth, 1547d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, 1557d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint dstRowStride, GLint dstImageStride, 1567d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLenum srcFormat, GLenum srcType, 1577d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const GLvoid *srcAddr, 1581c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul const struct gl_pixelstore_attrib *srcPacking, 1591c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLuint transferOps) 1608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 1618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint texComponents; 1628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx); 1648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dimensions >= 1 && dimensions <= 3); 16556671022f97cfbc199a47b3338125431e42030eeBrian Paul ASSERT(texDestAddr); 1668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcWidth >= 1); 1678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcHeight >= 1); 1688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcDepth >= 1); 1698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstXoffset >= 0); 1708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstYoffset >= 0); 1718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstZoffset >= 0); 1728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstRowStride >= 0); 1738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstImageStride >= 0); 1748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcAddr); 1758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcPacking); 1768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1770299ad753224372c7a6147f598fdad33f576a714Brian Paul texComponents = components_in_intformat(texDestFormat); 1788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* try common 2D texture cases first */ 1801c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (!transferOps && dimensions == 2 && srcType == CHAN_TYPE) { 1818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1820299ad753224372c7a6147f598fdad33f576a714Brian Paul if (srcFormat == texDestFormat) { 1838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA, 1848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy(). 1858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 1868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *src = (const GLchan *) _mesa_image_address( 1878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcPacking, srcAddr, srcWidth, srcHeight, 1888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, 0, 0, 0); 1898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint srcRowStride = _mesa_image_row_stride(srcPacking, 1908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcWidth, srcFormat, srcType); 1918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint widthInBytes = srcWidth * texComponents * sizeof(GLchan); 19256671022f97cfbc199a47b3338125431e42030eeBrian Paul GLchan *dst = (GLchan *) texDestAddr + dstYoffset * dstRowStride 1938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 1948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) { 1958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul MEMCPY(dst, src, srcHeight * widthInBytes); 1968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 1988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint i; 1998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < srcHeight; i++) { 2008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul MEMCPY(dst, src, widthInBytes); 2018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul src += srcRowStride; 2028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dst += dstRowStride; 2038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* all done */ 2068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2070299ad753224372c7a6147f598fdad33f576a714Brian Paul else if (srcFormat == GL_RGBA && texDestFormat == GL_RGB) { 2088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* commonly used by Quake */ 2098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *src = (const GLchan *) _mesa_image_address( 2108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcPacking, srcAddr, srcWidth, srcHeight, 2118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, 0, 0, 0); 2128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint srcRowStride = _mesa_image_row_stride(srcPacking, 2138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcWidth, srcFormat, srcType); 21456671022f97cfbc199a47b3338125431e42030eeBrian Paul GLchan *dst = (GLchan *) texDestAddr + dstYoffset * dstRowStride 2158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 2168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint i, j; 2178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < srcHeight; i++) { 2188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *s = src; 2198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *d = dst; 2208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < srcWidth; j++) { 2218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*red*/ 2228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*green*/ 2238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*blue*/ 2248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul s++; /*alpha*/ 2258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul src += srcRowStride; 2278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dst += dstRowStride; 2288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* all done */ 2308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 2348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * General case solutions 2358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 2360299ad753224372c7a6147f598fdad33f576a714Brian Paul if (texDestFormat == GL_COLOR_INDEX) { 2378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* color index texture */ 2381ceda0f84fdfe07951071fdf4fa643d07f09a4d7Brian Paul const GLenum texType = CHAN_TYPE; 2398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 24056671022f97cfbc199a47b3338125431e42030eeBrian Paul GLchan *dest = (GLchan *) texDestAddr + dstZoffset * dstImageStride 2418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride 2428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 2438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 2448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *destRow = dest; 2458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 2468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *src = _mesa_image_address(srcPacking, 2478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); 2488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_index_span(ctx, srcWidth, texType, destRow, 2491c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcType, src, srcPacking, transferOps); 2508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul destRow += dstRowStride; 2518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstImageStride; 2538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2550299ad753224372c7a6147f598fdad33f576a714Brian Paul else if (texDestFormat == GL_DEPTH_COMPONENT) { 256f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* Depth texture (shadow maps) */ 257f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint img, row; 25856671022f97cfbc199a47b3338125431e42030eeBrian Paul GLubyte *dest = (GLubyte *) texDestAddr 25956671022f97cfbc199a47b3338125431e42030eeBrian Paul + dstZoffset * dstImageStride 260f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul + dstYoffset * dstRowStride 261f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul + dstXoffset * texComponents; 262f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (img = 0; img < srcDepth; img++) { 26356671022f97cfbc199a47b3338125431e42030eeBrian Paul GLubyte *destRow = dest; 264f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (row = 0; row < srcHeight; row++) { 265f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul const GLvoid *src = _mesa_image_address(srcPacking, 266f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); 26756671022f97cfbc199a47b3338125431e42030eeBrian Paul _mesa_unpack_depth_span(ctx, srcWidth, (GLfloat *) destRow, 268e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul srcType, src, srcPacking); 269f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul destRow += dstRowStride; 270f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 271f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul dest += dstImageStride; 272f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 273f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 2758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* regular, color texture */ 2768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) || 2778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) || 2788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) { 2798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 2808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fill texture image with convolution 2818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 2828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 2838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint convWidth = srcWidth, convHeight = srcHeight; 2848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *tmpImage, *convImage; 2858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); 2868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!tmpImage) { 28708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); 2888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 2898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); 2918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!convImage) { 29208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); 2938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 2948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 2958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 2988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLfloat *srcf; 2998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *dstf = tmpImage; 3008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dest; 3018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack and do transfer ops up to convolution */ 3038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 3048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *src = _mesa_image_address(srcPacking, 3058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, 3068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, img, row, 0); 3078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf, 3088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, src, srcPacking, 3091c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul transferOps & IMAGE_PRE_CONVOLUTION_BITS, 3108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_TRUE); 3118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dstf += srcWidth * 4; 3128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convolve */ 3158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dimensions == 1) { 3168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Pixel.Convolution1DEnabled); 3178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); 3188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 3208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution2DEnabled) { 3218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, 3228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 3238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 3258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Pixel.Separable2DEnabled); 3268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, 3278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 3288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* packing and transfer ops after convolution */ 3328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcf = convImage; 33356671022f97cfbc199a47b3338125431e42030eeBrian Paul dest = (GLchan *) texDestAddr + (dstZoffset + img) * dstImageStride 3348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride; 3358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < convHeight; row++) { 3368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_pack_float_rgba_span(ctx, convWidth, 3378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (const GLfloat (*)[4]) srcf, 3380299ad753224372c7a6147f598fdad33f576a714Brian Paul texDestFormat, CHAN_TYPE, 3398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest, &_mesa_native_packing, 3401c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul transferOps 3418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul & IMAGE_POST_CONVOLUTION_BITS); 3428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcf += convWidth * 4; 3438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstRowStride; 3448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(convImage); 3488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 3498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 3518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 3528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * no convolution 3538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 3548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 35556671022f97cfbc199a47b3338125431e42030eeBrian Paul GLchan *dest = (GLchan *) texDestAddr + dstZoffset * dstImageStride 3568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride 3578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 3588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 3598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *destRow = dest; 3608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 3618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *srcRow = _mesa_image_address(srcPacking, 3628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, 3638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, img, row, 0); 3640299ad753224372c7a6147f598fdad33f576a714Brian Paul _mesa_unpack_chan_color_span(ctx, srcWidth, texDestFormat, 3650299ad753224372c7a6147f598fdad33f576a714Brian Paul destRow, srcFormat, srcType, srcRow, 3661c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcPacking, transferOps); 3678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul destRow += dstRowStride; 3688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstImageStride; 3708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 3748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 3787d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * Transfer a texture image from user space to <destAddr> applying all 3797d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * needed image transfer operations and storing the result in the format 3807d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * specified by <dstFormat>. <dstFormat> may be any format from texformat.h. 3817d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * Input: 3821c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * dimensions - 1, 2 or 3 3831c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * baseInternalFormat - base format of the internal texture format 3841c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * specified by the user. This is very important, see below. 3851c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * dstFormat - destination image format 3861c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * dstAddr - destination address 3871c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * srcWidth, srcHeight, srcDepth - size of source iamge 3881c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * dstX/Y/Zoffset - as specified by glTexSubImage 3897d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * dstRowStride - stride between dest rows in bytes 3907d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * dstImagetride - stride between dest images in bytes 3911c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * srcFormat, srcType - incoming image format and datatype 3921c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * srcAddr - source image address 3931c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * srcPacking - packing params of source image 3947d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * 3957d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * XXX this function is a bit more complicated than it should be. If 3967d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * _mesa_convert_texsubimage[123]d could handle any dest/source formats 3977d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * or if transfer_teximage() could store in any MESA_FORMAT_* format, we 3987d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul * could simplify things here. 3997d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul */ 4007d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paulvoid 4017d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul_mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions, 4021c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLenum baseInternalFormat, 4037d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const struct gl_texture_format *dstFormat, 4047d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLvoid *dstAddr, 4057d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint srcWidth, GLint srcHeight, GLint srcDepth, 4067d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, 4077d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint dstRowStride, GLint dstImageStride, 4087d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLenum srcFormat, GLenum srcType, 4097d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const GLvoid *srcAddr, 4107d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const struct gl_pixelstore_attrib *srcPacking) 4117d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul{ 4127d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const GLint dstRowStridePixels = dstRowStride / dstFormat->TexelBytes; 4137d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul const GLint dstImageStridePixels = dstImageStride / dstFormat->TexelBytes; 4147d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLboolean makeTemp; 4151c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLuint transferOps = ctx->_ImageTransferState; 4161c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLboolean freeSourceData = GL_FALSE; 4171c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLint postConvWidth = srcWidth, postConvHeight = srcHeight; 4181c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 4191c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (transferOps & IMAGE_CONVOLUTION_BIT) { 4201c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_adjust_image_for_convolution(ctx, dimensions, &postConvWidth, 4211c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul &postConvHeight); 4221c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul } 4231c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 4241c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul /* 4251c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * Consider this scenario: The user's source image is GL_RGB and the 4261c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * requested internal format is GL_LUMINANCE. Now suppose the device 4271c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * driver doesn't support GL_LUMINANCE and instead uses RGB16 as the 4281c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * texture format. In that case we still need to do an intermediate 4291c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * conversion to luminance format so that the incoming red channel gets 4301c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * replicated into the dest red, green and blue channels. The following 4311c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * code takes care of that. 4321c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul */ 4331c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (dstFormat->BaseFormat != baseInternalFormat) { 4341c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul /* Allocate storage for temporary image in the baseInternalFormat */ 4351c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul const GLint texelSize = _mesa_components_in_format(baseInternalFormat) 4361c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * sizeof(GLchan); 4371c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul const GLint bytes = texelSize * postConvWidth * postConvHeight *srcDepth; 4381c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul const GLint tmpRowStride = texelSize * postConvWidth; 4391c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul const GLint tmpImgStride = texelSize * postConvWidth * postConvHeight; 4401c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul GLvoid *tmpImage = MALLOC(bytes); 4411c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (!tmpImage) 4421c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul return; 4431c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul transfer_teximage(ctx, dimensions, baseInternalFormat, tmpImage, 4441c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcWidth, srcHeight, srcDepth, 4451c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 0, 0, 0, /* x/y/zoffset */ 4461c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul tmpRowStride, tmpImgStride, 4471c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcFormat, srcType, srcAddr, srcPacking, transferOps); 4481c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 4491c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul /* this is our new source image */ 4501c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcWidth = postConvWidth; 4511c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcHeight = postConvHeight; 4521c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcFormat = baseInternalFormat; 4531c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcType = CHAN_TYPE; 4541c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcAddr = tmpImage; 4551c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcPacking = &_mesa_native_packing; 4561c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul freeSourceData = GL_TRUE; 4571c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul transferOps = 0; /* image transfer ops were completed */ 4581c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul } 4597d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 4601c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul /* Let the optimized tex conversion functions take a crack at the 4611c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul * image conversion if the dest format is a h/w format. 4621c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul */ 4637d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (_mesa_is_hardware_tex_format(dstFormat)) { 4641c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (transferOps) { 4657d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul makeTemp = GL_TRUE; 4667d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 4677d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else { 4687d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (dimensions == 1) { 4697d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul makeTemp = !_mesa_convert_texsubimage1d(dstFormat->MesaFormat, 4707d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, 4717d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, 4727d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 4737d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, 4747d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstAddr); 4757d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 4767d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else if (dimensions == 2) { 4777d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul makeTemp = !_mesa_convert_texsubimage2d(dstFormat->MesaFormat, 4787d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, dstYoffset, 4797d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, 4807d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstRowStridePixels, 4817d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 4827d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, 4837d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstAddr); 4847d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 4857d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else { 4867d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(dimensions == 3); 4877d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul makeTemp = !_mesa_convert_texsubimage3d(dstFormat->MesaFormat, 4887d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, dstYoffset, dstZoffset, 4897d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, srcDepth, 4907d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstRowStridePixels, dstImageStridePixels, 4917d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 4927d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, dstAddr); 4937d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 4947d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (!makeTemp) { 4957d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* all done! */ 4961c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (freeSourceData) 4971c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul FREE((void *) srcAddr); 4987d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul return; 4997d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5007d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5017d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5027d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else { 5037d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* software texture format */ 5047d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul makeTemp = GL_FALSE; 5057d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5067d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5077d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (makeTemp) { 5087d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint postConvWidth = srcWidth, postConvHeight = srcHeight; 5097d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLenum tmpFormat; 5107d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLuint tmpComps, tmpTexelSize; 5117d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLint tmpRowStride, tmpImageStride; 5127d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLubyte *tmpImage; 5137d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5141c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (transferOps & IMAGE_CONVOLUTION_BIT) { 5157d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul _mesa_adjust_image_for_convolution(ctx, dimensions, &postConvWidth, 5167d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul &postConvHeight); 5177d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5187d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5191c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul tmpFormat = dstFormat->BaseFormat; 5207d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul tmpComps = _mesa_components_in_format(tmpFormat); 52136f3712e85cafef1b038189678030f6ef4f8b7e9Brian Paul tmpTexelSize = tmpComps * sizeof(GLchan); 5227d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul tmpRowStride = postConvWidth * tmpTexelSize; 5237d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul tmpImageStride = postConvWidth * postConvHeight * tmpTexelSize; 5247d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul tmpImage = (GLubyte *) MALLOC(postConvWidth * postConvHeight * 5257d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcDepth * tmpTexelSize); 5261c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (!tmpImage) { 5271c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (freeSourceData) 5281c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul FREE((void *) srcAddr); 5297d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul return; 5301c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul } 5317d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5327d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul transfer_teximage(ctx, dimensions, tmpFormat, tmpImage, 5337d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, srcDepth, 5347d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 0, 0, 0, /* x/y/zoffset */ 5357d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul tmpRowStride, tmpImageStride, 5361c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcFormat, srcType, srcAddr, srcPacking, transferOps); 5371c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 5381c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (freeSourceData) 5391c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul FREE((void *) srcAddr); 5407d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5417d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* the temp image is our new source image */ 5427d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth = postConvWidth; 5437d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcHeight = postConvHeight; 5447d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat = tmpFormat; 5457d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcType = CHAN_TYPE; 5467d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcAddr = tmpImage; 5477d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking = &_mesa_native_packing; 5481c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul freeSourceData = GL_TRUE; 5497d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5507d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5517d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (_mesa_is_hardware_tex_format(dstFormat)) { 5527d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(makeTemp); 5537d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (dimensions == 1) { 5547d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLboolean b; 5557d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul b = _mesa_convert_texsubimage1d(dstFormat->MesaFormat, 5567d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, 5577d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, 5587d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 5597d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, 5607d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstAddr); 5617d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(b); 5627d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5637d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else if (dimensions == 2) { 5647d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLboolean b; 5657d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul b = _mesa_convert_texsubimage2d(dstFormat->MesaFormat, 5667d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, dstYoffset, 5677d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, 5687d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstRowStridePixels, 5697d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 5707d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, 5717d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstAddr); 5727d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(b); 5737d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5747d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else { 5757d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul GLboolean b; 5767d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul b = _mesa_convert_texsubimage3d(dstFormat->MesaFormat, 5777d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, dstYoffset, dstZoffset, 5787d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, srcDepth, 5797d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstRowStridePixels, dstImageStridePixels, 5807d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcFormat, srcType, 5817d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcPacking, srcAddr, dstAddr); 5827d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(b); 5837d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5847d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5857d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul else { 5867d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* software format */ 5877d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(!makeTemp); 5881c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul transfer_teximage(ctx, dimensions, dstFormat->BaseFormat, dstAddr, 5897d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul srcWidth, srcHeight, srcDepth, 5907d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstXoffset, dstYoffset, dstZoffset, 5917d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul dstRowStride, dstImageStride, 5921c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul srcFormat, srcType, srcAddr, srcPacking, transferOps); 5937d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 5941c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul 5951c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul if (freeSourceData) 5961c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul FREE((void *) srcAddr); /* the temp image */ 5977d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul} 5987d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 5997d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul 6007d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul/* 6018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage1D(). 6028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 6038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 6048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 6058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 6068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 6078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 6088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, 6098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 6108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint border, 6118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const GLvoid *pixels, 6128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 6138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 6148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 6158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 6168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint postConvWidth = width; 61719d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes GLint texelBytes; 6188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 6208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 6218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6237d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* choose the texture format */ 6247d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(ctx->Driver.ChooseTextureFormat); 6257d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 6267d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul internalFormat, format, type); 6277d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(texImage->TexFormat); 6289228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel1D; 6298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 63019d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes texelBytes = texImage->TexFormat->TexelBytes; 63119d1e432612cf7db797da11793b13a6c1c6aac16Gareth Hughes 6328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 6337d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->Data = MALLOC(postConvWidth * texelBytes); 6347d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (!texImage->Data) { 6357d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 6367d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul return; 6377d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 6388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 6401c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 1, _mesa_base_tex_format(ctx, internalFormat), 6411c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 6428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, 1, 1, 0, 0, 0, 6438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstRowStride */ 6448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 6458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 6463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 6473893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 6483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 6493893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 6503893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 6513893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 6528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 6538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 6568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage2D(). 6578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 6588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 6598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 6608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 6618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 6628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 6638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, 6648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 6658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint border, 6668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 6678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 6688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 6698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 6708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 6718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint postConvWidth = width, postConvHeight = height; 6722c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GLint texelBytes; 6738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 6758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 6768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &postConvHeight); 6778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6797d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* choose the texture format */ 6807d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(ctx->Driver.ChooseTextureFormat); 6817d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 6827d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul internalFormat, format, type); 6837d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(texImage->TexFormat); 6843893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel2D; 6852c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes 6862c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texelBytes = texImage->TexFormat->TexelBytes; 6878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 6897d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->Data = MALLOC(postConvWidth * postConvHeight * texelBytes); 6907d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (!texImage->Data) { 6917d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 6927d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul return; 6937d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 6948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 6961c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 2, _mesa_base_tex_format(ctx, internalFormat), 6971c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 6988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, 1, 0, 0, 0, 6992c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texelBytes, 7008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 7018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 7023893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 7033893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 7043893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 7053893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 7063893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 7073893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 7088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 7098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 7138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage3D(). 7148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 7158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 7168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 7178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 7188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 7198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 7208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level, 7218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 7228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, GLint border, 7238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 7248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 7258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 7268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 7278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 7282c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GLint texelBytes; 7298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7307d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* choose the texture format */ 7317d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(ctx->Driver.ChooseTextureFormat); 7327d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 7337d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul internalFormat, format, type); 7347d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(texImage->TexFormat); 7359228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel3D; 7362c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes 737197c526d63e1d4ea96f29eece392cdc389770b38Brian Paul texelBytes = texImage->TexFormat->TexelBytes; 7388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 7407d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->Data = MALLOC(width * height * depth * texelBytes); 7417d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul if (!texImage->Data) { 7427d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 7437d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul return; 7447d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul } 7458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 7471c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 3, _mesa_base_tex_format(ctx, internalFormat), 7481c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 7498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 0, 0, 0, 7502c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texelBytes, 7512c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texImage->Height * texelBytes, 7528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 7533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 7543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 7553893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 7563893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 7573893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 7583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 7598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 7608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 7658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage1D(). 7668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 7678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 7688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 7698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint width, 7708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 7718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 7728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 7738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 7748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 7751c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 1, 7761c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_base_tex_format(ctx, texImage->IntFormat), 7771c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 7788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, 1, 1, /* src size */ 7798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, 0, 0, /* dest offsets */ 7808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstRowStride */ 7818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 7828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 7833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 7843893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 7853893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 7863893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 7873893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 7883893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 7898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 7908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 7938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage2D(). 7948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 7958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 7968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level, 7978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint yoffset, 7988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, 7998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 8008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 8018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 8041c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 2, 8051c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_base_tex_format(ctx, texImage->IntFormat), 8061c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 8078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, 1, /* src size */ 8088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, 0, /* dest offsets */ 80938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes texImage->Width * texImage->TexFormat->TexelBytes, 8108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 8118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 8123893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 8133893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 8143893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 8153893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 8163893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 8173893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 8188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 8228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage3D(). 8238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level, 8268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 8278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, 8288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 8298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 8308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 83338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes const GLint texelBytes = texImage->TexFormat->TexelBytes; 8341c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_transfer_teximage(ctx, 3, 8351c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul _mesa_base_tex_format(ctx, texImage->IntFormat), 8361c85aa33321821b44bea83d3dee702ab4e05f406Brian Paul texImage->TexFormat, texImage->Data, 8378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, /* src size */ 8388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, xoffset, /* dest offsets */ 83938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes texImage->Width * texelBytes, 84038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes texImage->Width * texImage->Height * texelBytes, 8418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 8423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* GL_SGIS_generate_mipmap */ 8433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (level == texObj->BaseLevel && texObj->GenerateMipmap) { 8443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], 8453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul texObj); 8463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 8478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 8522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 8538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage1D() 8548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage1d(GLcontext *ctx, GLenum target, GLint level, 8578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 8588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint border, 8598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 8608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 8638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 8648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 8658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 8718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage2D() 8728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level, 8758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 8768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint border, 8778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 8788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 8818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 8828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 8838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 8898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage3D() 8908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage3d(GLcontext *ctx, GLenum target, GLint level, 8938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 8948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, 8958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint border, 8968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 8978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 9008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 9018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 9028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 9088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the fallback for Driver.TestProxyTexImage(). 9098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9108e39ad2cd67d49be40ff0822f3269affdf83d601Brian PaulGLboolean 9118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, 9128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, GLenum format, GLenum type, 9138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, GLint border) 9148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 9158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_unit *texUnit; 9168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj; 9178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage; 9188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (void) format; 9208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (void) type; 9218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 9238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 9248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 9258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* We always pass. 9278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The core Mesa code will have already tested the image size, etc. 9289228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * If a driver has more stringent texture limits to enforce it will 9298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * have to override this function. 9308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9317d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul /* choose the texture format */ 9327d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(ctx->Driver.ChooseTextureFormat); 9337d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 9347d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul internalFormat, format, type); 9357d58f44f73be59bd3583e6dfeedf56c43f7fbd55Brian Paul assert(texImage->TexFormat); 9368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return GL_TRUE; 9388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 9403893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 9413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 9423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul/* 9433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * Average together two rows of a source image to produce a single new 9443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * row in the dest image. It's legal for the two source rows to point 9459228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * to the same data. The source width must be equal to either the 9469228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * dest width or two times the dest width. 9473893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul */ 9483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulstatic void 9499228e17bb5bf219269daeed5cbfdd912c118e926Brian Pauldo_row(const struct gl_texture_format *format, GLint srcWidth, 9509228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLvoid *srcRowA, const GLvoid *srcRowB, 9519228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLint dstWidth, GLvoid *dstRow) 9523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul{ 9539228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1; 9549228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2; 9559228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 9569228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth); 9579228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 9583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul switch (format->MesaFormat) { 9593893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_RGBA: 9603893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul { 9619228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 9623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowA)[4] = (const GLchan (*)[4]) srcRowA; 9633893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowB)[4] = (const GLchan (*)[4]) srcRowB; 9643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLchan (*dst)[4] = (GLchan (*)[4]) dstRow; 9659228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 9669228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 9679228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 9689228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 9699228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 9709228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 9719228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][2] = (rowA[j][2] + rowA[k][2] + 9729228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][2] + rowB[k][2]) >> 2; 9739228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][3] = (rowA[j][3] + rowA[k][3] + 9749228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][3] + rowB[k][3]) >> 2; 9753893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 9763893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 9773893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 9783893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_RGB: 9793893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul { 9809228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 9813893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowA)[3] = (const GLchan (*)[3]) srcRowA; 9823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowB)[3] = (const GLchan (*)[3]) srcRowB; 9833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLchan (*dst)[3] = (GLchan (*)[3]) dstRow; 9849228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 9859228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 9869228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 9879228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 9889228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 9899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 9909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][2] = (rowA[j][2] + rowA[k][2] + 9919228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][2] + rowB[k][2]) >> 2; 9923893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 9933893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 9943893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 9953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_ALPHA: 9963893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_LUMINANCE: 9973893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_INTENSITY: 9983893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_COLOR_INDEX: 9993893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul { 10009228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10013893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan *rowA = (const GLchan *) srcRowA; 10023893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan *rowB = (const GLchan *) srcRowB; 10033893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLchan *dst = (GLchan *) dstRow; 10049228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10059228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10069228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2; 10073893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 10083893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 10093893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 10103893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_LUMINANCE_ALPHA: 10113893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul { 10129228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10133893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowA)[2] = (const GLchan (*)[2]) srcRowA; 10143893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLchan (*rowB)[2] = (const GLchan (*)[2]) srcRowB; 10153893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLchan (*dst)[2] = (GLchan (*)[2]) dstRow; 10169228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10179228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10189228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 10199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 10209228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 10219228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 10223893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 10233893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 10243893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 10253893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case MESA_FORMAT_DEPTH_COMPONENT: 10268bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 10279228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10288bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLfloat *rowA = (const GLfloat *) srcRowA; 10298bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLfloat *rowB = (const GLfloat *) srcRowB; 10308bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLfloat *dst = (GLfloat *) dstRow; 10319228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10329228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10339228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) * 0.25F; 10348bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10358bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10368bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 10378bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul /* Begin hardware formats */ 10388bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_RGBA8888: 10398bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_ARGB8888: 10408bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 10419228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10428bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowA)[4] = (const GLubyte (*)[4]) srcRowA; 10438bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowB)[4] = (const GLubyte (*)[4]) srcRowB; 10448bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLubyte (*dst)[4] = (GLubyte (*)[4]) dstRow; 10459228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10469228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10479228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 10489228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 10499228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 10509228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 10519228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][2] = (rowA[j][2] + rowA[k][2] + 10529228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][2] + rowB[k][2]) >> 2; 10539228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][3] = (rowA[j][3] + rowA[k][3] + 10549228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][3] + rowB[k][3]) >> 2; 10558bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10568bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10578bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 10588bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_RGB888: 10598bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 10609228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10618bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowA)[3] = (const GLubyte (*)[3]) srcRowA; 10628bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowB)[3] = (const GLubyte (*)[3]) srcRowB; 10638bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLubyte (*dst)[3] = (GLubyte (*)[3]) dstRow; 10649228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10659228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10669228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 10679228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 10689228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 10699228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 10709228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][2] = (rowA[j][2] + rowA[k][2] + 10719228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][2] + rowB[k][2]) >> 2; 10728bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10738bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 10748bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 10758bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_RGB565: 10768bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 10779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 10788bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowA = (const GLushort *) srcRowA; 10798bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowB = (const GLushort *) srcRowB; 10808bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLushort *dst = (GLushort *) dstRow; 10819228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 10829228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 10839228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr0 = rowA[j] & 0x1f; 10849228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr1 = rowA[k] & 0x1f; 10859228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr0 = rowB[j] & 0x1f; 10869228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr1 = rowB[k] & 0x1f; 10879228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg0 = (rowA[j] >> 5) & 0x3f; 10889228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg1 = (rowA[k] >> 5) & 0x3f; 10899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg0 = (rowB[j] >> 5) & 0x3f; 10909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg1 = (rowB[k] >> 5) & 0x3f; 10919228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb0 = (rowA[j] >> 11) & 0x1f; 10929228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb1 = (rowA[k] >> 11) & 0x1f; 10939228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb0 = (rowB[j] >> 11) & 0x1f; 10949228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb1 = (rowB[k] >> 11) & 0x1f; 10958bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4; 10968bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4; 10978bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4; 10988bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul dst[i] = (blue << 11) | (green << 5) | red; 10998bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11008bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11018bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 11028bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_ARGB4444: 11038bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 11049228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 11058bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowA = (const GLushort *) srcRowA; 11068bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowB = (const GLushort *) srcRowB; 11078bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLushort *dst = (GLushort *) dstRow; 11089228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 11099228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 11109228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr0 = rowA[j] & 0xf; 11119228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr1 = rowA[k] & 0xf; 11129228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr0 = rowB[j] & 0xf; 11139228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr1 = rowB[k] & 0xf; 11149228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg0 = (rowA[j] >> 4) & 0xf; 11159228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg1 = (rowA[k] >> 4) & 0xf; 11169228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg0 = (rowB[j] >> 4) & 0xf; 11179228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg1 = (rowB[k] >> 4) & 0xf; 11189228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb0 = (rowA[j] >> 8) & 0xf; 11199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb1 = (rowA[k] >> 8) & 0xf; 11209228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb0 = (rowB[j] >> 8) & 0xf; 11219228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb1 = (rowB[k] >> 8) & 0xf; 11229228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAa0 = (rowA[j] >> 12) & 0xf; 11239228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAa1 = (rowA[k] >> 12) & 0xf; 11249228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBa0 = (rowB[j] >> 12) & 0xf; 11259228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBa1 = (rowB[k] >> 12) & 0xf; 11268bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4; 11278bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4; 11288bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4; 11298bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 4; 11308bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red; 11318bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11328bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11338bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 11348bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_ARGB1555: 11358bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 11369228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 11378bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowA = (const GLushort *) srcRowA; 11388bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLushort *rowB = (const GLushort *) srcRowB; 11398bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLushort *dst = (GLushort *) dstRow; 11409228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 11419228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 11429228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr0 = rowA[j] & 0x1f; 11439228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr1 = rowA[k] & 0x1f; 11449228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr0 = rowB[j] & 0x1f; 11459228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr1 = rowB[k] & 0xf; 11469228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg0 = (rowA[j] >> 5) & 0x1f; 11479228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg1 = (rowA[k] >> 5) & 0x1f; 11489228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg0 = (rowB[j] >> 5) & 0x1f; 11499228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg1 = (rowB[k] >> 5) & 0x1f; 11509228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb0 = (rowA[j] >> 10) & 0x1f; 11519228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb1 = (rowA[k] >> 10) & 0x1f; 11529228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb0 = (rowB[j] >> 10) & 0x1f; 11539228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb1 = (rowB[k] >> 10) & 0x1f; 11549228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAa0 = (rowA[j] >> 15) & 0x1; 11559228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAa1 = (rowA[k] >> 15) & 0x1; 11569228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBa0 = (rowB[j] >> 15) & 0x1; 11579228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBa1 = (rowB[k] >> 15) & 0x1; 11588bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4; 11598bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4; 11608bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4; 11618bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 4; 11628bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red; 11638bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11648bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11658bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 11668bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_AL88: 11678bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 11689228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 11698bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowA)[2] = (const GLubyte (*)[2]) srcRowA; 11708bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte (*rowB)[2] = (const GLubyte (*)[2]) srcRowB; 11718bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLubyte (*dst)[2] = (GLubyte (*)[2]) dstRow; 11729228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 11739228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 11749228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][0] = (rowA[j][0] + rowA[k][0] + 11759228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][0] + rowB[k][0]) >> 2; 11769228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i][1] = (rowA[j][1] + rowA[k][1] + 11779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul rowB[j][1] + rowB[k][1]) >> 2; 11788bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11798bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 11808bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 11818bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_RGB332: 11828bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 11839228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 11848bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte *rowA = (const GLubyte *) srcRowA; 11858bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte *rowB = (const GLubyte *) srcRowB; 11868bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLubyte *dst = (GLubyte *) dstRow; 11879228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 11889228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 11899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr0 = rowA[j] & 0x3; 11909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAr1 = rowA[k] & 0x3; 11919228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr0 = rowB[j] & 0x3; 11929228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBr1 = rowB[k] & 0x3; 11939228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg0 = (rowA[j] >> 2) & 0x7; 11949228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAg1 = (rowA[k] >> 2) & 0x7; 11959228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg0 = (rowB[j] >> 2) & 0x7; 11969228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBg1 = (rowB[k] >> 2) & 0x7; 11979228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb0 = (rowA[j] >> 5) & 0x7; 11989228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowAb1 = (rowA[k] >> 5) & 0x7; 11999228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb0 = (rowB[j] >> 5) & 0x7; 12009228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint rowBb1 = (rowB[k] >> 5) & 0x7; 12018bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 4; 12028bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 4; 12038bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 4; 12048bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul dst[i] = (blue << 5) | (green << 2) | red; 12058bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 12068bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 12078bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 12088bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_A8: 12098bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_L8: 12108bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_I8: 12118bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul case MESA_FORMAT_CI8: 12128bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul { 12139228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLuint i, j, k; 12148bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte *rowA = (const GLubyte *) srcRowA; 12158bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul const GLubyte *rowB = (const GLubyte *) srcRowB; 12168bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul GLubyte *dst = (GLubyte *) dstRow; 12179228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (i = j = 0, k = k0; i < dstWidth; 12189228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul i++, j += colStride, k += colStride) { 12199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2; 12208bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 12218bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul } 12228bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul return; 12233893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul default: 12243893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(NULL, "bad format in do_row()"); 12253893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 12263893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul} 12273893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12283893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12299228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul/* 12309228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * These functions generate a 1/2-size mipmap image from a source image. 12319228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * Texture borders are handled by copying or averaging the source image's 12329228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * border texels, depending on the scale-down factor. 12339228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul */ 12343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulstatic void 12363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulmake_1d_mipmap(const struct gl_texture_format *format, GLint border, 12373893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint srcWidth, const GLubyte *srcPtr, 12383893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint dstWidth, GLubyte *dstPtr) 12393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul{ 12403893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLint bpt = format->TexelBytes; 12413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLubyte *src; 12423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLubyte *dst; 12433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* skip the border pixel, if any */ 12453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul src = srcPtr + border * bpt; 12463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dst = dstPtr + border * bpt; 12473893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* we just duplicate the input row, kind of hack, saves code */ 12499228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidth - 2 * border, src, src, 12509228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidth - 2 * border, dst); 12513893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (border) { 12533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* copy left-most pixel from source */ 12543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr, srcPtr, bpt); 12553893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* copy right-most pixel from source */ 12563893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr + (dstWidth - 1) * bpt, 12573893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + (srcWidth - 1) * bpt, 12583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul bpt); 12593893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 12603893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul} 12613893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12633893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulstatic void 12643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulmake_2d_mipmap(const struct gl_texture_format *format, GLint border, 12653893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint srcWidth, GLint srcHeight, const GLubyte *srcPtr, 12663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint dstWidth, GLint dstHeight, GLubyte *dstPtr) 12673893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul{ 12683893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLint bpt = format->TexelBytes; 12699228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */ 12709228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint dstWidthNB = dstWidth - 2 * border; 12719228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint dstHeightNB = dstHeight - 2 * border; 12723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLint srcRowStride = bpt * srcWidth; 12733893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLint dstRowStride = bpt * dstWidth; 12743893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLubyte *srcA, *srcB; 12753893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLubyte *dst; 12769228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLint row, colStride; 12779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 12789228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul colStride = (srcWidth == dstWidth) ? 1 : 2; 12793893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12803893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* Compute src and dst pointers, skipping any border */ 12813893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcA = srcPtr + border * ((srcWidth + 1) * bpt); 12823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (srcHeight > 1) 12833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcB = srcA + srcRowStride; 12843893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul else 12853893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcB = srcA; 12863893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dst = dstPtr + border * ((dstWidth + 1) * bpt); 12873893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12889228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (row = 0; row < dstHeightNB; row++) { 12899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, srcA, srcB, 12909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidthNB, dst); 12913893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcA += 2 * srcRowStride; 12923893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcB += 2 * srcRowStride; 12933893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dst += dstRowStride; 12943893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 12953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 12968bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul /* This is ugly but probably won't be used much */ 12973893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (border > 0) { 12983893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* fill in dest border */ 12993893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* lower-left border pixel */ 13003893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr, srcPtr, bpt); 13013893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* lower-right border pixel */ 13023893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr + (dstWidth - 1) * bpt, 13033893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + (srcWidth - 1) * bpt, bpt); 13043893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* upper-left border pixel */ 13053893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr + dstWidth * (dstHeight - 1) * bpt, 13063893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt); 13073893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* upper-right border pixel */ 13083893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul MEMCPY(dstPtr + (dstWidth * dstHeight - 1) * bpt, 13093893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt); 13103893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* lower border */ 13119228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, 13129228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + bpt, 13139228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + bpt, 13149228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidthNB, dstPtr + bpt); 13153893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* upper border */ 13169228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, 13173893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt, 13183893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt, 13199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidthNB, 13203893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt); 13213893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* left and right borders */ 13229228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul if (srcHeight == dstHeight) { 13239228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* copy border pixel from src to dst */ 13249228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (row = 1; row < srcHeight; row++) { 13259228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dstPtr + dstWidth * row * bpt, 13269228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + srcWidth * row * bpt, bpt); 13279228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dstPtr + (dstWidth * row + dstWidth - 1) * bpt, 13289228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt); 13299228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 13309228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 13319228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul else { 13329228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* average two src pixels each dest pixel */ 13339228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (row = 0; row < dstHeightNB; row += 2) { 13349228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, 13359228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + (srcWidth * (row * 2 + 1)) * bpt, 13369228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + (srcWidth * (row * 2 + 2)) * bpt, 13379228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 1, dstPtr + (dstWidth * row + 1) * bpt); 13389228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, 13399228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt, 13409228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt, 13419228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt); 13429228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 13433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 13443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 13453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul} 13463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13473893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulstatic void 13493893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulmake_3d_mipmap(const struct gl_texture_format *format, GLint border, 13503893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint srcWidth, GLint srcHeight, GLint srcDepth, 13513893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLubyte *srcPtr, 13523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint dstWidth, GLint dstHeight, GLint dstDepth, 13533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLubyte *dstPtr) 13543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul{ 13559228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint bpt = format->TexelBytes; 13569228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */ 13579228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint srcDepthNB = srcDepth - 2 * border; 13589228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint dstWidthNB = dstWidth - 2 * border; 13599228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint dstHeightNB = dstHeight - 2 * border; 13609228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLint dstDepthNB = dstDepth - 2 * border; 13619228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLvoid *tmpRowA, *tmpRowB; 13623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint img, row; 13639228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLint bytesPerSrcImage, bytesPerDstImage; 13649228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLint bytesPerSrcRow, bytesPerDstRow; 13659228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLint srcImageOffset, srcRowOffset; 13663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13679228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Need two temporary row buffers */ 13689228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul tmpRowA = MALLOC(srcWidth * bpt); 13699228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul if (!tmpRowA) 13709228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul return; 13719228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul tmpRowB = MALLOC(srcWidth * bpt); 13729228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul if (!tmpRowB) { 13739228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul FREE(tmpRowA); 13743893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 13753893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 13763893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul bytesPerSrcImage = srcWidth * srcHeight * bpt; 13789228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul bytesPerDstImage = dstWidth * dstHeight * bpt; 13799228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 13809228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul bytesPerSrcRow = srcWidth * bpt; 13819228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul bytesPerDstRow = dstWidth * bpt; 13823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13839228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Offset between adjacent src images to be averaged together */ 13849228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage; 13853893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13869228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Offset between adjacent src rows to be averaged together */ 13879228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt; 13883893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* 13909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * Need to average together up to 8 src pixels for each dest pixel. 13919228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * Break that down into 3 operations: 13929228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * 1. take two rows from source image and average them together. 13939228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * 2. take two rows from next source image and average them together. 13949228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul * 3. take the two averaged rows and average them for the final dst row. 13959228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul */ 13963893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 13979228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* 13989228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul printf("mip3d %d x %d x %d -> %d x %d x %d\n", 13999228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth); 14009228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul */ 14019228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14029228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (img = 0; img < dstDepthNB; img++) { 14039228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* first source image pointer, skipping border */ 14049228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *imgSrcA = srcPtr 14059228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border 14069228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + img * (bytesPerSrcImage + srcImageOffset); 14079228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* second source image pointer, skipping border */ 14089228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *imgSrcB = imgSrcA + srcImageOffset; 14099228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* address of the dest image, skipping border */ 14109228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLubyte *imgDst = dstPtr 14119228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border 14129228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + img * bytesPerDstImage; 14139228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14149228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* setup the four source row pointers and the dest row pointer */ 14159228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *srcImgARowA = imgSrcA; 14169228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *srcImgARowB = imgSrcA + srcRowOffset; 14179228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *srcImgBRowA = imgSrcB; 14189228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *srcImgBRowB = imgSrcB + srcRowOffset; 14199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLubyte *dstImgRow = imgDst; 14209228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14219228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (row = 0; row < dstHeightNB; row++) { 14229228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Average together two rows from first src image */ 14239228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, srcImgARowA, srcImgARowB, 14249228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcWidthNB, tmpRowA); 14259228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Average together two rows from second src image */ 14269228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, srcImgBRowA, srcImgBRowB, 14279228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcWidthNB, tmpRowB); 14289228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Average together the temp rows to make the final row */ 14299228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, srcWidthNB, tmpRowA, tmpRowB, 14309228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidthNB, dstImgRow); 14319228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* advance to next rows */ 14329228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcImgARowA += bytesPerSrcRow + srcRowOffset; 14339228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcImgARowB += bytesPerSrcRow + srcRowOffset; 14349228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcImgBRowA += bytesPerSrcRow + srcRowOffset; 14359228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcImgBRowB += bytesPerSrcRow + srcRowOffset; 14369228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstImgRow += bytesPerDstRow; 14373893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 14383893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 14393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 14403893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul FREE(tmpRowA); 14413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul FREE(tmpRowB); 14429228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14439228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* Luckily we can leverage the make_2d_mipmap() function here! */ 14449228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul if (border > 0) { 14459228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do front border image */ 14469228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul make_2d_mipmap(format, 1, srcWidth, srcHeight, srcPtr, 14479228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidth, dstHeight, dstPtr); 14489228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do back border image */ 14499228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul make_2d_mipmap(format, 1, srcWidth, srcHeight, 14509228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul srcPtr + bytesPerSrcImage * (srcDepth - 1), 14519228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstWidth, dstHeight, 14529228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dstPtr + bytesPerDstImage * (dstDepth - 1)); 14539228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do four remaining border edges that span the image slices */ 14549228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul if (srcDepth == dstDepth) { 14559228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* just copy border pixels from src to dst */ 14569228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (img = 0; img < dstDepthNB; img++) { 14579228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *src; 14589228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLubyte *dst; 14599228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14609228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=0][col=0] */ 14619228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img + 1) * bytesPerSrcImage; 14629228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage; 14639228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dst, src, bpt); 14649228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14659228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=dstHeight-1][col=0] */ 14669228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 14679228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (srcHeight - 1) * bytesPerSrcRow; 14689228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 14699228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (dstHeight - 1) * bytesPerDstRow; 14709228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dst, src, bpt); 14719228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14729228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=0][col=dstWidth-1] */ 14739228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 14749228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (srcWidth - 1) * bpt; 14759228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 14769228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (dstWidth - 1) * bpt; 14779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dst, src, bpt); 14789228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14799228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=dstHeight-1][col=dstWidth-1] */ 14809228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 14819228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerSrcImage - bpt); 14829228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 14839228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerDstImage - bpt); 14849228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul MEMCPY(dst, src, bpt); 14859228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 14869228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 14879228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul else { 14889228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* average border pixels from adjacent src image pairs */ 14899228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul ASSERT(srcDepthNB == 2 * dstDepthNB); 14909228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul for (img = 0; img < dstDepthNB; img++) { 14919228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul const GLubyte *src; 14929228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul GLubyte *dst; 14939228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14949228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=0][col=0] */ 14959228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage; 14969228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage; 14979228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, src, src + srcImageOffset, 1, dst); 14989228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 14999228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=dstHeight-1][col=0] */ 15009228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 15019228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (srcHeight - 1) * bytesPerSrcRow; 15029228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 15039228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (dstHeight - 1) * bytesPerDstRow; 15049228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, src, src + srcImageOffset, 1, dst); 15059228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 15069228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=0][col=dstWidth-1] */ 15079228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 15089228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (srcWidth - 1) * bpt; 15099228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 15109228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (dstWidth - 1) * bpt; 15119228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, src, src + srcImageOffset, 1, dst); 15129228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul 15139228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* do border along [img][row=dstHeight-1][col=dstWidth-1] */ 15149228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul src = srcPtr + (img * 2 + 1) * bytesPerSrcImage 15159228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerSrcImage - bpt); 15169228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul dst = dstPtr + (img + 1) * bytesPerDstImage 15179228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul + (bytesPerDstImage - bpt); 15189228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul do_row(format, 1, src, src + srcImageOffset, 1, dst); 15199228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 15209228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 15219228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul } 15223893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul} 15233893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15243893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15253893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul/* 15263893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * For GL_SGIX_generate_mipmap: 15273893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * Generate a complete set of mipmaps from texObj's base-level image. 15283893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * Stop at texObj's MaxLevel or when we get to the 1x1 texture. 15293893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul */ 15303893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 15313893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_generate_mipmap(GLcontext *ctx, 15323893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const struct gl_texture_unit *texUnit, 15333893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_object *texObj) 15343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul{ 15353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLenum targets1D[] = { GL_TEXTURE_1D, 0 }; 15363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLenum targets2D[] = { GL_TEXTURE_2D, 0 }; 15373893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLenum targets3D[] = { GL_TEXTURE_3D, 0 }; 15383893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLenum targetsCube[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 15393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 15403893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 15413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 15423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 15433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 15443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 0 }; 15453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const GLenum *targets; 15463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLuint level; 1547cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 15483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15493893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul ASSERT(texObj); 15503893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul ASSERT(texObj->Image[texObj->BaseLevel]); 15513893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul switch (texObj->Dimensions) { 15533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 1: 15543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul targets = targets1D; 1555cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 15563893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 15573893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 2: 15583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul targets = targets2D; 1559cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 15603893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 15613893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 3: 15623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul targets = targets3D; 1563cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 15643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 15653893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 6: 15663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul targets = targetsCube; 1567cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 15683893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 15693893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul default: 15703893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(ctx, 15713893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul "Bad texture object dimension in _mesa_generate_mipmaps"); 15723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 15733893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 15743893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15758bd06931018d5662b92f1cfeee2abaf352d0044cBrian Paul for (level = texObj->BaseLevel; level < texObj->MaxLevel 1576cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul && level < maxLevels - 1; level++) { 15779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul /* generate image[level+1] from image[level] */ 15783893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul const struct gl_texture_image *srcImage; 15793893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *dstImage; 15803893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint srcWidth, srcHeight, srcDepth; 15813893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint dstWidth, dstHeight, dstDepth; 15823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint border, bytesPerTexel; 15833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint t; 15843893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15853893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcImage = texObj->Image[level]; 15863893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul ASSERT(srcImage); 15873893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcWidth = srcImage->Width; 15883893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcHeight = srcImage->Height; 15893893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcDepth = srcImage->Depth; 15903893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border = srcImage->Border; 15913893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul bytesPerTexel = srcImage->TexFormat->TexelBytes; 15923893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 15933893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* compute next (level+1) image size */ 15943893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (srcWidth - 2 * border > 1) { 15953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstWidth = (srcWidth - 2 * border) / 2 + 2 * border; 15963893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 15973893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul else { 15983893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstWidth = srcWidth; /* can't go smaller */ 15993893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16003893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (srcHeight - 2 * border > 1) { 16013893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstHeight = (srcHeight - 2 * border) / 2 + 2 * border; 16023893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16033893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul else { 16043893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstHeight = srcHeight; /* can't go smaller */ 16053893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16063893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (srcDepth - 2 * border > 1) { 16073893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstDepth = (srcDepth - 2 * border) / 2 + 2 * border; 16083893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16093893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul else { 16103893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstDepth = srcDepth; /* can't go smaller */ 16113893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16123893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16133893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (dstWidth == srcWidth && 16143893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstHeight == srcHeight && 16153893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstDepth == srcDepth) { 16163893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* all done */ 16173893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 16183893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16193893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16203893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* Need this loop just because of cubemaps */ 16213893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul for (t = 0; targets[t]; t++) { 16223893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul ASSERT(t < 6); 16233893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16243893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage = _mesa_select_tex_image(ctx, texUnit, targets[t], level+1); 16253893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (!dstImage) { 16263893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage = _mesa_alloc_texture_image(); 16273893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (!dstImage) { 16283893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); 16293893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 16303893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16313893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_set_tex_image(texObj, targets[t], level + 1, dstImage); 16323893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16333893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* Free old image data */ 16353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (dstImage->Data) 16363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul FREE(dstImage->Data); 16373893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16383893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* initialize new image */ 16393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_init_teximage_fields(ctx, dstImage, dstWidth, dstHeight, 16403893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstDepth, border, srcImage->Format); 16413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage->DriverData = NULL; 16423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage->TexFormat = srcImage->TexFormat; 16433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage->FetchTexel = srcImage->FetchTexel; 16449228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul ASSERT(dstImage->TexFormat); 16459228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul ASSERT(dstImage->FetchTexel); 16463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16473893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul ASSERT(dstWidth * dstHeight * dstDepth * bytesPerTexel > 0); 16483893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16493893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* alloc new image buffer */ 16503893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstImage->Data = MALLOC(dstWidth * dstHeight * dstDepth 16513893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * bytesPerTexel); 16523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul if (!dstImage->Data) { 16533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); 16543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 16553893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16563893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul 16573893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul /* 16583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul * We use simple 2x2 averaging to compute the next mipmap level. 16593893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul */ 16603893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul switch (texObj->Dimensions) { 16613893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 1: 16623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul make_1d_mipmap(srcImage->TexFormat, border, 16633893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcWidth, (const GLubyte *) srcImage->Data, 16643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstWidth, (GLubyte *) dstImage->Data); 16653893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 16663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 2: 16673893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 6: 16683893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul make_2d_mipmap(srcImage->TexFormat, border, 16693893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcWidth, srcHeight, (const GLubyte *) srcImage->Data, 16703893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstWidth, dstHeight, (GLubyte *) dstImage->Data); 16713893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 16723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul case 3: 16733893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul make_3d_mipmap(srcImage->TexFormat, border, 16743893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul srcWidth, srcHeight, srcDepth, (const GLubyte *) srcImage->Data, 16753893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul dstWidth, dstHeight, dstDepth, (GLubyte *) dstImage->Data); 16763893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul break; 16773893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul default: 16783893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(ctx, "bad dimensions in _mesa_generate_mipmaps"); 16793893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul return; 16803893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } 16813893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } /* loop over tex image targets */ 16823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul } /* loop over tex levels */ 16833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul} 1684