texstore.c revision 2c3d34c905fa6b831a066afae83b938de05eb241
12c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes/* $Id: texstore.c,v 1.12 2001/03/18 08:53:50 gareth Exp $ */ 28e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 38e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 48e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Mesa 3-D graphics library 58e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Version: 3.5 68e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 78e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 88e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 98e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a 108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * copy of this software and associated documentation files (the "Software"), 118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * to deal in the Software without restriction, including without limitation 128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense, 138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * and/or sell copies of the Software, and to permit persons to whom the 148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Software is furnished to do so, subject to the following conditions: 158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The above copyright notice and this permission notice shall be included 178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * in all copies or substantial portions of the Software. 188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Authors: 298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Brian Paul 308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The functions in this file are mostly related to software texture fallbacks. 358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This includes texture image transfer/packing and texel fetching. 368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Hardware drivers will likely override most of this. 378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 41e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul#include "colormac.h" 428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "context.h" 438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "convolve.h" 448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "image.h" 458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "macros.h" 468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "mem.h" 478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "teximage.h" 488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "texstore.h" 492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul#include "swrast/s_depth.h" /* XXX this is kind of a cheat */ 502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul#include "swrast/s_span.h" 518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 532c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes#if 0 548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Default 1-D texture texel fetch function. This will typically be 568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * overridden by hardware drivers which store their texture images in 578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * special ways. 588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic void 60e75d2424e53d6023f4414e40694cd467e5392b96Brian Paulfetch_1d_texel(const struct gl_texture_image *img, 61e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLint i, GLint j, GLint k, GLvoid *texel) 628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (img->Format) { 64e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGBA: 65e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 66e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i * 4; 67e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 68e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul COPY_CHAN4(rgba, src); 698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 70e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 71e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGB: 72e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 73e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i * 3; 74e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 75e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 76e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[GCOMP] = src[1]; 77e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[BCOMP] = src[2]; 782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 80e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 81e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_ALPHA: 82e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 83e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i; 84e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = 0; 862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = 0; 872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = 0; 88e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[0]; 898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 90e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 91e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE: 922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul { 932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul const GLchan *src = (GLchan *) img->Data + i; 942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *rgba = (GLchan *) texel; 952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = src[0]; 962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 1002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 101e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_INTENSITY: 102e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 103e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i; 104e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 105e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 1062aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 1072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 1082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = src[0]; 1098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 110e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 111e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE_ALPHA: 112e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 113e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i * 2; 114e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 115e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 1162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 1172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 118e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[1]; 1198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 120e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 121e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_COLOR_INDEX: 122e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 123e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + i; 124e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *index = (GLchan *) texel; 125e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *index = *src; 126e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul return; 127e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 128e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_DEPTH_COMPONENT: 129e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 130e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLfloat *src = (GLfloat *) img->Data + i; 131e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLfloat *depth = (GLfloat *) texel; 132e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *depth = *src; 1338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 134e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 135e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul default: 13608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "Bad format in fetch_1d_texel"); 1378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 1398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 1428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Default 2-D texture texel fetch function. 1438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 1448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic void 145e75d2424e53d6023f4414e40694cd467e5392b96Brian Paulfetch_2d_texel(const struct gl_texture_image *img, 146e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLint i, GLint j, GLint k, GLvoid *texel) 1478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 1488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (img->Format) { 149e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGBA: 150e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 151e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i) * 4; 152e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 153e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul COPY_CHAN4(rgba, src); 1548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 155e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 156e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGB: 157e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 158e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i) * 3; 159e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 160e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 161e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[GCOMP] = src[1]; 162e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[BCOMP] = src[2]; 1632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 1648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 165e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 166e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_ALPHA: 167e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 168e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i); 169e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 1702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = 0; 1712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = 0; 1722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = 0; 173e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[0]; 1748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 175e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 176e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE: 1772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul { 1782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i); 1792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *rgba = (GLchan *) texel; 1802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = src[0]; 1812aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 1822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 1832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 1842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 1852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 186e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_INTENSITY: 187e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 188e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i); 189e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 190e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 1912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 1922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 1932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = src[0]; 1948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 195e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 196e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE_ALPHA: 197e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 198e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i) * 2; 199e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 200abe094e4a158fcefc40eee9605d5214846881534Brian Paul rgba[RCOMP] = src[0]; 201abe094e4a158fcefc40eee9605d5214846881534Brian Paul rgba[GCOMP] = src[0]; 202abe094e4a158fcefc40eee9605d5214846881534Brian Paul rgba[BCOMP] = src[0]; 203e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[1]; 2048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 205e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 206e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_COLOR_INDEX: 207e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 208e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data + (img->Width * j + i); 209e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *index = (GLchan *) texel; 210e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *index = *src; 211e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul return; 212e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 213e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_DEPTH_COMPONENT: 214e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 215e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLfloat *src = (GLfloat *) img->Data + (img->Width * j + i); 216e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLfloat *depth = (GLfloat *) texel; 217e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *depth = *src; 218e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul return; 219e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 220e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul default: 22108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "Bad format in fetch_2d_texel"); 2228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 2238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 2248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 2278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Default 2-D texture texel fetch function. 2288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 2298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic void 230e75d2424e53d6023f4414e40694cd467e5392b96Brian Paulfetch_3d_texel(const struct gl_texture_image *img, 231e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLint i, GLint j, GLint k, GLvoid *texel) 2328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 233e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLint width = img->Width; 234e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLint rectArea = width * img->Height; 2358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (img->Format) { 237e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGBA: 238e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 239e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 240e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i) * 4; 241e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 242e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul COPY_CHAN4(rgba, src); 2438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 244e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 245e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_RGB: 246e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 247e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 248e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i) * 3; 249e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 250e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 251e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[GCOMP] = src[1]; 252e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[BCOMP] = src[2]; 2532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 2548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 255e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 256e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_ALPHA: 257e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 258e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 259e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i); 260e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 2612aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = 0; 2622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = 0; 2632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = 0; 264e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[0]; 2658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 266e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 267e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE: 2682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul { 2692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul const GLchan *src = (GLchan *) img->Data 2702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul + (rectArea * k + width * j + i); 2712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *rgba = (GLchan *) texel; 2722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[RCOMP] = src[0]; 2732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 2742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 2752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = CHAN_MAX; 2762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 2772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 278e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_INTENSITY: 279e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 280e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 281e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i); 282e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 283e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 2842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 2852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 2862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[ACOMP] = src[0]; 2878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 288e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 289e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_LUMINANCE_ALPHA: 290e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 291e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 292e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i) * 2; 293e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *rgba = (GLchan *) texel; 294e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[RCOMP] = src[0]; 2952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[GCOMP] = src[0]; 2962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul rgba[BCOMP] = src[0]; 297e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul rgba[ACOMP] = src[1]; 2988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 299e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 300e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_COLOR_INDEX: 301e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 302e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLchan *src = (GLchan *) img->Data 303e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i); 304e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLchan *index = (GLchan *) texel; 305e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *index = *src; 306e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul return; 307e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 308e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul case GL_DEPTH_COMPONENT: 309e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul { 310e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul const GLfloat *src = (GLfloat *) img->Data 311e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul + (rectArea * k + width * j + i); 312e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul GLfloat *depth = (GLfloat *) texel; 313e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul *depth = *src; 314e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul return; 315e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul } 316e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul default: 31708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "Bad format in fetch_3d_texel"); 3188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 3198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 3208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 3238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 3248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Examine the texImage->Format field and set the Red, Green, Blue, etc 3258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * texel component sizes to default values. 3268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * These fields are set only here by core Mesa but device drivers may 3278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * overwritting these fields to indicate true texel resolution. 3288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 3298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic void 3308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulset_teximage_component_sizes( struct gl_texture_image *texImage ) 3318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 3328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (texImage->Format) { 3338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA: 3348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 8 * sizeof(GLchan); 3388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 3408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 341f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE: 3448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 3488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 8 * sizeof(GLchan); 3508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 351f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE_ALPHA: 3548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 8 * sizeof(GLchan); 3588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 8 * sizeof(GLchan); 3608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 361f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY: 3648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 3688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 8 * sizeof(GLchan); 3698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 3708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 371f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RED: 3748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 8 * sizeof(GLchan); 3758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 3788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 3808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 381f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_GREEN: 3848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 8 * sizeof(GLchan); 3868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 3878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 3888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 3908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 391f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 3928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 3938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_BLUE: 3948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 3958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 3968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 8 * sizeof(GLchan); 3978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 3988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 3998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 4008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 401f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 4028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 4038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB: 4048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_BGR: 4058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 8 * sizeof(GLchan); 4068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 8 * sizeof(GLchan); 4078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 8 * sizeof(GLchan); 4088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 4098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 4108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 4118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 412f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 4138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 4148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA: 4158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_BGRA: 4168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ABGR_EXT: 4178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 8 * sizeof(GLchan); 4188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 8 * sizeof(GLchan); 4198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 8 * sizeof(GLchan); 4208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 8 * sizeof(GLchan); 4218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 4228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 4238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 0; 424f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 4258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 4268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX: 4278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->RedBits = 0; 4288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->GreenBits = 0; 4298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->BlueBits = 0; 4308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->AlphaBits = 0; 4318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IntensityBits = 0; 4328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->LuminanceBits = 0; 4338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->IndexBits = 8 * sizeof(GLchan); 434f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 0; 435f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul break; 436f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT: 437f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->RedBits = 0; 438f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->GreenBits = 0; 439f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->BlueBits = 0; 440f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->AlphaBits = 0; 441f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->IntensityBits = 0; 442f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->LuminanceBits = 0; 443f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->IndexBits = 0; 444f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits = 8 * sizeof(GLfloat); 4458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul break; 4468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul default: 44708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "unexpected format in set_teximage_component_sizes"); 4488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 4498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 4502c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes#endif 4518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 4528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 4538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 4548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 4558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Given an internal texture format enum or 1, 2, 3, 4 return the 4568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, 4578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the 4588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * number of components for the format. Return -1 if invalid enum. 4598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 4608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLint 4618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulcomponents_in_intformat( GLint format ) 4628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 4638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul switch (format) { 4648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA: 4658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA4: 4668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA8: 4678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA12: 4688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_ALPHA16: 4698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 4708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 1: 4718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE: 4728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE4: 4738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE8: 4748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12: 4758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE16: 4768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 4778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 2: 4788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE_ALPHA: 4798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE4_ALPHA4: 4808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE6_ALPHA2: 4818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE8_ALPHA8: 4828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12_ALPHA4: 4838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE12_ALPHA12: 4848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_LUMINANCE16_ALPHA16: 4858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 2; 4868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY: 4878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY4: 4888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY8: 4898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY12: 4908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_INTENSITY16: 4918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 4928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 3: 4938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB: 4948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_R3_G3_B2: 4958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB4: 4968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB5: 4978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB8: 4988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB10: 4998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB12: 5008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB16: 5018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 3; 5028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case 4: 5038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA: 5048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA2: 5058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA4: 5068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB5_A1: 5078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA8: 5088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGB10_A2: 5098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA12: 5108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_RGBA16: 5118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 4; 5128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX: 5138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX1_EXT: 5148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX2_EXT: 5158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX4_EXT: 5168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX8_EXT: 5178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX12_EXT: 5188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul case GL_COLOR_INDEX16_EXT: 5198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return 1; 520f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT: 521f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT16_SGIX: 522f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT24_SGIX: 523f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT32_SGIX: 524f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return 1; 5258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul default: 5268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return -1; /* error */ 5278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 5288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 5298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 5328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This function is used to transfer the user's image data into a texture 5338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * image buffer. We handle both full texture images and subtexture images. 5348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * We also take care of all image transfer operations here, including 5358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convolution, scale/bias, colortables, etc. 5368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 5378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The destination texel channel type is always GLchan. 5388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 5398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * A hardware driver may use this as a helper routine to unpack and 5408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * apply pixel transfer ops into a temporary image buffer. Then, 5418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * convert the temporary image into the special hardware format. 5428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 5438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Input: 5448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * dimensions - 1, 2, or 3 5458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA, 5468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_RGB or GL_RGBA 5478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * texAddr - destination image address 5488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images 5498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * dstXoffset, dstYoffset, dstZoffset - position to store the image within 5508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * the destination 3D texture 5518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * dstRowStride, dstImageStride - dest image strides in GLchan's 5528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc) 5538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc 5548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * srcPacking - describes packing of incoming image. 5558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 5568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 5578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions, 5588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum texFormat, GLchan *texAddr, 5598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcWidth, GLint srcHeight, GLint srcDepth, 5608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, 5618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint dstRowStride, GLint dstImageStride, 5628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum srcFormat, GLenum srcType, 5638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *srcAddr, 5648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *srcPacking) 5658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 5668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint texComponents; 5678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx); 5698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dimensions >= 1 && dimensions <= 3); 5708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texAddr); 5718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcWidth >= 1); 5728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcHeight >= 1); 5738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcDepth >= 1); 5748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstXoffset >= 0); 5758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstYoffset >= 0); 5768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstZoffset >= 0); 5778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstRowStride >= 0); 5788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(dstImageStride >= 0); 5798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcAddr); 5808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(srcPacking); 5818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texComponents = components_in_intformat(texFormat); 5838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* try common 2D texture cases first */ 585f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->_ImageTransferState && dimensions == 2 && srcType == CHAN_TYPE) { 5868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (srcFormat == texFormat) { 5888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA, 5898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy(). 5908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 5918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *src = (const GLchan *) _mesa_image_address( 5928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcPacking, srcAddr, srcWidth, srcHeight, 5938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, 0, 0, 0); 5948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint srcRowStride = _mesa_image_row_stride(srcPacking, 5958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcWidth, srcFormat, srcType); 5968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint widthInBytes = srcWidth * texComponents * sizeof(GLchan); 5978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dst = texAddr + dstYoffset * dstRowStride 5988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 5998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) { 6008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul MEMCPY(dst, src, srcHeight * widthInBytes); 6018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 6038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint i; 6048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < srcHeight; i++) { 6058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul MEMCPY(dst, src, widthInBytes); 6068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul src += srcRowStride; 6078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dst += dstRowStride; 6088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* all done */ 6118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else if (srcFormat == GL_RGBA && texFormat == GL_RGB) { 6138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* commonly used by Quake */ 6148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *src = (const GLchan *) _mesa_image_address( 6158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcPacking, srcAddr, srcWidth, srcHeight, 6168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, 0, 0, 0); 6178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint srcRowStride = _mesa_image_row_stride(srcPacking, 6188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcWidth, srcFormat, srcType); 6198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dst = texAddr + dstYoffset * dstRowStride 6208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 6218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint i, j; 6228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < srcHeight; i++) { 6238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLchan *s = src; 6248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *d = dst; 6258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < srcWidth; j++) { 6268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*red*/ 6278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*green*/ 6288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *d++ = *s++; /*blue*/ 6298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul s++; /*alpha*/ 6308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul src += srcRowStride; 6328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dst += dstRowStride; 6338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* all done */ 6358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 6388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 6398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * General case solutions 6408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 6418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (texFormat == GL_COLOR_INDEX) { 6428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* color index texture */ 6431ceda0f84fdfe07951071fdf4fa643d07f09a4d7Brian Paul const GLenum texType = CHAN_TYPE; 6448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 6458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dest = texAddr + dstZoffset * dstImageStride 6468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride 6478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 6488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 6498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *destRow = dest; 6508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 6518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *src = _mesa_image_address(srcPacking, 6528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); 6538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_index_span(ctx, srcWidth, texType, destRow, 6548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcType, src, srcPacking, 6558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState); 6568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul destRow += dstRowStride; 6578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstImageStride; 6598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 661f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else if (texFormat == GL_DEPTH_COMPONENT) { 662f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* Depth texture (shadow maps) */ 663f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint img, row; 664f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLfloat *dest = (GLfloat *) texAddr + dstZoffset * dstImageStride 665f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul + dstYoffset * dstRowStride 666f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul + dstXoffset * texComponents; 667f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (img = 0; img < srcDepth; img++) { 668f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLfloat *destRow = dest; 669f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (row = 0; row < srcHeight; row++) { 670f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul const GLvoid *src = _mesa_image_address(srcPacking, 671f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); 672e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul _mesa_unpack_depth_span(ctx, srcWidth, destRow, 673e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul srcType, src, srcPacking); 674f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul destRow += dstRowStride; 675f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 676f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul dest += dstImageStride; 677f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 678f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 6798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 6808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* regular, color texture */ 6818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) || 6828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) || 6838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) { 6848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 6858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fill texture image with convolution 6868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 6878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 6888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint convWidth = srcWidth, convHeight = srcHeight; 6898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *tmpImage, *convImage; 6908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); 6918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!tmpImage) { 69208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); 6938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 6948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 6958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); 6968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!convImage) { 69708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); 6988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 6998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 7008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 7038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLfloat *srcf; 7048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *dstf = tmpImage; 7058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dest; 7068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack and do transfer ops up to convolution */ 7088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 7098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *src = _mesa_image_address(srcPacking, 7108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, 7118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, img, row, 0); 7128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf, 7138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, src, srcPacking, 7148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, 7158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_TRUE); 7168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dstf += srcWidth * 4; 7178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convolve */ 7208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dimensions == 1) { 7218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Pixel.Convolution1DEnabled); 7228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); 7238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 7258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution2DEnabled) { 7268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, 7278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 7288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 7308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Pixel.Separable2DEnabled); 7318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, 7328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 7338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* packing and transfer ops after convolution */ 7378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcf = convImage; 7388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest = texAddr + (dstZoffset + img) * dstImageStride 7398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride; 7408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < convHeight; row++) { 7418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_pack_float_rgba_span(ctx, convWidth, 7428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (const GLfloat (*)[4]) srcf, 7431ceda0f84fdfe07951071fdf4fa643d07f09a4d7Brian Paul texFormat, CHAN_TYPE, 7448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest, &_mesa_native_packing, 7458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState 7468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul & IMAGE_POST_CONVOLUTION_BITS); 7478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcf += convWidth * 4; 7488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstRowStride; 7498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(convImage); 7538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 7548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 7568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* 7578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * no convolution 7588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 7598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 7608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *dest = texAddr + dstZoffset * dstImageStride 7618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstYoffset * dstRowStride 7628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul + dstXoffset * texComponents; 7638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < srcDepth; img++) { 7648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan *destRow = dest; 7658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < srcHeight; row++) { 7668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLvoid *srcRow = _mesa_image_address(srcPacking, 7678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcAddr, srcWidth, srcHeight, 7688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, img, row, 0); 7698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_chan_color_span(ctx, srcWidth, texFormat, destRow, 7708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul srcFormat, srcType, srcRow, srcPacking, 7718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState); 7728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul destRow += dstRowStride; 7738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul dest += dstImageStride; 7758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 7788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 7798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 7828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 7838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage1D(). 7848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 7858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 7868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 7878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 7888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 7898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 7908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, 7918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 7928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint border, 7938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const GLvoid *pixels, 7948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 7958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 7968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 7978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 7988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint postConvWidth = width; 7998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 8018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 8028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 8038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* setup the teximage struct's fields */ 8052c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes _mesa_init_tex_format( ctx, internalFormat, texImage ); 8062c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->FetchTexel = texImage->TexFormat->FetchTexel1D; 8078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 8092c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Data = (GLchan *) MALLOC(postConvWidth * 8102c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->TexFormat->TexelBytes); 8118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) 8128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* out of memory */ 8138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 815b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 1, texImage->Format, (GLchan *) texImage->Data, 8168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, 1, 1, 0, 0, 0, 8178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstRowStride */ 8188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 8198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 8208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 8248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage2D(). 8258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 8268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 8278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 8288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 8298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, 8328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 8338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint border, 8348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 8358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 8368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 8398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint postConvWidth = width, postConvHeight = height; 8402c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GLint texelBytes; 8418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 8438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 8448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &postConvHeight); 8458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 8468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* setup the teximage struct's fields */ 8482c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes _mesa_init_tex_format( ctx, internalFormat, texImage ); 8492c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->FetchTexel = texImage->TexFormat->FetchTexel2D; 8502c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes 8512c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texelBytes = texImage->TexFormat->TexelBytes; 8528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 8542c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Data = (GLchan *) MALLOC(postConvWidth * postConvHeight * 8552c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texelBytes); 8568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) 8578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* out of memory */ 8588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 860b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 2, texImage->Format, (GLchan *) texImage->Data, 8618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, 1, 0, 0, 0, 8622c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texelBytes, 8638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 8648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 8658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 8668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 8708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexImage3D(). 8718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image type will be GLchan. 8728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY, 8738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA. 8748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * 8758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 8768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 8778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level, 8788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 8798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, GLint border, 8808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 8818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 8828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 8838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 8848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 8852c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GLint texelBytes; 8868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* setup the teximage struct's fields */ 8882c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes _mesa_init_tex_format( ctx, internalFormat, texImage ); 8892c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->FetchTexel = texImage->TexFormat->FetchTexel3D; 8902c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes 8912c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texelBytes = texImage->TexFormat->TexelBytes; 8928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* allocate memory */ 8942c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Data = (GLchan *) MALLOC(width * height * depth * texelBytes); 8958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) 8968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* out of memory */ 8978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 8988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* unpack image, apply transfer ops and store in texImage->Data */ 899b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 3, texImage->Format, (GLchan *) texImage->Data, 9008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 0, 0, 0, 9012c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texelBytes, 9022c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes texImage->Width * texImage->Height * texelBytes, 9038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 9048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 9108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage1D(). 9118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 9138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 9148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint width, 9158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 9168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 9178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 9188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 9198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 920b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 1, texImage->Format, (GLchan *) texImage->Data, 9218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, 1, 1, /* src size */ 9228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, 0, 0, /* dest offsets */ 9238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstRowStride */ 9248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 9258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 9268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 9308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage2D(). 9318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 9338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level, 9348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint yoffset, 9358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, 9368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 9378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 9388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 9398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 9408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 9418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = components_in_intformat(texImage->IntFormat); 942f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul const GLint compSize = _mesa_sizeof_type(texImage->Type); 943b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 2, texImage->Format, (GLchan *) texImage->Data, 9448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, 1, /* src size */ 9458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, 0, /* dest offsets */ 946f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->Width * components * compSize, 9478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 0, /* dstImageStride */ 9488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 9498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 9538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the software fallback for Driver.TexSubImage3D(). 9548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 9558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 9568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level, 9578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 9588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, 9598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum format, GLenum type, const void *pixels, 9608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_pixelstore_attrib *packing, 9618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 9628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 9638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 9648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = components_in_intformat(texImage->IntFormat); 965f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul const GLint compSize = _mesa_sizeof_type(texImage->Type); 966b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_transfer_teximage(ctx, 3, texImage->Format, (GLchan *) texImage->Data, 9678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, /* src size */ 9688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, xoffset, /* dest offsets */ 969f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->Width * components * compSize, 9708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage->Width * texImage->Height * components 971f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul * compSize, 9728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, packing); 9738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 9748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 9782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 9792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Read an RGBA image from the frame buffer. 9802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * This is used by glCopyTex[Sub]Image[12]D(). 9812aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Input: ctx - the context 9822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * x, y - lower left corner 9832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * width, height - size of region to read 9842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Return: pointer to block of GL_RGBA, GLchan data. 9852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 9862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulstatic GLchan * 9872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulread_color_image( GLcontext *ctx, GLint x, GLint y, 9882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLsizei width, GLsizei height ) 9892aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 9902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint stride, i; 9912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image, *dst; 9922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 9932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan)); 9942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) 9952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return NULL; 9962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 9972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* Select buffer to read from */ 9982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 9992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->Pixel.DriverReadBuffer ); 10002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul RENDER_START(ctx); 10022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul dst = image; 10042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul stride = width * 4; 10052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul for (i = 0; i < height; i++) { 100608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i, 10072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (GLchan (*)[4]) dst ); 10082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul dst += stride; 10092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 10102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul RENDER_FINISH(ctx); 10122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* Read from draw buffer (the default) */ 10142aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 10152aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->Color.DriverDrawBuffer ); 10162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return image; 10182aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 10192aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10202aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 10222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * As above, but read data from depth buffer. 10232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 10242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulstatic GLfloat * 10252aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulread_depth_image( GLcontext *ctx, GLint x, GLint y, 10262aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLsizei width, GLsizei height ) 10272aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 10282aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint i; 10292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image, *dst; 10302aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10312aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul image = (GLfloat *) MALLOC(width * height * sizeof(GLfloat)); 10322aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) 10332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return NULL; 10342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10352aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul RENDER_START(ctx); 10362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10372aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul dst = image; 10382aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul for (i = 0; i < height; i++) { 10392aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul _mesa_read_depth_span_float(ctx, width, x, y + i, dst); 10402aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul dst += width; 10412aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 10422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10432aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul RENDER_FINISH(ctx); 10442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return image; 10462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 10472aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10482aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulstatic GLboolean 10512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulis_depth_format(GLenum format) 10522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 10532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul switch (format) { 10542aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul case GL_DEPTH_COMPONENT: 10552aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul case GL_DEPTH_COMPONENT16_SGIX: 10562aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul case GL_DEPTH_COMPONENT24_SGIX: 10572aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul case GL_DEPTH_COMPONENT32_SGIX: 10582aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return GL_TRUE; 10592aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul default: 10602aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return GL_FALSE; 10612aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 10622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 10632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 10662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Fallback for Driver.CopyTexImage1D(). 10672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 10682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulvoid 10692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul_mesa_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level, 10702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLenum internalFormat, 10712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint x, GLint y, GLsizei width, GLint border ) 10722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 10732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 10742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 10752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 10762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 10782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 10792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texObj); 10802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 10812aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texImage); 10822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.TexImage1D); 10842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (is_depth_format(internalFormat)) { 10862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read depth image from framebuffer */ 10872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image = read_depth_image(ctx, x, y, width, 1); 10882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 108908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 10902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 10912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 10922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 10932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage1D to redefine the texture */ 10942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 10952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul width, border, 10962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_DEPTH_COMPONENT, GL_FLOAT, image, 10972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 10982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 10992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else { 11012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read RGBA image from framebuffer */ 11022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image = read_color_image(ctx, x, y, width, 1); 11032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 110408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 11052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 11062aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage1D to redefine the texture */ 11092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 11102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul width, border, 11112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_RGBA, CHAN_TYPE, image, 11122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 11132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 11142aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11152aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 11162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11182aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 11192aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Fallback for Driver.CopyTexImage2D(). 11202aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 11212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulvoid 11222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul_mesa_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level, 11232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLenum internalFormat, 11242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 11252aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint border ) 11262aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 11272aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 11282aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 11292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 11302aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11312aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 11322aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 11332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texObj); 11342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 11352aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texImage); 11362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11372aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.TexImage2D); 11382aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11392aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (is_depth_format(internalFormat)) { 11402aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read depth image from framebuffer */ 11412aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image = read_depth_image(ctx, x, y, width, height); 11422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 114308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 11442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 11452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11472aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage2D to redefine the texture */ 11482aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 11492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul width, height, border, 11502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_DEPTH_COMPONENT, GL_FLOAT, image, 11512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 11522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 11532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11542aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else { 11552aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read RGBA image from framebuffer */ 11562aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image = read_color_image(ctx, x, y, width, height); 11572aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 115808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 11592aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 11602aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11612aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage2D to redefine the texture */ 11632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 11642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul width, height, border, 11652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_RGBA, CHAN_TYPE, image, 11662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 11672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 11682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 11702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 11732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Fallback for Driver.CopyTexSubImage1D(). 11742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 11752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulvoid 11762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul_mesa_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 11772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width) 11782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 11792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 11802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 11812aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 11822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 11842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 11852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texObj); 11862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 11872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texImage); 11882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11892aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.TexImage1D); 11902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (is_depth_format(texImage->IntFormat)) { 11922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read depth image from framebuffer */ 11932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image = read_depth_image(ctx, x, y, width, 1); 11942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 119508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D"); 11962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 11972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 11982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 11992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage1D to redefine the texture */ 12002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 12012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_DEPTH_COMPONENT, GL_FLOAT, image, 12022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 12032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 12042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else { 12062aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image = read_color_image(ctx, x, y, width, 1); 12072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 120808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D" ); 12092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 12102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* now call glTexSubImage1D to do the real work */ 12132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 12142aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_RGBA, CHAN_TYPE, image, 12152aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 12162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 12172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12182aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 12192aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12202aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 12222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Fallback for Driver.CopyTexSubImage2D(). 12232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 12242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulvoid 12252aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul_mesa_copy_texsubimage2d( GLcontext *ctx, 12262aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLenum target, GLint level, 12272aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint xoffset, GLint yoffset, 12282aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 12292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 12302aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 12312aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 12322aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 12332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 12352aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 12362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texObj); 12372aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 12382aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texImage); 12392aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12402aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.TexImage2D); 12412aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (is_depth_format(texImage->IntFormat)) { 12432aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read depth image from framebuffer */ 12442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image = read_depth_image(ctx, x, y, width, height); 12452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 124608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D"); 12472aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 12482aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage1D to redefine the texture */ 12512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, 12522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, width, height, 12532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_DEPTH_COMPONENT, GL_FLOAT, image, 12542aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 12552aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 12562aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12572aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else { 12582aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read RGBA image from framebuffer */ 12592aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image = read_color_image(ctx, x, y, width, height); 12602aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 126108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); 12622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 12632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* now call glTexSubImage2D to do the real work */ 12662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, 12672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, width, height, 12682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_RGBA, CHAN_TYPE, image, 12692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 12702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 12712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 12722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 12732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul/* 12762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul * Fallback for Driver.CopyTexSubImage3D(). 12772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul */ 12782aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paulvoid 12792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul_mesa_copy_texsubimage3d( GLcontext *ctx, 12802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLenum target, GLint level, 12812aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 12822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 12832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul{ 12842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 12852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 12862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 12872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 12892aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 12902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texObj); 12912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 12922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(texImage); 12932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.TexImage3D); 12952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 12962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (is_depth_format(texImage->IntFormat)) { 12972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read depth image from framebuffer */ 12982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLfloat *image = read_depth_image(ctx, x, y, width, height); 12992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 130008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage3D"); 13012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 13022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 13032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 13042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* call glTexImage1D to redefine the texture */ 13052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 13062aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, zoffset, width, height, 1, 13072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_DEPTH_COMPONENT, GL_FLOAT, image, 13082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 13092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 13102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 13112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else { 13122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* read RGBA image from framebuffer */ 13132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GLchan *image = read_color_image(ctx, x, y, width, height); 13142aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!image) { 131508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage3D" ); 13162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul return; 13172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 13182aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 13192aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* now call glTexSubImage3D to do the real work */ 13202aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 13212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, zoffset, width, height, 1, 13222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul GL_RGBA, CHAN_TYPE, image, 13232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul &_mesa_native_packing, texObj, texImage); 13242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(image); 13252aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 13262aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul} 13272aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 13282aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 13292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 13308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 13318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage1D() 13328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 13348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage1d(GLcontext *ctx, GLenum target, GLint level, 13358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 13368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint border, 13378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 13388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 13398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 13408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 13418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 13428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 13438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 13458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 13498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage2D() 13508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 13528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level, 13538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 13548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint border, 13558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 13568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 13578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 13588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 13598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 13608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 13618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 13638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 13678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Fallback for Driver.CompressedTexImage3D() 13688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 13708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_store_compressed_teximage3d(GLcontext *ctx, GLenum target, GLint level, 13718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, 13728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, 13738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint border, 13748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLsizei imageSize, const GLvoid *data, 13758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj, 13768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage) 13778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 13788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* Nothing here. 13798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The device driver has to do it all. 13808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 13828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul/* 13898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This is the fallback for Driver.TestProxyTexImage(). 13908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 13918e39ad2cd67d49be40ff0822f3269affdf83d601Brian PaulGLboolean 13928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, 13938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint internalFormat, GLenum format, GLenum type, 13948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width, GLint height, GLint depth, GLint border) 13958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul{ 13968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_unit *texUnit; 13978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_object *texObj; 13988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage; 13998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 14008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (void) format; 14018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (void) type; 14028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 14038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 14048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 14058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 14068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 14078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* We always pass. 14088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * The core Mesa code will have already tested the image size, etc. 14098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Drivers may have more stringent texture limits to enforce and will 14108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * have to override this function. 14118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul */ 14126628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul /* setup the teximage struct's fields */ 14132c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes _mesa_init_tex_format( ctx, internalFormat, texImage ); 14148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 14158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return GL_TRUE; 14168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 1417