teximage.c revision 75280a2c742ee241d392618a3b29548fce1520a9
175280a2c742ee241d392618a3b29548fce1520a9Brian Paul/* $Id: teximage.c,v 1.82 2001/03/05 22:18:23 brianp Exp $ */ 2afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 4afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library 501e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul * Version: 3.5 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. 85e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 155e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 185e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 26afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#ifdef PC_HEADER 29afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "all.h" 30afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#else 31fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 32afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 33f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul#include "convolve.h" 34afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 35ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 36fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "mem.h" 37afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "mmath.h" 38fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 39afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 415e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 427298e71360ca1f38e7f0e0426fbf1a8dcbafdbd7Brian Paul#include "swrast/s_span.h" /* XXX SWRAST hack */ 43afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#endif 44afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 45afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * NOTES: 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * 49699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul * Mesa's native texture datatype is GLchan. Native formats are 50c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, 51c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * and GL_COLOR_INDEX. 52c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Device drivers are free to implement any internal format they want. 53afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 54afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 55afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 564827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul#ifdef DEBUG 57e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paulstatic void PrintTexture(const struct gl_texture_image *img) 584827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul{ 59e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul int i, j, c; 60699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *data = img->Data; 61e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul 62e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul if (!data) { 63e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul printf("No texture data\n"); 64e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul return; 65e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul } 66e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul 67e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul switch (img->Format) { 68e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_ALPHA: 69e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_LUMINANCE: 70e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_INTENSITY: 71e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_COLOR_INDEX: 72e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul c = 1; 73e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul break; 74e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_LUMINANCE_ALPHA: 75e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul c = 2; 76e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul break; 77e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_RGB: 78e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul c = 3; 79e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul break; 80e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul case GL_RGBA: 81e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul c = 4; 82e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul break; 83e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul default: 8408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "error in PrintTexture\n"); 85e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul return; 86e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul } 87e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul 88e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul 89e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul for (i = 0; i < img->Height; i++) { 90e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul for (j = 0; j < img->Width; j++) { 914827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul if (c==1) 924827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul printf("%02x ", data[0]); 934827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul else if (c==2) 94e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul printf("%02x%02x ", data[0], data[1]); 954827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul else if (c==3) 96e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul printf("%02x%02x%02x ", data[0], data[1], data[2]); 974827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul else if (c==4) 98e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]); 994827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul data += c; 1004827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul } 1014827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul printf("\n"); 1024827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul } 1034827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul} 1044827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul#endif 1054827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1064827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1074827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 108f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Compute log base 2 of n. 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * If n isn't an exact power of two return -1. 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * If n<0 return -1. 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 113fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 114fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (n<0) { 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Given an internal texture format enum or 1, 2, 3, 4 return the 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, 140c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. 141c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return -1 if invalid enum. 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 143b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 144aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul_mesa_base_tex_format( GLcontext *ctx, GLint format ) 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 146289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* 147289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul * Ask the driver for the base format, if it doesn't 148289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul * know, it will return -1; 149289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul */ 150289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ctx->Driver.BaseCompressedTexFormat) { 151289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format); 152289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ifmt >= 0) { 153289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return ifmt; 154289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 155289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg switch (format) { 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 181afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 182afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 186afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 187afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 189afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 190afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 191afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 194afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 196afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 197afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 198afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 199afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 200afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 201afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 202afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 203afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 204afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX: 206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX1_EXT: 207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX2_EXT: 208afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX4_EXT: 209afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX8_EXT: 210afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX12_EXT: 211afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX16_EXT: 212afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_COLOR_INDEX; 213f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT: 214f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT16_SGIX: 215f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT24_SGIX: 216f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT32_SGIX: 217f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (ctx->Extensions.SGIX_depth_texture) 218f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 219f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else 220f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return -1; 221afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg default: 222afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; /* error */ 223afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 224afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 225afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 226afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 227f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul/* 228f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul * Test if the given image format is a color/rgba format. That is, 229f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul * not color index, depth, stencil, etc. 230f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul */ 231f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 232f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulis_color_format(GLenum format) 233f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 234f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul switch (format) { 235f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA: 236f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA4: 237f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA8: 238f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA12: 239f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA16: 240f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 1: 241f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE: 242f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4: 243f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8: 244f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12: 245f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16: 246f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 2: 247f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE_ALPHA: 248f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4_ALPHA4: 249f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE6_ALPHA2: 250f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8_ALPHA8: 251f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA4: 252f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA12: 253f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16_ALPHA16: 254f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY: 255f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY4: 256f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY8: 257f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY12: 258f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY16: 259f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 3: 260f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB: 261f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_R3_G3_B2: 262f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB4: 263f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5: 264f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB8: 265f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10: 266f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB12: 267f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB16: 268f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 4: 269f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA: 270f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA2: 271f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA4: 272f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5_A1: 273f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA8: 274f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10_A2: 275f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA12: 276f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA16: 277f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 278f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 279f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 280f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 281f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 282f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 283f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 284f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 285f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulis_index_format(GLenum format) 286f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 287f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul switch (format) { 288f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX: 289f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX1_EXT: 290f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX2_EXT: 291f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX4_EXT: 292f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX8_EXT: 293f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX12_EXT: 294f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX16_EXT: 295f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 296f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 297f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 298f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 299f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 300f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 301afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 302afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 303aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE 304aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * otherwise. 305aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 306aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paulstatic GLboolean 307289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paulis_compressed_format(GLcontext *ctx, GLenum internalFormat) 308aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 309289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ctx->Driver.IsCompressedFormat) { 310289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat); 311289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 312289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return GL_FALSE; 313aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 314aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 315aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 316afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 317afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 3188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 3198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 3208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 321afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 322fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic void 323fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulset_tex_image(struct gl_texture_object *tObj, 324fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level, 325fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul struct gl_texture_image *texImage) 326fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 327fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 328fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 329fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 330fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 331fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->Image[level] = texImage; 332fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 333fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 334413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul tObj->Image[level] = texImage; 335fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 336fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 337fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegX[level] = texImage; 338fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 339fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 340fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosY[level] = texImage; 341fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 342fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 343fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegY[level] = texImage; 344fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 345fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 346fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosZ[level] = texImage; 347fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 348fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 349fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegZ[level] = texImage; 350fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 351fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 35208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in set_tex_image()"); 353fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 354fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 355fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 356fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 357fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 3588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 35977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul/* 36077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul * Return new gl_texture_image struct with all fields initialized to zero. 36177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 36277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 363021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_alloc_texture_image( void ) 36477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 36577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 36677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 36777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 36877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 36977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 37077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 371021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_free_texture_image( struct gl_texture_image *teximage ) 37277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 37377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul if (teximage->Data) { 37477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul FREE( teximage->Data ); 37577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul teximage->Data = NULL; 37677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul } 37777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul FREE( teximage ); 37877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 37977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 38077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 381fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul/* 3828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Return GL_TRUE if the target is a proxy target. 383aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 3848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLboolean 3858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulis_proxy_target(GLenum target) 386aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 3878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 3888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 3898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 3908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); 391aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 392aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 393aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 394aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul/* 39535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * Given a texture unit and a texture target, return the corresponding 39635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * texture object. 39735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 39835d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 39901e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 40035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 40135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 40235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 40335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 404a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D; 40535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 40635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy1D; 40735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 408a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D; 40935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 41035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy2D; 41135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 412a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D; 41335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 41435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy3D; 41535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 41635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 41735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 41835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 41935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 42035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 421a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 42235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? texUnit->CurrentCubeMap : NULL; 42335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 424a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 42535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? ctx->Texture.ProxyCubeMap : NULL; 42635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 42708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 42835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 42935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 43035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 43135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 43235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 43335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul/* 434fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * Return the texture image struct which corresponds to target and level 435fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * for the given texture unit. 436fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 437fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 438fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 439fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level) 440fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 441fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texUnit); 442fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 443fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_1D: 444a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D->Image[level]; 445fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_1D: 446fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy1D->Image[level]; 447fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 448a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D->Image[level]; 449fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_2D: 450fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy2D->Image[level]; 451fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_3D: 452a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D->Image[level]; 453fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_3D: 454fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy3D->Image[level]; 455fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 456a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 457413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return texUnit->CurrentCubeMap->Image[level]; 458fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 459fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 460fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 461a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 462fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegX[level]; 463fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 464fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 465fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 466a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 467fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosY[level]; 468fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 469fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 470fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 471a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 472fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegY[level]; 473fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 474fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 475fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 476a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 477fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosZ[level]; 478fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 479fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 480fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 481a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 482fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegZ[level]; 483fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 484fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 485fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 486a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 487413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return ctx->Texture.ProxyCubeMap->Image[level]; 488fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 489fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 490fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 49108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(ctx, "bad target in _mesa_select_tex_image()"); 492fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 493fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 494fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 495fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 496fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 497fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 498f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 499afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 500afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 5018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 502afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 5048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 5068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 5078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 5088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 509afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 510afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 511afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 514afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 51665d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 517afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 518afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 519afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 520afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 521afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 522afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 523afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 525afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 526afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 5288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 5298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 5308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 5328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 5338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 5348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 5358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 5368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 5378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 539afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 541afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 5428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 549f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 5509c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 5519c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 552f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 553f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 554f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 5559c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 5569c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 557f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 5589c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 5599c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 5609c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Format = 0; 561f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul img->Type = 0; 5629c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IntFormat = 0; 5639c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->RedBits = 0; 5649c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->GreenBits = 0; 5659c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->BlueBits = 0; 5669c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->AlphaBits = 0; 5679c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IntensityBits = 0; 5689c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->LuminanceBits = 0; 5699c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IndexBits = 0; 5709c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 5719c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 5729c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 5739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 5749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 5759c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 5769c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 5779c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 5789c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 5799c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 5809c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 5819c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IsCompressed = 0; 5829c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->CompressedSize = 0; 583f378ab825c0c74aab263e7dec30194eead22c288Brian Paul img->FetchTexel = NULL; 5849c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 5859c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 5869c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 5876628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul/* 5886628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 5896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 5906628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paulstatic void 5916628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paulinit_teximage_fields(GLcontext *ctx, 5926628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul struct gl_texture_image *img, 5936628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 5946628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul GLint border, GLenum internalFormat) 5956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 5966628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 5976628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 5986628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->IntFormat = internalFormat; 5996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 6006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 6016628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 6026628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 6036628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->WidthLog2 = logbase2(width - 2 * border); 6046628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (height == 1) /* 1-D texture */ 6056628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 6066628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 6076628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = logbase2(height - 2 * border); 6086628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (depth == 1) /* 2-D texture */ 6096628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 6106628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 6116628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = logbase2(depth - 2 * border); 6126628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width2 = 1 << img->WidthLog2; 6136628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height2 = 1 << img->HeightLog2; 6146628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth2 = 1 << img->DepthLog2; 6156628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 6166628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->IsCompressed = is_compressed_format(ctx, internalFormat); 6176628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 6186628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 6196628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 6209c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 6219c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul/* 622c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexImage[123]D() parameters for errors. 623afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input: 624afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * dimensions - must be 1 or 2 or 3 625afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 626afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 627c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 628c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paultexture_error_check( GLcontext *ctx, GLenum target, 629c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 630c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 6315b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLuint dimensions, 632c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 633c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 634afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 635afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLboolean isProxy; 636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint iformat; 637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 638afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions == 1) { 6395b37c322741f019118a618bc6220f37adba4fbcdBrian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D); 640afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (target != GL_TEXTURE_1D && !isProxy) { 64108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 642afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 645afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 6468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D || 6478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); 648413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul if (target != GL_TEXTURE_2D && !isProxy && 649a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell !(ctx->Extensions.ARB_texture_cube_map && 650413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 651413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 65208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 655afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 6575b37c322741f019118a618bc6220f37adba4fbcdBrian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D); 658afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (target != GL_TEXTURE_3D && !isProxy) { 65908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 661afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 662afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 66408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 665afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 667afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 668afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Border */ 6699fd2b0a698163b397b0a17493e52b27273e51b63Brian Paul if (border != 0 && border != 1) { 670afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 671c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 672ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(border=%d)", dimensions, border); 67308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 674afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 675afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 677afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Width */ 679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize 680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( width - 2 * border ) < 0) { 681afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 682c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 683ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(width=%d)", dimensions, width); 68408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 685afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 686afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 687afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 688afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 689afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Height */ 690afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions >= 2) { 691afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize 692afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( height - 2 * border ) < 0) { 693afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 694c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 695ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(height=%d)", dimensions, height); 69608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 698c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 700afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 701afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 702ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 703ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 704ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 705ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 706ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (!isProxy) { 70708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); 708ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 709ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 710ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 711ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 712ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 713afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Depth */ 714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions >= 3) { 715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize 716afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( depth - 2 * border ) < 0) { 717afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 718ec15398681249fca439794de03bf2a89d04f6c55Brian Paul char message[100]; 719ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage3D(depth=%d)", depth ); 72008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, message ); 721afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 722afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 725afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 726afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Level */ 7279fd2b0a698163b397b0a17493e52b27273e51b63Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 728c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 730ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(level=%d)", dimensions, level); 73108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 732c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 734afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 735afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 7361f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul /* For cube map, width must equal height */ 7371f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 7381f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 7391f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul if (width != height) { 74008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); 7411f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul return GL_TRUE; 7421f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul } 7431f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul } 7441f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul 745aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul iformat = _mesa_base_tex_format( ctx, internalFormat ); 746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (iformat < 0) { 747c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 748c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 749ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(internalFormat=0x%x)", dimensions, 750ec15398681249fca439794de03bf2a89d04f6c55Brian Paul internalFormat); 75108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 752c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 753afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 754afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 756289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (!is_compressed_format(ctx, internalFormat)) { 757aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!_mesa_is_legal_format_and_type( format, type )) { 758aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 759aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 760aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 761aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!isProxy) { 762aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul char message[100]; 763aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul sprintf(message, "glTexImage%dD(format or type)", dimensions); 76408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, message); 765aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 766aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return GL_TRUE; 767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 770afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 774afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 775afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 776afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 777c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: 779c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * dimensions - must be 1 or 2 or 3 780c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 782c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 783fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 784c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 785c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 787c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 789afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *destTex; 791afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 792c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 793c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_1D) { 79408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 795c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 796afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 797c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 798c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 799a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 800fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 801fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 802fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 80308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 804fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 805fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 806fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 807fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 80808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 809c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 810afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 811c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 812c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 813c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_3D) { 81408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 815c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 816afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 817c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 818c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 81908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 821c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 823c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 824ec15398681249fca439794de03bf2a89d04f6c55Brian Paul char message[100]; 825ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage2D(level=%d)", level); 82608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, message); 827c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 828c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 830c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 831c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 832ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(width=%d)", dimensions, width); 83308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 834c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 835c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 836c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 837c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 838ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(height=%d)", dimensions, height); 83908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 840c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 841c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 842c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 843c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 844ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(depth=%d)", dimensions, depth); 84508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 846c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 847c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 848afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 849f2718b0966f54049056e16e7cca08718341557b2Brian Paul destTex = _mesa_select_tex_image(ctx, texUnit, target, level); 850f2718b0966f54049056e16e7cca08718341557b2Brian Paul 851c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 85208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); 853c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 854c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 855afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 856c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 85708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); 858c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 859afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 860c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 86108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); 862c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 863c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 864c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 865c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 86608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); 867c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 869c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 87008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); 871c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 872afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 873afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 874c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 875c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 87608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 877c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 878c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 879c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) { 88008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 881c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 882c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 883afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 884afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 885289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (!is_compressed_format(ctx, destTex->IntFormat)) { 8869540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!_mesa_is_legal_format_and_type(format, type)) { 8879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul char message[100]; 8889540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul sprintf(message, "glTexSubImage%dD(format or type)", dimensions); 88908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, message); 8909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return GL_TRUE; 8919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 892c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 893afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 894c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 895c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 896afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 897afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 898afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 899c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: dimensions - must be 1 or 2 or 3 901c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 902afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 903c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 904fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 905c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 906c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 907afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 908c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint iformat; 909afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 910fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 911fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 91208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 913fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 914fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 915c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 916fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 917a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 918fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 919fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 920fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 92108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 922fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 923fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 924fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 925fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 92608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 927fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 928fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 929c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 930c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 931c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Border */ 932c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (border!=0 && border!=1) { 933c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 934c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexImage%dD(border)", dimensions); 93508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 936c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 937c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 938c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 939c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Width */ 940c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize 941c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( width - 2 * border ) < 0) { 942c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 943ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width); 94408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 945c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 946c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 947c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 948c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Height */ 949c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions >= 2) { 950c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize 951c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( height - 2 * border ) < 0) { 952c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 953ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height); 95408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 955c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 956c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 957c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 958c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 959ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 960ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 961ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 962ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 96308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); 964ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 965ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 966ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 967ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 968c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Level */ 969c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level<0 || level>=ctx->Const.MaxTextureLevels) { 970c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 971ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level); 97208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 973c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 974c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 975c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 976aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul iformat = _mesa_base_tex_format( ctx, internalFormat ); 977c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (iformat < 0) { 978c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 979c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions); 98008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 981c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 982c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 983c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 984c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 985c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 986c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 987c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 988c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 989c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 990fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 991c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 992c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 9935b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLsizei width, GLsizei height ) 994c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 995c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 996c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 997c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 998fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 999fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 100008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 1001fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1002fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1003c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1004fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1005a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 1006fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 1007fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 1008fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 100908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1010fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1011fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1012fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1013fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 101408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1015fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1016fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1017c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1018fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 1019fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_3D) { 102008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 1021fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1022fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1023c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1024c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1025c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 1026c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1027ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level); 102808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1029c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1030c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1031c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1032c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 1033c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1034ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(width=%d)", dimensions, width); 103508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1036c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1037c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1038c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1 && height < 0) { 1039c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1040ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(height=%d)", dimensions, height); 104108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1042c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1043c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1044c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1045a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = _mesa_select_tex_image(ctx, texUnit, target, level); 1046c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 1047c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1048c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions); 104908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, message); 1050c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1051c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1052c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1053c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 1054c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1055ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 105608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1057c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1058c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1059c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) { 1060c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1061c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions); 106208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1063c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1064c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1065c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1066c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 1067c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1068ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 106908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1070c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1071c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1072c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 1073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) { 1074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions); 107608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1077c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1078c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1079c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1080c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1081c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1082c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 1083c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1084c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions); 108508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1086c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1087c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1088c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset > (GLint) (teximage->Depth+teximage->Border)) { 1089c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 1090c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 109108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1092c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1093c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1094c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1095c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1096c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1097c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1098c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1099c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1100c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1101c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 11028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 11038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 11048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum type, GLvoid *pixels ) 1105289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul{ 11068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GET_CURRENT_CONTEXT(ctx); 11078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 11088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_object *texObj; 11098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage; 11108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 11128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 111408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 11158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 1116289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 1117289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 11188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (_mesa_sizeof_type(type) <= 0) { 111908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 11208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1123f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (_mesa_components_in_format(format) <= 0 || 1124f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul format == GL_STENCIL_INDEX) { 112508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 11268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1129f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { 113008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 1131f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1132f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 1133f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) { 113408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 1135f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1136f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 1137f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX what if format/type doesn't match texture format/type? */ 1138f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 11398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!pixels) 11408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 11438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 11448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texObj || is_proxy_target(target)) { 114508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 11468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 11508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage) { 11518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* invalid mipmap level, not an error */ 11528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) { 11568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* no image data, not an error */ 11578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->NewState & _NEW_PIXEL) 116108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 11628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1163f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format) && 1164f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 11658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convert texture image to GL_RGBA, GL_FLOAT */ 11668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width = texImage->Width; 11678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint height = texImage->Height; 11688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint depth = texImage->Depth; 11698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 11708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *tmpImage, *convImage; 11718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); 11728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!tmpImage) { 117308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); 11748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); 11778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!convImage) { 11788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 117908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); 11808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 11818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < depth; img++) { 11848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint convWidth, convHeight; 11858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convert texture data to GLfloat/GL_RGBA */ 11878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < height; row++) { 11888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan texels[1 << MAX_TEXTURE_LEVELS][4]; 11898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint col; 11908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *dst = tmpImage + row * width * 4; 11918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (col = 0; col < width; col++) { 1192e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 11938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texels[col]); 11948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst, 11968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_RGBA, CHAN_TYPE, texels, 11978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, 11988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, 11998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_FALSE); 1200289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 12018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 12028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convWidth = width; 12038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convHeight = height; 12048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 12058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convolve */ 12068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 12078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution1DEnabled) { 12088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); 12098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1210289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 12118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 12128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution2DEnabled) { 12138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, 12148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 12158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 12168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else if (ctx->Pixel.Separable2DEnabled) { 12178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, 12188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 12198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1220289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 12218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 12228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* pack convolved image */ 12238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < convHeight; row++) { 12248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLfloat *src = convImage + row * convWidth * 4; 12258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels, 12268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convWidth, convHeight, 12278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, img, row, 0); 12288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_pack_float_rgba_span(ctx, convWidth, 12298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (const GLfloat(*)[4]) src, 12308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, dest, &ctx->Pack, 12318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS); 1232289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 12338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 12348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 12358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 12368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(convImage); 1237289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 12388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 1239f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* no convolution, or non-rgba image */ 12408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width = texImage->Width; 12418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint height = texImage->Height; 12428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint depth = texImage->Depth; 12438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 12448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < depth; img++) { 12458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < height; row++) { 12468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* compute destination address in client memory */ 12478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, 1248f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul width, height, format, type, 1249f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul img, row, 0); 12508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul assert(dest); 12518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1252f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (format == GL_COLOR_INDEX) { 1253f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLuint indexRow[MAX_WIDTH]; 1254f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint col; 1255f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (col = 0; col < width; col++) { 1256e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1257e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) &indexRow[col]); 1258f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1259f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_pack_index_span(ctx, width, type, dest, 1260f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul indexRow, &ctx->Pack, 1261f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul ctx->_ImageTransferState); 1262f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1263f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else if (format == GL_DEPTH_COMPONENT) { 1264f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLfloat depthRow[MAX_WIDTH]; 1265f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint col; 1266f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (col = 0; col < width; col++) { 1267e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1268e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) &depthRow[col]); 1269f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1270f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_pack_depth_span(ctx, width, dest, type, 1271f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul depthRow, &ctx->Pack); 1272f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1273f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else { 12748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* general case: convert row to RGBA format */ 12758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan rgba[MAX_WIDTH][4]; 12768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint col; 12778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (col = 0; col < width; col++) { 1278e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1279e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) rgba[col]); 12808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1281e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul _mesa_pack_rgba_span(ctx, width, (const GLchan (*)[4])rgba, 1282e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul format, type, dest, &ctx->Pack, 1283e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul ctx->_ImageTransferState); 12848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* format */ 12858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* row */ 12868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* img */ 12878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* convolution */ 1288289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul} 1289289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1290289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 12918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1292289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 1293c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 1294c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 1295fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 129643911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 1297fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 1298fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 1299c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1300ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1301fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1302cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1303c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1304f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1305f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1306f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1307f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 13088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 1309f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 13100293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 13110293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1312f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1313aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1314f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 1, postConvWidth, 1, 1, border)) { 13158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1316c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1317c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1318f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 13198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 13208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 13210293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 13220293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1323021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 13240293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 13250293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 132608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 13270293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 13280293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 13290293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 13300293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 13318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 13320293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 13330293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1334c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1335f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 13366628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, 13376628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul border, internalFormat); 1338c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 13399499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 134008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1341fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 13428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage1D); 1343c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 13448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 13458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, format, type, pixels, 13468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1347c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1348c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 13498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, 1, 1, format); 13508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 13518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 13528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, 13538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 13548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 13558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 13560293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1357c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1358c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1359f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1360f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1361f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->LuminanceBits || texImage->IntensityBits || 1362f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits); 1363f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1364f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 13650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1366a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1367a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1368c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 136938d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 1370c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 137138d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 13728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, 1, 13738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 13748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1375a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1376a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1377a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1378a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1379a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, 1380a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 13818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 138238d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 138338d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 13848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 138538d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 138638d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1387aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 13888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1389f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 1390c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1391c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1392c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1393c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 139408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1395c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1396c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1397c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1398c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1399c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1400fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 140143911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 1402fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 1403fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1404fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1405c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1406ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1407fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1408cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1409c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1410f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1411f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 1412f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 1413f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1414f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 14158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 1416a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 1417fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1418fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 14198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 1420f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 14210293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 14220293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1423f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1424aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1425f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 2, postConvWidth, postConvHeight, 1426f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 1, border)) { 14278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1428c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1429c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1430f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 143135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 1432fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 14330293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 14340293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1435021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 1436fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul set_tex_image(texObj, target, level, texImage); 14370293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 143808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 14390293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 14400293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 14410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 14420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 14438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 14440293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 14450293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1446c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1447f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 14486628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, 14496628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul border, internalFormat); 1450c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 14519499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 145208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1453fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 14548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage2D); 1455c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 14568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 14578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, format, type, pixels, 14588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1459c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1460c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 14618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, 1, format); 14628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 14638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 14648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, 14658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 14668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 14678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 14680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1469afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1470afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1471f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1472f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1473f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->LuminanceBits || texImage->IntensityBits || 1474f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits); 1475f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1476f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 14770293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1478a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1479a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 148138d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_2D) { 1482afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 148338d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 14848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, 2, 14858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, postConvHeight, 1, border); 14868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1487a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1488a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1489a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1490a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1491a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, 1492a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 14938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 149438d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 14958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, format, type, 14968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, postConvHeight, 1, border); 149738d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 149838d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1499aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 15008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1501f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 1502afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1503afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1504afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 150608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 1507afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1508afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1509afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1510afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1511afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 1513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 1514afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 1515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1516fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 151743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 1518fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1519fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 1520fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1521afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1522fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1523cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_3D) { 1526f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 15270293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 15280293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1529289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1530aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1531aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul format, type, 3, width, height, depth, border)) { 15328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1535f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 15368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 15378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 15380293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 15390293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1540021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 15410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 15420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 154308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 15440293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 15450293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 15460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 15470293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 15480293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 15490293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1551f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 15526628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, width, height, depth, border, 15536628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul internalFormat); 1554afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15559499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 155608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1557fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 15588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage3D); 1559c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 15608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 15618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 15628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 15638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 15668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, depth, format); 15678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 15688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 15698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 15708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 15718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 15728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 15730293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1574afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1575afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1576f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1577f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1578f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->LuminanceBits || texImage->IntensityBits || 1579f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul texImage->DepthBits); 1580f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1581f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 15820293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1583a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1584a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1585afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 158638d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 1587afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 158838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 158938d3f3d660225150715bc06f6b33e394ba803299Brian Paul format, type, 3, width, height, depth, border); 15908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1591a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1592a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1593a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1594a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1595a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, width, height, 1, 1596a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 15978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 159838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 159938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 160038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 160138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 160238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1603aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1604f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1605f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 1606afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1608afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1609afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 161008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1611afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1612afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1613afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1614afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1615afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1616663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paulvoid 161743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 1618663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1619663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 1620663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 1621663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 162243911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 1623663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 1624663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 1625663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1626663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1627afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1628fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1629fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 1630fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 1631fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1632fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1633afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1634ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1635fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 16360293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 16370293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 16380293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1639a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul 164075280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 164175280a2c742ee241d392618a3b29548fce1520a9Brian Paul 16422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (ctx->NewState & _NEW_PIXEL) 164308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 16442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1645f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1646f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 1647f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1648f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1650c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 1651a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, 1, 1, format, type)) { 1652f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16550293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 16568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 16578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 16580293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1659afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1660c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || !pixels) 1661c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1662afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage1D); 16648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 16658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, &ctx->Unpack, 16668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 1667bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1668afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1669afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1670afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1671fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1672fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 1673fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 1674fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 1675fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1676fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1677afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1678ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1679fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 16800293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 16810293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 16820293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1683a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul 168475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 168575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 16862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (ctx->NewState & _NEW_PIXEL) 168708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 16882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1689f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1690f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 1691f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 1692f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 1693f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1694afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1695c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1696a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, postConvHeight, 1, format, type)) { 1697f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17000293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 170135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 17028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 17030293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1705c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || !pixels) 1706c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1707afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage2D); 17098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 17108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, format, type, pixels, 17118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1712bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1713c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1716afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1717fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1718fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 1719fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1720fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1721fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1722fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1724fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 17250293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 17260293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 17270293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 172975280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 173075280a2c742ee241d392618a3b29548fce1520a9Brian Paul 17312aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (ctx->NewState & _NEW_PIXEL) 173208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 17332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1734c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 1735c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 1736f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1737afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1738afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17390293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 17408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 17418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 17420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1743afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1744c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || height == 0 || !pixels) 1745c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage3D); 17488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 17498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 17508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 17518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 17528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage ); 1753bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1754afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1756afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1758fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1759fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 1760fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 1761fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 1762fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 1763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 17642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 17652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 17662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 1767ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1768fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1769cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1770afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17719499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 177208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1773fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1774f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1775f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1776f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1777ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1778ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 1779ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, 1, border)) 1780ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1781ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 17822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 17832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 17842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 17852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 17862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_alloc_texture_image(); 17872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul set_tex_image(texObj, target, level, texImage); 17882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 178908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 1790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1791c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 17922aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 17932aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else if (texImage->Data) { 17942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* free the old texture data */ 17952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(texImage->Data); 17962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage->Data = NULL; 17972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 17987dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 17992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 18002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, 18012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul border, internalFormat); 18027dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 18032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 18042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage1D); 18052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, 18062aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, border); 18072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 18082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 18092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 18102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 1811afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1812afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1813afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1814afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1815fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1816fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 1817fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 1818fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 1819afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 18202aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 18212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 18222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 1823ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1824fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1825cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1826afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18279499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 182808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1829fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1830f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1831f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 1832f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 1833f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1834ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1835ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 1836ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight, border)) 1837ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1838ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 18392aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 18402aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 18412aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 18422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 18432aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_alloc_texture_image(); 18442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul set_tex_image(texObj, target, level, texImage); 18452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 184608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 1847c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 18492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 18502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else if (texImage->Data) { 18512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* free the old texture data */ 18522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul FREE(texImage->Data); 18532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage->Data = NULL; 18542aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 18557dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 18562aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 18572aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, 18582aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul border, internalFormat); 1859afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18602aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 18612aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, 18622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height, border); 18632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 18642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 18652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 18662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 1867afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1869afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1870afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1871fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1872fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 1873fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 1874afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1875ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1876fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1877cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1878afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18799499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 188008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1881fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1882f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 18838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1884ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1885ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 1, target, level, 1886ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul xoffset, 0, 0, postConvWidth, 1)) 1887ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1888ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 18892aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage1D); 18902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width); 1891bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1892afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1893afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1894afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1895afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1896fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1897fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 1898fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 1899fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 1900afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1901ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1902fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1903cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1904afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 19059499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 190608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1907fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1908f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1909f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 1910ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1911ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1912ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight)) 1913ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1914ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 19152aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage2D); 19162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 19172aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, x, y, width, height); 1918bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1919afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1920afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1921afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1922afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1923fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1924fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 1925fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1926fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 1927afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1928ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1929fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1930cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1931afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 19329499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 193308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1934fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1935f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1936f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 1937ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1938ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, 1939ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul zoffset, postConvWidth, postConvHeight)) 1940ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1941ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 19422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage3D); 19432aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 19442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, zoffset, 19452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height); 1946bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1947afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 19481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 19491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 19501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 19511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 19521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 1953aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 19541207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 19551207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 19561207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 1957aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 1958cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1959aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1960289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 1961289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 1962289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 1963289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 1964289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 1965289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 1966289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 196708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); 1968289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 1969289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 1970289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 1971289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 1972289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 1973289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1974aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 1975aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 1976aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 1977aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 1978aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1979aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1980aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border)) { 1981aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 1982aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1983aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1984aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 19858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 19868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1987aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1988aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 1989aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 1990aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 1991aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 199208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB"); 1993aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 1994aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1995aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1996aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 1997aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 1998aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 1999aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2000aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 20016628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, width, 1, 1, border, internalFormat); 20026628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 20038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 20048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 20058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 20068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, border, 20078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul imageSize, data, 20088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 20098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2010aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2011aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2012aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2013a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2014a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2015aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2016aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2017aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 201838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 201938d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border); 20208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2021a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2022a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2023a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2024a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2025a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, width, 1, 1, 2026a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 20278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 202838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 202938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 203038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 203138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 203238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2033aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2034f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 2035f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 2036aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2037aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2038aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2039aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 204008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" ); 2041aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2042aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 20431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 20441207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20451207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20461207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 20471207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 2048aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 20491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 20501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 20511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2052aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2053cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2054aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2055289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2056289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2057289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2058289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2059289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2060289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2061289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 206208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); 2063289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2064289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2065289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2066289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2067289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2068289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 20698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 2070a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 20719540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 20729540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 2073aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2074aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2075aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2076aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2077aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2078aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, height, 1, border)) { 2079aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2080aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2081aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2082aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 20838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 20848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2085aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2086aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2087aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2088aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2089aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 209008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); 2091aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2092aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2093aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2094aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2095aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 2096aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2097aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2098aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 20996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, width, height, 1, border, 21006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul internalFormat); 21016628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 21028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 21038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 21048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 21058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, height, 21068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 21078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 21088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2109aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2110aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2111aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2112a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2113a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2114aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2115aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_2D) { 2116aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 211738d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 211838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 2, width, height, 1, border); 21198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2120a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2121a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2122a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2123a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2124a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, width, height, 1, 2125a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 21268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 212738d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 212838d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 212938d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 213038d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 213138d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2132aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2133f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 2134f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 2135aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2136aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2137aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2138aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 213908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" ); 2140aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2141aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 21421207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 21431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21441207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21451207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 21461207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 2147aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 21481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 21491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 21501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2151aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2152cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2153aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2154289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2155289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2156289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2157289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2158289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2159289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2160289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 216108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); 2162289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2163289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2164289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2165289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2166289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2167289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 21689540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 2169aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2170aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2171aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2172aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2173aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2174aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, height, depth, border)) { 2175aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2176aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2177aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2178aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 21808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2181aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2182aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2183aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2184aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2185aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 218608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); 2187aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2188aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2189aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2190aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2191aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 2192aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2193aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2194aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 21956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul init_teximage_fields(ctx, texImage, width, height, depth, border, 21966628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul internalFormat); 21976628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 21988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 21998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 22008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 22018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, 22028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 22038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 22048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 22058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2206aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2207aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2208aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2209a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2210a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2211aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2212aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 2213aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 221438d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 221538d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 1, width, height, depth, border); 22168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2217a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2218a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2219a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2220a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2221a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul init_teximage_fields(ctx, texImage, width, height, depth, 2222a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul border, internalFormat); 22238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 222438d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 222538d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 222638d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 222738d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 222838d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2229aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2230f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 2231f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 2232aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2233aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2234aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2235aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 223608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" ); 2237aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2238aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 22391207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 22401207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22411207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22421207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 22431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 22441207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei width, GLenum format, 22451207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 22461207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 22479540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 22489540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 22499540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2250a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 22519540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 225275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 225375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 22549540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 22559540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, 1, 1, format, GL_NONE)) { 22569540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 22579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22589540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22599540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 22609540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 22618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 22629540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 22639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || !data) 22659540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 22669540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22679540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage1D) { 22688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 22698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, width, 22708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 22718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 22729540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2273bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 22741207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 22751207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22761207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22771207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 22781207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 22791207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 22801207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 22811207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 22821207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 22839540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 22849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 22859540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2286a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 22879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 228875280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 228975280a2c742ee241d392618a3b29548fce1520a9Brian Paul 22909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 22919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, 1, format, GL_NONE)) { 22929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 22939540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22949540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22959540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 22969540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 22978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 22989540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 22999540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23009540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || !data) 23019540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 23029540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23039540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage2D) { 23048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 23058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, width, height, 23068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 23078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 23089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2309bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 23101207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 23111207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 23141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 23151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 23161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 23171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 23181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 23199540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 23209540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 23219540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2322a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 23239540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 232475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 232575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 23269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 23279540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, depth, format, GL_NONE)) { 23289540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 23299540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23309540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23319540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 23338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 23349540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 23359540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23369540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || depth == 0 || !data) 23379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 23389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage3D) { 23408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 23418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 23428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 23438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 23448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 23459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2346bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 23471207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 23481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 23519540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 23521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 23538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 23549540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul const struct gl_texture_object *texObj; 23559540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2356a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 23579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 2358cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 23599540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23609540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 236108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" ); 23629540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 23639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (is_proxy_target(target)) { 236608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 23678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 23689540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23699540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 23728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 23738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 23749540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage) { 23759540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul /* invalid mipmap level */ 237608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 23779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 23789540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23799540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23809540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage->IsCompressed) { 238108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); 23829540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 23839540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23859540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!img) 23869540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 23879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 23888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 23898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.GetCompressedTexImage); 23909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, 23919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texImage); 23929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 23931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 2394