teximage.c revision f378ab825c0c74aab263e7dec30194eead22c288
1f378ab825c0c74aab263e7dec30194eead22c288Brian Paul/* $Id: teximage.c,v 1.72 2001/02/06 23:35:26 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: 84e5d68a2b7dba4d4402ee117dcaebde0b35c87956Brian Paul gl_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; 213afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg default: 214afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; /* error */ 215afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 216afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 217afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 218afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 219afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 220afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 221aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE 222aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * otherwise. 223aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 224aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paulstatic GLboolean 225289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paulis_compressed_format(GLcontext *ctx, GLenum internalFormat) 226aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 227289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ctx->Driver.IsCompressedFormat) { 228289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat); 229289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 230289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return GL_FALSE; 231aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 232aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 233aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 234afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 235afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 2378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 2388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 239afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 240fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic void 241fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulset_tex_image(struct gl_texture_object *tObj, 242fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level, 243fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul struct gl_texture_image *texImage) 244fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 245fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 246fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 247fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 248fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 249fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->Image[level] = texImage; 250fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 251fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 252413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul tObj->Image[level] = texImage; 253fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 254fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 255fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegX[level] = texImage; 256fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 257fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 258fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosY[level] = texImage; 259fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 260fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 261fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegY[level] = texImage; 262fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 263fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 264fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosZ[level] = texImage; 265fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 266fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 267fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegZ[level] = texImage; 268fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 269fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 270fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_problem(NULL, "bad target in set_tex_image()"); 271fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 272fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 273fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 274fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 275fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 2768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 27777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul/* 27877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul * Return new gl_texture_image struct with all fields initialized to zero. 27977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 28077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 281021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_alloc_texture_image( void ) 28277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 28377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 28477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 28577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 28677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 28777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 28877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 289021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_free_texture_image( struct gl_texture_image *teximage ) 29077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 29177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul if (teximage->Data) { 29277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul FREE( teximage->Data ); 29377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul teximage->Data = NULL; 29477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul } 29577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul FREE( teximage ); 29677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 29777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 29877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 299fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul/* 3008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Return GL_TRUE if the target is a proxy target. 301aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 3028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLboolean 3038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulis_proxy_target(GLenum target) 304aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 3058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 3068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 3078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 3088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); 309aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 310aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 311aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 312aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul/* 31335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * Given a texture unit and a texture target, return the corresponding 31435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * texture object. 31535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 31635d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 31701e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 31835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 31935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 32035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 32135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 322a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D; 32335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 32435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy1D; 32535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 326a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D; 32735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 32835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy2D; 32935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 330a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D; 33135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 33235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy3D; 33335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 33435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 33535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 33635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 33735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 33835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 339a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 34035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? texUnit->CurrentCubeMap : NULL; 34135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 342a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 34335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? ctx->Texture.ProxyCubeMap : NULL; 34435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 34535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul gl_problem(NULL, "bad target in _mesa_select_tex_object()"); 34635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 34735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 34835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 34935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 35035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 35135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul/* 352fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * Return the texture image struct which corresponds to target and level 353fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * for the given texture unit. 354fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 355fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 356fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 357fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level) 358fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 359fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texUnit); 360fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 361fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_1D: 362a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D->Image[level]; 363fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_1D: 364fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy1D->Image[level]; 365fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 366a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D->Image[level]; 367fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_2D: 368fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy2D->Image[level]; 369fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_3D: 370a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D->Image[level]; 371fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_3D: 372fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy3D->Image[level]; 373fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 374a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 375413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return texUnit->CurrentCubeMap->Image[level]; 376fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 377fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 378fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 379a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 380fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegX[level]; 381fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 382fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 383fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 384a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 385fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosY[level]; 386fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 387fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 388fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 389a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 390fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegY[level]; 391fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 392fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 393fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 394a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 395fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosZ[level]; 396fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 397fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 398fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 399a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 400fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegZ[level]; 401fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 402fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 403fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 404a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 405413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return ctx->Texture.ProxyCubeMap->Image[level]; 406fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 407fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 408fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 409fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_problem(ctx, "bad target in _mesa_select_tex_image()"); 410fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 411fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 412fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 413fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 414fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 415fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 416f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 417afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 418afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 4198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 420afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 4218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 4228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 423afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 4248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 4258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 4268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 427afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 428afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 429afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 430afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 431afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 432afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 4338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 43465d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 435afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 436afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 437afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 438afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 439afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 440afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 441afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 442afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 443afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 444afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 4458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 4468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 4478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 4488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 4498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 4508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 4518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 4528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 4538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 4548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 4558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 456afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 457afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 458afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 459afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 4608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 4618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 462afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 463afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 464afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 465afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 466afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 467f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 4689c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 4699c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 470f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 471f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 472f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 4739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 4749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 475f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 4769c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 4779c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 4789c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Format = 0; 4799c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IntFormat = 0; 4809c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->RedBits = 0; 4819c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->GreenBits = 0; 4829c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->BlueBits = 0; 4839c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->AlphaBits = 0; 4849c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IntensityBits = 0; 4859c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->LuminanceBits = 0; 4869c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IndexBits = 0; 4879c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 4889c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 4899c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 4909c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 4919c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 4929c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 4939c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 4949c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 4959c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 4969c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 4979c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 4989c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IsCompressed = 0; 4999c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->CompressedSize = 0; 500f378ab825c0c74aab263e7dec30194eead22c288Brian Paul img->FetchTexel = NULL; 5019c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 5029c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 5039c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 5049c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 5059c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul/* 506c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexImage[123]D() parameters for errors. 507afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input: 508afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * dimensions - must be 1 or 2 or 3 509afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 510afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 511c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 512c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paultexture_error_check( GLcontext *ctx, GLenum target, 513c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 514c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 5155b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLuint dimensions, 516c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 517c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 518afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 519afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLboolean isProxy; 520afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint iformat; 521afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 522afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions == 1) { 5235b37c322741f019118a618bc6220f37adba4fbcdBrian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D); 524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (target != GL_TEXTURE_1D && !isProxy) { 525afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 526afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 527afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 528afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 529afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 5308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D || 5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); 532413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul if (target != GL_TEXTURE_2D && !isProxy && 533a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell !(ctx->Extensions.ARB_texture_cube_map && 534413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 535413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 536afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 537afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 539afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 5415b37c322741f019118a618bc6220f37adba4fbcdBrian Paul isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D); 542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (target != GL_TEXTURE_3D && !isProxy) { 543afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg gl_problem( ctx, "bad dims in texture_error_check" ); 549afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 551afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 552afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Border */ 5539fd2b0a698163b397b0a17493e52b27273e51b63Brian Paul if (border != 0 && border != 1) { 554afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 555c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 556ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(border=%d)", dimensions, border); 557c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 562afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Width */ 563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize 564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( width - 2 * border ) < 0) { 565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 566c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 567ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(width=%d)", dimensions, width); 568c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 571afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 573afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Height */ 574afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions >= 2) { 575afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize 576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( height - 2 * border ) < 0) { 577afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 578c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 579ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(height=%d)", dimensions, height); 580c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 581afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 582c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 584afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 585afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 586ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 587ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 588ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 589ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 590ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (!isProxy) { 591ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); 592ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 593ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 594ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 595ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 596ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 597afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Depth */ 598afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions >= 3) { 599afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize 600afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( depth - 2 * border ) < 0) { 601afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 602ec15398681249fca439794de03bf2a89d04f6c55Brian Paul char message[100]; 603ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage3D(depth=%d)", depth ); 604ec15398681249fca439794de03bf2a89d04f6c55Brian Paul gl_error( ctx, GL_INVALID_VALUE, message ); 605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 606afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 608afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 609afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 610afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Level */ 6119fd2b0a698163b397b0a17493e52b27273e51b63Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 612c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 613c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 614ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(level=%d)", dimensions, level); 615c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 616c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 617afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 618afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 619afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 620aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul iformat = _mesa_base_tex_format( ctx, internalFormat ); 621afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (iformat < 0) { 622c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 623c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 624ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexImage%dD(internalFormat=0x%x)", dimensions, 625ec15398681249fca439794de03bf2a89d04f6c55Brian Paul internalFormat); 626c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 627c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 628afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 629afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 630afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 631289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (!is_compressed_format(ctx, internalFormat)) { 632aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!_mesa_is_legal_format_and_type( format, type )) { 633aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 634aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 635aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 636aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!isProxy) { 637aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul char message[100]; 638aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul sprintf(message, "glTexImage%dD(format or type)", dimensions); 639aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error(ctx, GL_INVALID_OPERATION, message); 640aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 641aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return GL_TRUE; 642c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 645afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 650afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 651afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 652c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 653c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: 654c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * dimensions - must be 1 or 2 or 3 655c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 657c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 658fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 659c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 660c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 661c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 662c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 665c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *destTex; 666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 667c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 668c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_1D) { 669c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 670c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 671afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 672c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 673c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 674a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 675fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 676fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 677fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 678fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 679fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 680fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 681fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 682fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 683c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 684c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 685afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 686c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 687c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 688c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_3D) { 689c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 690c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 691afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 692c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 693c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 694c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_problem( ctx, "bad dims in texture_error_check" ); 695c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 696c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 698c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 699ec15398681249fca439794de03bf2a89d04f6c55Brian Paul char message[100]; 700ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage2D(level=%d)", level); 701ec15398681249fca439794de03bf2a89d04f6c55Brian Paul gl_error(ctx, GL_INVALID_ENUM, message); 702c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 703c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 705c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 706c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 707ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(width=%d)", dimensions, width); 708c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 709c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 710c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 711c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 712c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 713ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(height=%d)", dimensions, height); 714c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 715c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 716c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 717c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 718c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 719ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glTexSubImage%dD(depth=%d)", dimensions, depth); 720c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 721c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 722c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 724f2718b0966f54049056e16e7cca08718341557b2Brian Paul destTex = _mesa_select_tex_image(ctx, texUnit, target, level); 725f2718b0966f54049056e16e7cca08718341557b2Brian Paul 726c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 727c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); 728c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 730afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 731c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 732c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); 733c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 734afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 735c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 736c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); 737c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 738c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 739c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 740c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 741c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); 742c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 743afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 744c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 745c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); 746c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 747afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 748afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 749c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 750c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 751c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 752c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 753c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 754c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) { 755c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 756c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 757c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 759afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 760289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (!is_compressed_format(ctx, destTex->IntFormat)) { 7619540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!_mesa_is_legal_format_and_type(format, type)) { 7629540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul char message[100]; 7639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul sprintf(message, "glTexSubImage%dD(format or type)", dimensions); 7649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul gl_error(ctx, GL_INVALID_ENUM, message); 7659540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return GL_TRUE; 7669540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 769c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 770c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 774c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 775c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: dimensions - must be 1 or 2 or 3 776c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 777afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 779fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 780c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 781c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 782afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 783c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint iformat; 784afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 785fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 786fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 787fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 788fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 789fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 791fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 792a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 793fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 794fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 795fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 796fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 797fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 798fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 799fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 800fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 801fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 802fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 803fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 804c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 805c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 806c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Border */ 807c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (border!=0 && border!=1) { 808c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 809c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexImage%dD(border)", dimensions); 810c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 811c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 812c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 813c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 814c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Width */ 815c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize 816c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( width - 2 * border ) < 0) { 817c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 818ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width); 819c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 821c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 822c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 823c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Height */ 824c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions >= 2) { 825c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize 826c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( height - 2 * border ) < 0) { 827c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 828ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height); 829c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 830c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 831c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 832c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 833c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 834ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 835ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 836ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 837ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 838ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); 839ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 840ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 841ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 842ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 843c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Level */ 844c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level<0 || level>=ctx->Const.MaxTextureLevels) { 845c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 846ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level); 847c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 849c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 850c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 851aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul iformat = _mesa_base_tex_format( ctx, internalFormat ); 852c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (iformat < 0) { 853c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 854c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions); 855c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 856c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 857c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 858c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 859c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 860c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 861c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 862c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 863c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 864c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 865fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 866c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 867c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 8685b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLsizei width, GLsizei height ) 869c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 870c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 871c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 872c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 873fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 874fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 875fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 876fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 877fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 878c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 879fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 880a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 881fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 882fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 883fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 884fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 885fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 886fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 887fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 888fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 889fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 890fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 891fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 892c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 893fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 894fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_3D) { 895fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 896fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 897fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 898c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 899c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 901c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 902ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level); 903c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 904c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 905c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 906c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 907c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 908c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 909ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(width=%d)", dimensions, width); 910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 911c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 912c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 913c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1 && height < 0) { 914c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 915ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(height=%d)", dimensions, height); 916c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 917c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 918c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 919c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 920a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = _mesa_select_tex_image(ctx, texUnit, target, level); 921c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 922c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 923c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions); 924c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_OPERATION, message); 925c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 926c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 927c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 928c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 929c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 930ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 931c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 932c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 933c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 934c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) { 935c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 936c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions); 937c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 938c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 939c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 940c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 941c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 942c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 943ec15398681249fca439794de03bf2a89d04f6c55Brian Paul sprintf(message, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 944c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 945c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 946c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 947c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 948c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) { 949c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 950c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions); 951c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 952c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 953c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 954c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 955c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 956c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 957c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 958c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 959c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions); 960c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 961c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 962c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 963c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset > (GLint) (teximage->Depth+teximage->Border)) { 964c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul char message[100]; 965c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 966c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error(ctx, GL_INVALID_VALUE, message); 967c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 968c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 969c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 970c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 971c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 972c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 973c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 974c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 975c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 976c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 9778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 9788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 9798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum type, GLvoid *pixels ) 980289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul{ 9818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GET_CURRENT_CONTEXT(ctx); 9828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 9838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_object *texObj; 9848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul struct gl_texture_image *texImage; 9858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 9878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 9898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 9908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 991289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 992289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 9938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (_mesa_sizeof_type(type) <= 0) { 9948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 9958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 9968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 9978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (_mesa_components_in_format(format) <= 0) { 9998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 10008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!pixels) 10048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 10078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 10088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texObj || is_proxy_target(target)) { 10098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 10148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage) { 10158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* invalid mipmap level, not an error */ 10168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) { 10208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* no image data, not an error */ 10218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->NewState & _NEW_PIXEL) 10258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_update_state(ctx); 10268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { 10288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convert texture image to GL_RGBA, GL_FLOAT */ 10298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width = texImage->Width; 10308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint height = texImage->Height; 10318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint depth = texImage->Depth; 10328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 10338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *tmpImage, *convImage; 10348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); 10358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!tmpImage) { 10368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); 10378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); 10408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!convImage) { 10418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 10428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); 10438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 10448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < depth; img++) { 10478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint convWidth, convHeight; 10488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convert texture data to GLfloat/GL_RGBA */ 10508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < height; row++) { 10518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan texels[1 << MAX_TEXTURE_LEVELS][4]; 10528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint col; 10538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLfloat *dst = tmpImage + row * width * 4; 10548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (col = 0; col < width; col++) { 10558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*texImage->FetchTexel)(ctx, texObj, texImage, col, row, img, 10568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texels[col]); 10578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst, 10598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_RGBA, CHAN_TYPE, texels, 10608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, 10618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, 10628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GL_FALSE); 1063289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 10648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convWidth = width; 10668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convHeight = height; 10678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* convolve */ 10698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 10708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution1DEnabled) { 10718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); 10728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1073289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 10748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 10758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Pixel.Convolution2DEnabled) { 10768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, 10778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 10788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else if (ctx->Pixel.Separable2DEnabled) { 10808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, 10818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul tmpImage, convImage); 10828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1083289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 10848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* pack convolved image */ 10868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < convHeight; row++) { 10878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLfloat *src = convImage + row * convWidth * 4; 10888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels, 10898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul convWidth, convHeight, 10908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, img, row, 0); 10918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_pack_float_rgba_span(ctx, convWidth, 10928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (const GLfloat(*)[4]) src, 10938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, dest, &ctx->Pack, 10948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS); 1095289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 10968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 10978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(tmpImage); 10998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(convImage); 1100289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 11018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul else { 11028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* no convolution */ 11038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint width = texImage->Width; 11048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint height = texImage->Height; 11058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint depth = texImage->Depth; 11068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 11078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < depth; img++) { 11088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < height; row++) { 11098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* compute destination address in client memory */ 11108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, 11118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, format, type, img, row, 0); 11128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul assert(dest); 11138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul { 11158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* general case: convert row to RGBA format */ 11168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan rgba[MAX_WIDTH][4]; 11178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint col; 11188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (col = 0; col < width; col++) { 11198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*texImage->FetchTexel)(ctx, texObj, texImage, 11208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul img, row, col, rgba[col]); 11218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 11228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_pack_rgba_span( ctx, width, (const GLchan (*)[4])rgba, 11248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, dest, &ctx->Pack, 11258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ctx->_ImageTransferState ); 11268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* format */ 11278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* row */ 11288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* img */ 11298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* convolution */ 1130289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul} 1131289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1132289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 11338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1134289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 1135c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 1136c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 1137fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 113843911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 1139fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 1140fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 1141c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1142ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1143fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1144cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1145c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 11468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1147f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 11488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 1149f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 11500293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 11510293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1152f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1153aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1154f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 1, postConvWidth, 1, 1, border)) { 11558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1156c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1157c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1158f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 11598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 11608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 11610293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 11620293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1163021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 11640293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 11650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 11660293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 11670293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 11680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 11690293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 11700293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 11718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 11720293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 11730293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1174c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1175f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 1176c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 11779499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 11789499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1179fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 11808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage1D); 1181c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 11828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 11838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, format, type, pixels, 11848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1185c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1186c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 11878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, 1, 1, format); 11888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 11898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 11908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, 11918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 11928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 11938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 11940293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1195c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1196c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1197f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1198f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1199f378ab825c0c74aab263e7dec30194eead22c288Brian Paul texImage->LuminanceBits || texImage->IntensityBits); 1200f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1201f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 12020293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1203a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1204a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1205c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 120638d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 1207c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 120838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 12098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, 1, 12108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 12118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 12128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 121338d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 121438d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 12158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 121638d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 121738d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1218aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 12198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1220f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 1221c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1222c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1223c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1224c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 1225c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1226c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1227c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1228c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1229c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1230c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1231fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 123243911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 1233fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 1234fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1235fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1236c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1237ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1238fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1239cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1240c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 12418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); 1242f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 12438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 1244a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 1245fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1246fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 12478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 1248f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 12490293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 12500293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1251f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1252aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1253f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 2, postConvWidth, postConvHeight, 1254f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 1, border)) { 12558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1256c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1257c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1258f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 125935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 1260fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 12610293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 12620293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1263021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 1264fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul set_tex_image(texObj, target, level, texImage); 12650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 12660293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 12670293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 12680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 12690293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 12700293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 12718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 12720293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 12730293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1274c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1275f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 1276c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 12779499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 12789499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1279fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 12808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage2D); 1281c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 12828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 12838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, format, type, pixels, 12848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1285c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1286c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 12878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, 1, format); 12888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 12898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 12908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, 12918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 12928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 12938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 12940293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1295afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1296afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1297f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1298f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1299f378ab825c0c74aab263e7dec30194eead22c288Brian Paul texImage->LuminanceBits || texImage->IntensityBits); 1300f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1301f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 13020293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1303a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1304a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1305afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 130638d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_2D) { 1307afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 130838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 13098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, 2, 13108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, postConvHeight, 1, border); 13118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 13128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 131338d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 13148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, format, type, 13158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, postConvHeight, 1, border); 131638d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 131738d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1318aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 13198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1320f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 1321afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1322afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1323afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1324afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 1325afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 1326afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1327afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1328afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1329afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1330afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1331afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 1332afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 1333afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 1334afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1335fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 133643911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 1337fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1338fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 1339fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1340afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1341fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1342cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1343afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 13448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_3D) { 1345f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 13460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 13470293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1348289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1349aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1350aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul format, type, 3, width, height, depth, border)) { 13518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1352afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1353afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1354f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 13558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 13568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 13570293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 13580293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1359021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 13600293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 13610293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 13620293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 13630293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 13640293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 13650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 13660293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 13670293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul FREE(texImage->Data); 13680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1369afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1370f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 1371afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 13729499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 13739499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1374fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 13758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage3D); 1376c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 13778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 13788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 13798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 13808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1381afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1382afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 13838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, depth, format); 13848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 13858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 13868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 13878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 13888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 13898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 13900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1391afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1392afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1393f378ab825c0c74aab263e7dec30194eead22c288Brian Paul /* one of these has to be non-zero! */ 1394f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || 1395f378ab825c0c74aab263e7dec30194eead22c288Brian Paul texImage->LuminanceBits || texImage->IntensityBits); 1396f378ab825c0c74aab263e7dec30194eead22c288Brian Paul ASSERT(texImage->FetchTexel); 1397f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 13980293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1399a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1400a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1401afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 140238d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 1403afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 140438d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 140538d3f3d660225150715bc06f6b33e394ba803299Brian Paul format, type, 3, width, height, depth, border); 14068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 14078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 140838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 140938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 141038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 141138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 141238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1413aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1414f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1415f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 1416afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1417afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1418afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1419afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 1420c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1421afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1422afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1423afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1424afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1425afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1426663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paulvoid 142743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 1428663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1429663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 1430663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 1431663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 143243911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 1433663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 1434663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 1435663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1436663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1437afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1438fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1439fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 1440fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 1441fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1442fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1443afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1444ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1445fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 14460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 14470293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 14480293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1449a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul 14508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1451afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1452c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 1453a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, 1, 1, format, type)) { 1454f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1455afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1456afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 14570293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 14588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 14598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 14600293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1461afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1462c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || !pixels) 1463c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1464afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 14659499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 14669499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1467afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 14688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage1D); 14698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 14708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, &ctx->Unpack, 14718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 1472afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1473afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1475fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1476fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 1477fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 1478fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 1479fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1480fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1481afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1482ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1483fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 14840293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 14850293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 14860293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1487a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul 14888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); 1489afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1490c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1491a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, postConvHeight, 1, format, type)) { 1492f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1493afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1494afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 14950293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 149635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 14978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 14980293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1499afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1500c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || !pixels) 1501c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1502afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15039499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 15049499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1505fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 15068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage2D); 15078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 15088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, format, type, pixels, 15098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1510c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1511afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1514fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1515fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 1516fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1517fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1518fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1519fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1520afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1521fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 15220293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 15230293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 15240293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1525afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1526c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 1527c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 1528f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1529afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1530afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15310293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 15328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 15338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 15340293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1535afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1536c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || height == 0 || !pixels) 1537c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15399499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 15409499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1541fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 15428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage3D); 15438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 15448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 15458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 15468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 15478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage ); 1548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1549afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1551afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1552afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 1553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Read an RGBA image from the frame buffer. 1554a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul * This is used by glCopyTex[Sub]Image[12]D(). 1555afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input: ctx - the context 1556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * x, y - lower left corner 1557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * width, height - size of region to read 1558699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul * Return: pointer to block of GL_RGBA, GLchan data. 1559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1560699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paulstatic GLchan * 1561c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulread_color_image( GLcontext *ctx, GLint x, GLint y, 1562c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLsizei width, GLsizei height ) 1563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1564c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint stride, i; 1565699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image, *dst; 1566afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1567699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan)); 1568c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!image) 1569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return NULL; 1570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1571afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Select buffer to read from */ 1572cea0e8e6700e871bb9bcb334cb75fbfbfcdfd702Brian Paul (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 1573cea0e8e6700e871bb9bcb334cb75fbfbfcdfd702Brian Paul ctx->Pixel.DriverReadBuffer ); 1574afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1575c34cea7de54525a337c904cf22fc026b7ca31578Brian Paul RENDER_START(ctx); 1576c34cea7de54525a337c904cf22fc026b7ca31578Brian Paul 1577c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul dst = image; 1578699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul stride = width * 4; 1579c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul for (i = 0; i < height; i++) { 15803f02f90f943a996d88abc20f74503afbb56a4c98Brian Paul gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i, 1581699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul (GLchan (*)[4]) dst ); 1582c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul dst += stride; 1583c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1584afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1585c34cea7de54525a337c904cf22fc026b7ca31578Brian Paul RENDER_FINISH(ctx); 1586c34cea7de54525a337c904cf22fc026b7ca31578Brian Paul 1587cea0e8e6700e871bb9bcb334cb75fbfbfcdfd702Brian Paul /* Read from draw buffer (the default) */ 1588cea0e8e6700e871bb9bcb334cb75fbfbfcdfd702Brian Paul (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 1589cea0e8e6700e871bb9bcb334cb75fbfbfcdfd702Brian Paul ctx->Color.DriverDrawBuffer ); 1590afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return image; 1592afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1594afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1595afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1596fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1597fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 1598fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 1599fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 1600fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 1601afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1602ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1603fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1604cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16069499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 16079499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1608fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 16098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1610ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1611ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 1612ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, 1, border)) 1613ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1614ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 16155e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage1D 1616f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level, 1617a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul internalFormat, x, y, width, border)) { 16187dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul struct gl_pixelstore_attrib unpackSave; 16197dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 16207dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* get image from framebuffer */ 1621699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image = read_color_image( ctx, x, y, width, 1 ); 1622c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!image) { 1623c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" ); 1624c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1625c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 16267dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 16277dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* call glTexImage1D to redefine the texture */ 16287dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul unpackSave = ctx->Unpack; 16297dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = _mesa_native_packing; 16303ab6bbe6135da26dfe9a9ba880386fdc98f6580aBrian Paul (*ctx->Exec->TexImage1D)( target, level, internalFormat, width, 1631f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul border, GL_RGBA, GL_UNSIGNED_BYTE, image ); 16327dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = unpackSave; 16337dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 1634c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul FREE(image); 1635afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1638afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1639afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1640fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1641fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 1642fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 1643fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 1644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1645ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1646fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1647cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16499499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 16509499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1651fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 16528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); 1653ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1654ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 1655ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight, border)) 1656ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1657ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 165814940c4ffe066a8b85bc14274c19ad3d8e334d61Keith Whitwell if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage2D 1659f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level, 1660a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul internalFormat, x, y, width, height, border)) { 16617dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul struct gl_pixelstore_attrib unpackSave; 16627dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 16637dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* get image from framebuffer */ 1664699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image = read_color_image( ctx, x, y, width, height ); 1665c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!image) { 1666c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" ); 1667c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1668c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 16697dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 16707dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* call glTexImage2D to redefine the texture */ 16717dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul unpackSave = ctx->Unpack; 16727dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = _mesa_native_packing; 16733ab6bbe6135da26dfe9a9ba880386fdc98f6580aBrian Paul (ctx->Exec->TexImage2D)( target, level, internalFormat, width, 1674f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul height, border, GL_RGBA, GL_UNSIGNED_BYTE, image ); 16757dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = unpackSave; 1676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16777dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul FREE(image); 1678c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1681afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1682afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1683fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1684fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 1685fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 1686afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1687ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1688fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1689cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1690afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16919499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 16929499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1693fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 16948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1695ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1696ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 1, target, level, 1697ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul xoffset, 0, 0, postConvWidth, 1)) 1698ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1699ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 170014940c4ffe066a8b85bc14274c19ad3d8e334d61Keith Whitwell if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage1D 1701f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, 1702f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul xoffset, x, y, width)) { 1703c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit; 1704c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 17057dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul struct gl_pixelstore_attrib unpackSave; 1706699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image; 17077dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 1708c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1709a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = texUnit->Current1D->Image[level]; 1710c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul assert(teximage); 17117dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 17127dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* get image from frame buffer */ 17137dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul image = read_color_image(ctx, x, y, width, 1); 17147dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul if (!image) { 1715ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D" ); 17167dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul return; 1717afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 17185e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 17197dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* now call glTexSubImage1D to do the real work */ 17207dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul unpackSave = ctx->Unpack; 17217dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = _mesa_native_packing; 17227dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul _mesa_TexSubImage1D(target, level, xoffset, width, 17237dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul GL_RGBA, GL_UNSIGNED_BYTE, image); 17247dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = unpackSave; 17257dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 17267dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul FREE(image); 1727afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1729afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1730afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1731afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1732fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1733fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 1734fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 1735fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 1736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1737ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1738fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1739cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17419499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 17429499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1743fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 17448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); 1745ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1746ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1747ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight)) 1748ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1749ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 175014940c4ffe066a8b85bc14274c19ad3d8e334d61Keith Whitwell if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage2D 1751f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 1752f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul xoffset, yoffset, x, y, width, height )) { 1753c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit; 1754c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 17557dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul struct gl_pixelstore_attrib unpackSave; 1756699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image; 17577dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 1758c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1759a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = texUnit->Current2D->Image[level]; 1760c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul assert(teximage); 17617dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 17627dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* get image from frame buffer */ 17637dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul image = read_color_image(ctx, x, y, width, height); 17647dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul if (!image) { 17657dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); 17667dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul return; 1767afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 17687dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 17697dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* now call glTexSubImage2D to do the real work */ 17707dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul unpackSave = ctx->Unpack; 17717dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = _mesa_native_packing; 17727dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul _mesa_TexSubImage2D(target, level, xoffset, yoffset, width, height, 17737dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul GL_RGBA, GL_UNSIGNED_BYTE, image); 17747dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = unpackSave; 17755e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 17767dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul FREE(image); 1777afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1778afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1782fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1783fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 1784fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1785fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 1786afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1787ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1788fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1789cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1790afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17919499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul if (ctx->NewState & _NEW_PIXEL) 17929499e017b7e05411a32b3e4fa94885eaec0d7277Brian Paul gl_update_state(ctx); 1793fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 17948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); 1795ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1796ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, 1797ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul zoffset, postConvWidth, postConvHeight)) 1798ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 1799ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 180014940c4ffe066a8b85bc14274c19ad3d8e334d61Keith Whitwell if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage3D 1801f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 18020293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul xoffset, yoffset, zoffset, x, y, width, height )) { 18030293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 18040293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *teximage; 18057dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul struct gl_pixelstore_attrib unpackSave; 1806699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul GLchan *image; 18077dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 18080293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1809a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = texUnit->Current3D->Image[level]; 18100293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(teximage); 18117dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 18127dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* get image from frame buffer */ 18137dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul image = read_color_image(ctx, x, y, width, height); 18147dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul if (!image) { 18157dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); 18167dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul return; 1817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 18187dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 18197dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul /* now call glTexSubImage2D to do the real work */ 18207dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul unpackSave = ctx->Unpack; 18217dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = _mesa_native_packing; 18227dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul _mesa_TexSubImage3D(target, level, xoffset, yoffset, zoffset, 18237dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); 18247dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul ctx->Unpack = unpackSave; 18255e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 18267dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul FREE(image); 1827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 18291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 18301207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 18311207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 18321207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 18331207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 1834aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 18351207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 18361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 18371207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 1838aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 1839cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1840aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1841289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 1842289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 1843289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 1844289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 1845289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 1846289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 1847289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 1848289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); 1849289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 1850289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 1851289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 1852289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 1853289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 1854289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1855aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 1856aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 1857aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 1858aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 1859aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1860aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1861aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border)) { 1862aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 1863aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1864aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1865aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 18668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 18678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1868aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1869aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 1870aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 1871aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 1872aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 1873aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB"); 1874aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 1875aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1876aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1877aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 1878aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 1879aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 1880aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1881aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 18828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 18838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 18848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 18858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, border, 18868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul imageSize, data, 18878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 18888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 1889aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1890aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1891aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 1892a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1893a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1894aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1895aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 1896aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 189738d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 189838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border); 18998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 19008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 190138d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 190238d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 190338d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 190438d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 190538d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1906aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1907f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1908f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 1909aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1910aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1911aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1912aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 1913aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" ); 1914aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 1915aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 19161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 19171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 19181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 19191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 19201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 1921aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 19221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 19231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 19241207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 1925aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 1926cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1927aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1928289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 1929289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 1930289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 1931289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 1932289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 1933289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 1934289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 1935289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); 1936289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 1937289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 1938289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 1939289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 1940289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 1941289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 19428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 1943a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 19449540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 19459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 1946aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 1947aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 1948aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 1949aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1950aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1951aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, height, 1, border)) { 1952aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 1953aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1954aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1955aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 19568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 19578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1958aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1959aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 1960aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 1961aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 1962aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 1963aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); 1964aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 1965aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1966aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1967aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 1968aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 1969aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 1970aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1971aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 19728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 19738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 19748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 19758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, height, 19768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 19778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 19788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 1979aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1980aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 1981aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 1982a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1983a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1984aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 1985aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_2D) { 1986aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 198738d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 198838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 2, width, height, 1, border); 19898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 19908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 199138d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 199238d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 199338d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 199438d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 199538d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1996aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1997f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1998f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 1999aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2000aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2001aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2002aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 2003aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" ); 2004aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2005aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 20061207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 20071207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20081207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20091207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 20101207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 2011aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 20121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 20131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 20141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2015aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2016cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2017aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2018289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2019289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2020289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2021289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2022289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2023289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2024289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 2025289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); 2026289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2027289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2028289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2029289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2030289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2031289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 20329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 2033aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2034aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2035aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2036aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2037aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2038aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, height, depth, border)) { 2039aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2040aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2041aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2042aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 20438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 20448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2045aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2046aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2047aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2048aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2049aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2050aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); 2051aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2052aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2053aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2054aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2055aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul FREE(texImage->Data); 2056aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2057aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2058aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 20598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 20608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 20618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 20628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, 20638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 20648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 20658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 20668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2067aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2068aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2069aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2070a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2071a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2072aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2073aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 2074aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 207538d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 207638d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 1, width, height, depth, border); 20778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 20788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 207938d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 208038d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 208138d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 208238d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 208338d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2084aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2085f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 2086f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 2087aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2088aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2089aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2090aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 2091aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" ); 2092aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2093aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 20941207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 20951207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20961207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 20971207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 20981207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 20991207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei width, GLenum format, 21001207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 21011207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 21029540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul GET_CURRENT_CONTEXT(ctx); 21039540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 21049540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 21059540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 21069540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21079540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 21089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, 1, 1, format, GL_NONE)) { 21099540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 21109540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21119540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21129540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21139540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 21148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 21159540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 21169540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21179540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || !data) 21189540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 21199540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21209540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage1D) { 21218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 21228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, width, 21238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 21248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 21259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21261207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 21271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21281207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 21301207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 21311207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 21321207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 21331207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 21341207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 21359540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul GET_CURRENT_CONTEXT(ctx); 21369540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 21379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 21389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 21399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21409540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 21419540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, 1, format, GL_NONE)) { 21429540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 21439540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21449540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21469540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 21478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 21489540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 21499540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21509540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || !data) 21519540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 21529540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21539540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage2D) { 21548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 21558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, width, height, 21568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 21578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 21589540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 21601207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21611207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21621207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 21631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 21641207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 21651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 21661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 21671207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 21689540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul GET_CURRENT_CONTEXT(ctx); 21699540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 21709540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 21719540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 21729540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21739540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 21749540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, depth, format, GL_NONE)) { 21759540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 21769540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21789540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21799540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 21808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 21819540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 21829540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21839540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || depth == 0 || !data) 21849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 21859540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 21869540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage3D) { 21878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 21888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 21898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 21908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 21918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 21929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 21931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 21941207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21951207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 21961207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 21979540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 21981207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 21999540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul GET_CURRENT_CONTEXT(ctx); 22008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 22019540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul const struct gl_texture_object *texObj; 22029540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 22039540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 2204cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 22059540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22069540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 22079540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" ); 22089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 22099540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22109540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (is_proxy_target(target)) { 22128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 22138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 22149540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22159540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 22178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 22188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 22198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 22209540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage) { 22219540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul /* invalid mipmap level */ 22229540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 22239540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 22249540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage->IsCompressed) { 22279540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); 22289540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 22299540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22309540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22319540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!img) 22329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 22339540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 22348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 22358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.GetCompressedTexImage); 22369540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, 22379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texImage); 22389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 22391207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 2240