teximage.c revision c5b995066020191982b2315fc45d05e068eee761
1c5b995066020191982b2315fc45d05e068eee761Brian Paul/* $Id: teximage.c,v 1.115 2002/09/21 16:51:25 brianp Exp $ */ 2afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 4afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library 562c36a2ff39d775c1f1bc377b9ddbc69e2340799Brian Paul * Version: 4.1 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul * Copyright (C) 1999-2002 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" 392c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes#include "texformat.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 41afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul#include "texstore.h" 435e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 44afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#endif 45afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * NOTES: 49afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * 50699bc7b73d2fede77d3290f66c1ec355afd0373eBrian Paul * Mesa's native texture datatype is GLchan. Native formats are 51c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, 52c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * and GL_COLOR_INDEX. 53c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Device drivers are free to implement any internal format they want. 54afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 55afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 56afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul#if 0 584e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paulstatic void PrintTexture(GLcontext *ctx, const struct gl_texture_image *img) 594827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul{ 60f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#if CHAN_TYPE == GL_FLOAT 61f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul _mesa_problem(NULL, "PrintTexture doesn't support float channels"); 62f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#else 63b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul GLuint i, j, c; 64b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul const GLchan *data = (const GLchan *) img->Data; 65b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 66b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul if (!data) { 674e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "No texture data\n"); 68b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul return; 69b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 70b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 71b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul switch (img->Format) { 72b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_ALPHA: 73b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_LUMINANCE: 74b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_INTENSITY: 75b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_COLOR_INDEX: 76b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 1; 77b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 78b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_LUMINANCE_ALPHA: 79b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 2; 80b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 81b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_RGB: 82b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 3; 83b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 84b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_RGBA: 85b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 4; 86b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 87b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul default: 88b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_problem(NULL, "error in PrintTexture\n"); 89b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul return; 90b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 91b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 92b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul for (i = 0; i < img->Height; i++) { 93b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul for (j = 0; j < img->Width; j++) { 94b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul if (c==1) 954e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "%02x ", data[0]); 96b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==2) 974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "%02x%02x ", data[0], data[1]); 98b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==3) 994e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "%02x%02x%02x ", data[0], data[1], data[2]); 100b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==4) 1014e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]); 102b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul data += c; 103b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 1044e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_printf(ctx, "\n"); 105b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 106f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif 1074827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul} 1084827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul#endif 1094827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1104827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1114827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 112f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Compute log base 2 of n. 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * If n isn't an exact power of two return -1. 11538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * If n < 0 return -1. 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 117fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 118fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 12338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (n < 0) { 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Given an internal texture format enum or 1, 2, 3, 4 return the 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, 144c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. 145c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return -1 if invalid enum. 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 147b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 148aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul_mesa_base_tex_format( GLcontext *ctx, GLint format ) 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 15038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes /* 15138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * Ask the driver for the base format, if it doesn't 15238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * know, it will return -1; 15338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 154289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ctx->Driver.BaseCompressedTexFormat) { 155289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format); 156289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul if (ifmt >= 0) { 157289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return ifmt; 158289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 159289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg switch (format) { 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 181afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 182afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 186afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 187afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 189afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 190afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 191afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 194afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 196afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 197afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 198afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 199afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 200afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 201afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 202afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 203afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 204afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 208afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 209afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX: 210afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX1_EXT: 211afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX2_EXT: 212afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX4_EXT: 213afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX8_EXT: 214afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX12_EXT: 215afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_COLOR_INDEX16_EXT: 216afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_COLOR_INDEX; 217f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT: 218f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT16_SGIX: 219f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT24_SGIX: 220f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_DEPTH_COMPONENT32_SGIX: 221f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (ctx->Extensions.SGIX_depth_texture) 222f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 223f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else 224f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return -1; 225c5b995066020191982b2315fc45d05e068eee761Brian Paul case GL_YCBCR_MESA: 226c5b995066020191982b2315fc45d05e068eee761Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) 227c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_YCBCR_MESA; 228c5b995066020191982b2315fc45d05e068eee761Brian Paul else 229c5b995066020191982b2315fc45d05e068eee761Brian Paul return -1; 230afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg default: 231afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; /* error */ 232afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 233afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 234afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 235afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 236f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul/* 237f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul * Test if the given image format is a color/rgba format. That is, 238f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul * not color index, depth, stencil, etc. 239f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul */ 240f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 241f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulis_color_format(GLenum format) 242f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 243f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul switch (format) { 244f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA: 245f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA4: 246f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA8: 247f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA12: 248f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA16: 249f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 1: 250f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE: 251f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4: 252f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8: 253f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12: 254f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16: 255f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 2: 256f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE_ALPHA: 257f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4_ALPHA4: 258f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE6_ALPHA2: 259f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8_ALPHA8: 260f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA4: 261f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA12: 262f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16_ALPHA16: 263f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY: 264f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY4: 265f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY8: 266f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY12: 267f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY16: 268f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 3: 269f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB: 270f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_R3_G3_B2: 271f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB4: 272f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5: 273f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB8: 274f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10: 275f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB12: 276f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB16: 277f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 4: 278f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA: 279f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA2: 280f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA4: 281f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5_A1: 282f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA8: 283f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10_A2: 284f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA12: 285f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA16: 286f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 287c5b995066020191982b2315fc45d05e068eee761Brian Paul case GL_YCBCR_MESA: /* not considered to be RGB */ 288f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 289f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 290f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 291f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 292f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 293f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 294f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 295f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulis_index_format(GLenum format) 296f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 297f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul switch (format) { 298f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX: 299f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX1_EXT: 300f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX2_EXT: 301f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX4_EXT: 302f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX8_EXT: 303f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX12_EXT: 304f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX16_EXT: 305f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 306f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 307f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 308f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 309f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 310f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 311afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 312afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 313aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE 314aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul * otherwise. 315aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 316aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paulstatic GLboolean 317289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paulis_compressed_format(GLcontext *ctx, GLenum internalFormat) 318aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 319e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (ctx->Driver.BaseCompressedTexFormat) { 320e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul GLint b = (*ctx->Driver.BaseCompressedTexFormat)(ctx, internalFormat); 321e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (b > 0) 322e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 323e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul else 324e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_FALSE; 325e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 326e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_FALSE; 327aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 328aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 329aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 330afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 331afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 3328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 3338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 3348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 335afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 3363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 3373893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 3383893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 3393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 340fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 341fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 342fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 343fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 3449228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_1D: 345fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 3469228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_3D: 347fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->Image[level] = texImage; 348fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 349fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 350413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul tObj->Image[level] = texImage; 351fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 352fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 353fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegX[level] = texImage; 354fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 355fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 356fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosY[level] = texImage; 357fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 358fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 359fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegY[level] = texImage; 360fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 361fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 362fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->PosZ[level] = texImage; 363fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 364fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 365fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul tObj->NegZ[level] = texImage; 366fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 3678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 3688afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 3698afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul tObj->Image[level] = texImage; 3708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return; 371fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 3723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(NULL, "bad target in _mesa_set_tex_image()"); 373fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 374fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 375fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 376fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 377fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 3788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 37977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul/* 38077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul * Return new gl_texture_image struct with all fields initialized to zero. 38177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 38277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 383021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_alloc_texture_image( void ) 38477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 38577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 38677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 38777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 38877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 38977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 39077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 391021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul_mesa_free_texture_image( struct gl_texture_image *teximage ) 39277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 39377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul if (teximage->Data) { 394aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE( teximage->Data ); 39577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul teximage->Data = NULL; 39677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul } 39777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul FREE( teximage ); 39877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 39977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 40077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 401fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul/* 4028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Return GL_TRUE if the target is a proxy target. 403aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 4048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLboolean 4058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulis_proxy_target(GLenum target) 406aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 4078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 4088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 4098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 4108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); 411aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 412aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 413aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 414aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul/* 41535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * Given a texture unit and a texture target, return the corresponding 41635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul * texture object. 41735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 41835d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 41901e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 42035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 42135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 42235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 42335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 424a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D; 42535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 42635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy1D; 42735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 428a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D; 42935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 43035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy2D; 43135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 432a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D; 43335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 43435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy3D; 43535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 43635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 43735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 43835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 43935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 44035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 4415ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 442a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 44335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? texUnit->CurrentCubeMap : NULL; 44435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 445a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 44635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? ctx->Texture.ProxyCubeMap : NULL; 4478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 4488afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 4498afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ? texUnit->CurrentRect : NULL; 4508afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 4518afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 4528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ? ctx->Texture.ProxyRect : NULL; 45335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 45408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 45535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 45635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 45735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 45835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 45935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 46035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul/* 461fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * Return the texture image struct which corresponds to target and level 462fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul * for the given texture unit. 463fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 464fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 465fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 466fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level) 467fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 468fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texUnit); 469cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 470fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 471fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_1D: 472a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D->Image[level]; 473fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_1D: 474fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy1D->Image[level]; 475fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 476a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D->Image[level]; 477fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_2D: 478fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy2D->Image[level]; 479fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_3D: 480a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D->Image[level]; 481fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_3D: 482fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return ctx->Texture.Proxy3D->Image[level]; 483fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 484a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 485413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return texUnit->CurrentCubeMap->Image[level]; 486fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 487fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 488fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 489a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 490fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegX[level]; 491fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 492fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 493fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 494a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 495fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosY[level]; 496fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 497fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 498fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 499a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 500fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegY[level]; 501fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 502fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 503fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 504a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 505fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->PosZ[level]; 506fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 507fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 508fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 509a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 510fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return texUnit->CurrentCubeMap->NegZ[level]; 511fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 512fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 513fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 514a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 515413d6a21f849a689b5c83ea04395856b44fc65a8Brian Paul return ctx->Texture.ProxyCubeMap->Image[level]; 516fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 517fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 5188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 5198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (ctx->Extensions.NV_texture_rectangle) { 5208afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 5218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return texUnit->CurrentRect->Image[level]; 5228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 5238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 5248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return NULL; 5258afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 5268afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 5278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (ctx->Extensions.NV_texture_rectangle) { 5288afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 5298afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Texture.ProxyRect->Image[level]; 5308afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 5318afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 5328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return NULL; 5338afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 534fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 53508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(ctx, "bad target in _mesa_select_tex_image()"); 536fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 537fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 538fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 539fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 540fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 541fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 54262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 543f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 5468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 5498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 5518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 5528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 5538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 554afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 555a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 56265d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 566afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 567afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 568afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 571afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 5748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 5758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 5768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 5778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 5788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 5798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 5808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 5818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 5828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 5838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 584afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 585afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 586afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 587afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 588a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 5898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 59262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 594afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 595afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 596afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 597f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 5989c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 5999c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 600f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 601f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 602f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 6039c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 6049c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 605f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 6069c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 6079c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 6089c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Format = 0; 60916a8e986cebae6560d00992b6b9f54549e1d03c6Gareth Hughes img->IntFormat = 0; 6109c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 6119c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 6129c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 6139c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 6149c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 6159c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 6169c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 6179c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 6189c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 6199c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 6209c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 6212c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes img->TexFormat = &_mesa_null_texformat; 6222c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes img->FetchTexel = NULL; 6239c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IsCompressed = 0; 6249c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->CompressedSize = 0; 6259c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 6269c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 6279c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 6286628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul/* 6296628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 6306628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 6313893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 6328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul_mesa_init_teximage_fields(GLcontext *ctx, GLenum target, 6333893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 6343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 6353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint border, GLenum internalFormat) 6366628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 6376628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 63838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes img->Format = _mesa_base_tex_format( ctx, internalFormat ); 639e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(img->Format > 0); 64016a8e986cebae6560d00992b6b9f54549e1d03c6Gareth Hughes img->IntFormat = internalFormat; 6416628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 6426628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 6436628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 6446628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 6456628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->WidthLog2 = logbase2(width - 2 * border); 6466628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (height == 1) /* 1-D texture */ 6476628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 6486628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 6496628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = logbase2(height - 2 * border); 6506628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (depth == 1) /* 2-D texture */ 6516628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 6526628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 6536628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = logbase2(depth - 2 * border); 6546628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width2 = 1 << img->WidthLog2; 6556628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height2 = 1 << img->HeightLog2; 6566628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth2 = 1 << img->DepthLog2; 6576628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 6586628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->IsCompressed = is_compressed_format(ctx, internalFormat); 6598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 6608afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 6618afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 6628afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 6638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 6648afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 6658afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 6668afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 6678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 6688afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 6698afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 6708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 6716628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 6726628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 6736628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 6749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 6759c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul/* 676c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexImage[123]D() parameters for errors. 677afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input: 678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * dimensions - must be 1 or 2 or 3 679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 681c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 682c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paultexture_error_check( GLcontext *ctx, GLenum target, 683c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 684c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 6855b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLuint dimensions, 686c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 687c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 688afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 689afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLboolean isProxy; 690afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint iformat; 691cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0, maxTextureSize; 692afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 693afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions == 1) { 6948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_PROXY_TEXTURE_1D) { 6958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_TRUE; 6968afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 6978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_1D) { 6988afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_FALSE; 6998afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7008afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 70108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 704cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 705afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 706afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 7078afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 7088afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_TRUE; 709cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 7108afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7118afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_2D) { 7128afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_FALSE; 7138afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 7148afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7158afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 7168afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 7178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 7188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7208afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_TRUE; 721cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 7228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 7248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 7258afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 7268afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 7278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7288afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7298afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_FALSE; 7308afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 7318afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV) { 7338afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 7348afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 7358afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7368afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7378afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_TRUE; 7388afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = 1; 7398afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 7418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 7428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 7438afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7448afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_FALSE; 7468afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = 1; 7478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7488afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 7498afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 7508afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7518afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 752afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 753afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 7548afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_PROXY_TEXTURE_3D) { 7558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_TRUE; 7568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7578afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_3D) { 7588afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul isProxy = GL_FALSE; 7598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7608afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 76108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 764cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 765afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 76708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 770afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 771cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 772cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxTextureSize = 1 << (maxLevels - 1); 773cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 774afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Border */ 7759fd2b0a698163b397b0a17493e52b27273e51b63Brian Paul if (border != 0 && border != 1) { 776afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 7774e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 7784e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(border=%d)", dimensions, border); 779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 7828afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if ((target == GL_TEXTURE_RECTANGLE_NV || 7838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0) { 7848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 786afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Width */ 7888afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV || 7898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) { 7908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (width < 1 || width > ctx->Const.MaxTextureRectSize) { 7918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!isProxy) { 7924e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 7934e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(width=%d)", dimensions, width); 7948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 7968afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7988afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (width < 2 * border || width > 2 + maxTextureSize 799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( width - 2 * border ) < 0) { 800afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 8014e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(width=%d)", dimensions, width); 803afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 804afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 805afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 806afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 807afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Height */ 8088afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV || 8098afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) { 8108afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (height < 1 || height > ctx->Const.MaxTextureRectSize) { 8118afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!isProxy) { 8124e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8134e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(height=%d)", dimensions, height); 8148afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8158afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 8168afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (dimensions >= 2) { 819cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (height < 2 * border || height > 2 + maxTextureSize 820afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( height - 2 * border ) < 0) { 821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 8224e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8234e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(height=%d)", dimensions, height); 824afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 825c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 826afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 829ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 830ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 831ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 832ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 833ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (!isProxy) { 83408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); 835ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 836ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 837ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 838ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 839ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 840afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Depth */ 841afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (dimensions >= 3) { 842cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (depth < 2 * border || depth > 2 + maxTextureSize 843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg || logbase2( depth - 2 * border ) < 0) { 844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (!isProxy) { 8454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, 8464e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage3D(depth=%d)", depth ); 847afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 848afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 849afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 852afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Level */ 8538afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV || 8548afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) { 8558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (level != 0) { 8568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!isProxy) { 8574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8584e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage2D(level=%d)", level); 8598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8608afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 8618afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8628afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 8638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (level < 0 || level >= maxLevels) { 864c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 8654e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(level=%d)", dimensions, level); 867c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 869afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 870afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 8711f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul /* For cube map, width must equal height */ 8721f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 8731f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 8741f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul if (width != height) { 87508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); 8761f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul return GL_TRUE; 8771f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul } 8781f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul } 8791f57563b9dccfb6ce5026eaf5b7a418dc4dd52b9Brian Paul 880aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul iformat = _mesa_base_tex_format( ctx, internalFormat ); 881afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (iformat < 0) { 882c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 8834e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 8844e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(internalFormat=0x%x)", 8854e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul dimensions, internalFormat); 886c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 887afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 888afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 889afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 890e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(iformat > 0); 891e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 89238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!is_compressed_format( ctx, internalFormat ) && 89338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes !_mesa_is_legal_format_and_type( format, type )) { 89438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 89538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 89638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 89738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 8984e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 8994e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(format or type)", dimensions); 900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 90138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 902afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 904c5b995066020191982b2315fc45d05e068eee761Brian Paul if (format == GL_YCBCR_MESA || iformat == GL_YCBCR_MESA) { 905c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 906c5b995066020191982b2315fc45d05e068eee761Brian Paul if (format != GL_YCBCR_MESA || 907c5b995066020191982b2315fc45d05e068eee761Brian Paul iformat != GL_YCBCR_MESA || 908c5b995066020191982b2315fc45d05e068eee761Brian Paul (type != GL_UNSIGNED_SHORT_8_8_MESA && 909c5b995066020191982b2315fc45d05e068eee761Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA)) { 910c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 911c5b995066020191982b2315fc45d05e068eee761Brian Paul sprintf(message, 912c5b995066020191982b2315fc45d05e068eee761Brian Paul "glTexImage%d(format/type/internalFormat YCBCR mismatch", 913c5b995066020191982b2315fc45d05e068eee761Brian Paul dimensions); 914c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, message); 915c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 916c5b995066020191982b2315fc45d05e068eee761Brian Paul } 917c5b995066020191982b2315fc45d05e068eee761Brian Paul } 918c5b995066020191982b2315fc45d05e068eee761Brian Paul 919afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 920afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 921afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 922afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 923afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 924afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 925afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 926c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 927c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: 928c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * dimensions - must be 1 or 2 or 3 929c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 930afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 931c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 932fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 933c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 934c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 935c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 936c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 937afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 938afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 939c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *destTex; 940cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 941e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul GLboolean compressed; 942afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 943c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 944c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_1D) { 94508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 946c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 947afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 948cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 949c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 950c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 951a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 952fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 953fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 954fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 95508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 956fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 957fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 958fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 959fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 96008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 961c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 962afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 963cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D) 964cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 965cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else 966cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 967c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 968c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 969c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (target != GL_TEXTURE_3D) { 97008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 971c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 972afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 973cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 974c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 975c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 97608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 977c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 978c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 980cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 981cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 982cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 9834e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 984c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 985c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 987c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 9884e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 9894e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 990c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 991c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 992c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 9934e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 9944e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 995c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 996c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 997c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 9984e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(depth=%d)", dimensions, depth); 999c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1000c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1001afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1002f2718b0966f54049056e16e7cca08718341557b2Brian Paul destTex = _mesa_select_tex_image(ctx, texUnit, target, level); 1003f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1004c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 100508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); 1006c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1007c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1008afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1009c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 101008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); 1011c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1013c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 101408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); 1015c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1016c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1017c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1018c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 101908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); 1020c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1021afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1022c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 102308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); 1024c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1027c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1028c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 102908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1030c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1031c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 103238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 103308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1034c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1035c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1036afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1038e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul compressed = is_compressed_format(ctx, destTex->IntFormat); 1039e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1040e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (!compressed && !_mesa_is_legal_format_and_type(format, type)) { 10414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 10424e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(format or type)", dimensions); 104338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1044c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1045afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1046e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (compressed) { 10477b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (xoffset != -((GLint)destTex->Border)) { 1048e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1049e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glTexSubImage1/2/3D(xoffset != -border"); 1050e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1051e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 10527b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (dimensions > 1 && yoffset != -((GLint)destTex->Border)) { 1053e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1054e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glTexSubImage2/3D(yoffset != -border"); 1055e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1056e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 10577b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (dimensions > 2 && zoffset != -((GLint)destTex->Border)) { 1058e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1059e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glTexSubImage3D(zoffset != -border"); 1060e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1061e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1062e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1063e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1064c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1065c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1066afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1067afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1068afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 1069c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 1070c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Input: dimensions - must be 1 or 2 or 3 1071c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Return: GL_TRUE = an error was detected, GL_FALSE = no errors 1072afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1074fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 1075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1076c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1077afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1078c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint iformat; 1079cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0, maxTextureSize; 1080afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1081fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1082fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 108308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 1084fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1085fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1086cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 1087c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1088fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 10898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 10908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 10918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 10928afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 10938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 10948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 10958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 10968afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 10978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 109808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1099fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1100fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1101fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1102fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 110308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1104fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1105fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 11068afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_2D) 1107cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 11088afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) 11098afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = 1; 1110cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else 1111cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 1112c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1113c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1114cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 1115cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxTextureSize = 1 << (maxLevels - 1); 1116cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 1117c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Border */ 111838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (border != 0 && border != 1) { 11194e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 11204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexImage%dD(border)", dimensions); 1121c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1122c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1123c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1124c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Width */ 1125cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (width < 2 * border || width > 2 + maxTextureSize 1126c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( width - 2 * border ) < 0) { 11274e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 11284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexImage%dD(width=%d)", dimensions, width); 1129c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1130c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1131c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1132c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Height */ 1133c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions >= 2) { 1134cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (height < 2 * border || height > 2 + maxTextureSize 1135c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul || logbase2( height - 2 * border ) < 0) { 11364e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 11374e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexImage%dD(height=%d)", dimensions, height); 1138c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1139c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1140c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1141c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1142ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul /* For cube map, width must equal height */ 1143ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1144ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1145ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul if (width != height) { 114608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); 1147ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul return GL_TRUE; 1148ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1149ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1150ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul 1151c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Level */ 1152cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 11534e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 11544e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexImage%dD(level=%d)", dimensions, level); 1155c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1156c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1157c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1158cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul iformat = _mesa_base_tex_format(ctx, internalFormat); 1159c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (iformat < 0) { 11604e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 11614e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 1162c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1163c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1164c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1165c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1166c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1167c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1168c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1169c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1170c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1171fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 1172c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1173c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 11745b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLsizei width, GLsizei height ) 1175c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1176c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1177c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 1178cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 1179e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul GLboolean compressed; 1180c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1181fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1182fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 118308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 1184fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1185fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1186cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 1187c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1188fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1189a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 1190fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || 1191fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && 1192fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target != GL_TEXTURE_2D) { 119308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1194fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1195fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1196fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1197fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 119808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1199fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1200fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1201cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D) 1202cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 1203cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else 1204cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 1205c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1206fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 1207fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_3D) { 120808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 1209fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1210fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1211cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 1212c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1213c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1214cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 1215cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 1216cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 12174e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12184e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 1219c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1220c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1221c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1222c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 12234e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12244e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 1225c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1226c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1227c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1 && height < 0) { 12284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12294e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 1230c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1231c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1232c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1233a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = _mesa_select_tex_image(ctx, texUnit, target, level); 1234c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 12354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1236b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 1237b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 1238c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1239c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1240c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1241c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 12424e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12434e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 1244c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1245c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 124638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 12474e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12484e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 1249c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1250c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1251c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1252c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 12534e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12544e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 1255c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1256c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1257c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 125838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 12594e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12604e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 1261c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1262c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1263c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1264c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1265c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1266c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 12674e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12684e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 1269c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1270c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 127138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 12724e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 12734e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 1274c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1275c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1276c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1277c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1278e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul compressed = is_compressed_format(ctx, teximage->IntFormat); 1279e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (compressed) { 12807b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (xoffset != -((GLint)teximage->Border)) { 1281e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1282e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glCopyTexSubImage1/2/3D(xoffset != -border"); 1283e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1284e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 12857b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (dimensions > 1 && yoffset != -((GLint)teximage->Border)) { 1286e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1287e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glCopyTexSubImage2/3D(yoffset != -border"); 1288e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1289e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 12907b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz if (dimensions > 2 && zoffset != -((GLint)teximage->Border)) { 1291e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1292e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul "glCopyTexSubImage3D(zoffset != -border"); 1293e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1294e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1295e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1296e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1297c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1298c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1299c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1300c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1301c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1302c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 13038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulvoid 13048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 13058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum type, GLvoid *pixels ) 1306289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul{ 13078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 13088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_object *texObj; 130957aca2bf6e82cdab43575123530fce2ba54bf9c7Brian Paul const struct gl_texture_image *texImage; 1310cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 13112c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 13128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 13138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1314cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 1315cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 1316cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (!texObj || is_proxy_target(target)) { 1317cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 1318cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 1319cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 1320cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 1321cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D) { 1322cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 1323cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 1324cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else if (target == GL_TEXTURE_3D) { 1325cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 1326cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 13278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 13288afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul maxLevels = 1; 13298afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1330cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else { 1331cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 1332cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 1333cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 1334cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 1335cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 1336cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 133708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 13388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 1339289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 1340289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 134162c36a2ff39d775c1f1bc377b9ddbc69e2340799Brian Paul if (_mesa_sizeof_packed_type(type) <= 0) { 134208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 13438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 13448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 13458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1346f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (_mesa_components_in_format(format) <= 0 || 1347f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul format == GL_STENCIL_INDEX) { 134808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 13498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 13508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 13518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1352f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { 135308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 1354f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1355f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 1356f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) { 135708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 1358f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1359f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 1360c5b995066020191982b2315fc45d05e068eee761Brian Paul if (!ctx->Extensions.MESA_ycbcr_texture && format == GL_YCBCR_MESA) { 1361c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 1362c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1363c5b995066020191982b2315fc45d05e068eee761Brian Paul 1364f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX what if format/type doesn't match texture format/type? */ 1365f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 13668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!pixels) 13678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 13688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 13708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage) { 13718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* invalid mipmap level, not an error */ 13728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 13738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 13748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage->Data) { 13768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* no image data, not an error */ 13778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 13788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 13798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 13805ed63e089564a3d10e65bc22902ac722f92bdd29Brian Paul { 13815ed63e089564a3d10e65bc22902ac722f92bdd29Brian Paul const GLint width = texImage->Width; 13825ed63e089564a3d10e65bc22902ac722f92bdd29Brian Paul const GLint height = texImage->Height; 13835ed63e089564a3d10e65bc22902ac722f92bdd29Brian Paul const GLint depth = texImage->Depth; 13848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint img, row; 13858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (img = 0; img < depth; img++) { 13868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (row = 0; row < height; row++) { 13878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* compute destination address in client memory */ 138857aca2bf6e82cdab43575123530fce2ba54bf9c7Brian Paul GLvoid *dest = _mesa_image_address( &ctx->Pack, pixels, 1389f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul width, height, format, type, 1390f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul img, row, 0); 13918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul assert(dest); 13928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1393f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (format == GL_COLOR_INDEX) { 1394f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLuint indexRow[MAX_WIDTH]; 1395f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint col; 1396f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (col = 0; col < width; col++) { 1397e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1398e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) &indexRow[col]); 1399f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1400f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_pack_index_span(ctx, width, type, dest, 1401f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul indexRow, &ctx->Pack, 1402cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 0 /* no image transfer */); 1403f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1404f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else if (format == GL_DEPTH_COMPONENT) { 1405f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLfloat depthRow[MAX_WIDTH]; 1406f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul GLint col; 1407f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul for (col = 0; col < width; col++) { 1408e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1409e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) &depthRow[col]); 1410f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1411f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_pack_depth_span(ctx, width, dest, type, 1412f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul depthRow, &ctx->Pack); 1413f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1414c5b995066020191982b2315fc45d05e068eee761Brian Paul else if (format == GL_YCBCR_MESA) { 1415c5b995066020191982b2315fc45d05e068eee761Brian Paul /* No pixel transfer */ 1416c5b995066020191982b2315fc45d05e068eee761Brian Paul MEMCPY(dest, (const GLushort *) texImage->Data + row * width, 1417c5b995066020191982b2315fc45d05e068eee761Brian Paul width * sizeof(GLushort)); 1418c5b995066020191982b2315fc45d05e068eee761Brian Paul /* check for byte swapping */ 1419c5b995066020191982b2315fc45d05e068eee761Brian Paul if ((texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR 1420c5b995066020191982b2315fc45d05e068eee761Brian Paul && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) || 1421c5b995066020191982b2315fc45d05e068eee761Brian Paul (texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV 1422c5b995066020191982b2315fc45d05e068eee761Brian Paul && type == GL_UNSIGNED_SHORT_8_8_MESA)) { 1423c5b995066020191982b2315fc45d05e068eee761Brian Paul if (!ctx->Pack.SwapBytes) 1424c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_swap2((GLushort *) dest, width); 1425c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1426c5b995066020191982b2315fc45d05e068eee761Brian Paul else if (ctx->Pack.SwapBytes) { 1427c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_swap2((GLushort *) dest, width); 1428c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1429c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1430f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul else { 14318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* general case: convert row to RGBA format */ 14328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLchan rgba[MAX_WIDTH][4]; 14338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint col; 14348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (col = 0; col < width; col++) { 1435e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (*texImage->FetchTexel)(texImage, col, row, img, 1436e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul (GLvoid *) rgba[col]); 14378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1438e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul _mesa_pack_rgba_span(ctx, width, (const GLchan (*)[4])rgba, 1439e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul format, type, dest, &ctx->Pack, 1440cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 0 /* no image transfer */); 14418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* format */ 14428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* row */ 14438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } /* img */ 14445ed63e089564a3d10e65bc22902ac722f92bdd29Brian Paul } 1445289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul} 1446289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 1447289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 14488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 1449289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 1450c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 1451c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 1452fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 145343911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 1454fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 1455fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 1456c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1457ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1458fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1459cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1460c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1461f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1462f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1463f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1464f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 14658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 1466f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 14670293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 14680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1469f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1470aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1471f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 1, postConvWidth, 1, 1, border)) { 14728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1473c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1474c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1475f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 14768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 14778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 14780293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 14790293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1480021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 14810293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 14820293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 148308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 14840293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 14850293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 14860293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 14870293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 14888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 1489aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 14900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1491c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1492f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 14938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 14948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, 1, 1, 14953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 1496c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1497b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 149808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1499fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 15008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage1D); 150162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 150262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 0 /* don't make default teximage anymore */ 1503c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 15048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 15058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, format, type, pixels, 15068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1507c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1508c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 15098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, 1, 1, format); 15108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 15118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 15128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, border, 15138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 15148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 15158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 15160293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1517c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 151862c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#else 151962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul /* <pixels> may be null! */ 152062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 152162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, border, format, type, pixels, 152262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul &ctx->Unpack, texObj, texImage); 152362c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1524c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 152538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 152629acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul if (!texImage->FetchTexel) { 152729acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul /* If driver didn't explicitly set this, use the default */ 152829acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel1D; 152929acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul } 1530e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->FetchTexel); 1531f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 1532e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (texImage->IsCompressed) { 1533e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(texImage->CompressedSize > 0); 1534e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1535e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 15360293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1537a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1538a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1539c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 154038d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 1541c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 154238d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 15438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, 1, 15448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 15458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1546a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1547a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1548a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1549a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 15508afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 15518afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, 1, 1, 15523893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 15538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 155438d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 155538d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 15568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, 1, 1, border); 155738d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 155838d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1559aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 15608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 1561f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 1562c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1563c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1564c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1565c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 156608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1567c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 1568c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1569c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1570c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1571c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1572fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 157343911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 1574fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 1575fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1576fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1577c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1578ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 1579fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1580cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1581c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1582f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1583f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 158438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes &postConvHeight); 1585f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1586f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 15878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 1588a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 1589fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 15908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 15918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (ctx->Extensions.NV_texture_rectangle && 15928afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_TEXTURE_RECTANGLE_NV)) { 15938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 1594f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 15950293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 15960293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1597f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 1598aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 1599f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 2, postConvWidth, postConvHeight, 1600f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 1, border)) { 16018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1602c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1603c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1604f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 160535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 1606fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 16070293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 16080293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1609021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 16103893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 16110293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 161208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 16130293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 16140293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 16150293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 16160293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 16178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* free the old texture data */ 1618aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 16190293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1620c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1621f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 16228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 16238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, postConvHeight, 1, 16248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 1625c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1626b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 162708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1628fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 16298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage2D); 163062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 163162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 0 /* don't make default teximage anymore */ 1632c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 16338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 16348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, format, type, pixels, 16358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1636c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1637c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 16388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, 1, format); 16398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 16408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 16418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, border, 16428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 16438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 16448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 16450293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 164762c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#else 164862c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul /* <pixels> may be null! */ 164962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 165062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, height, border, format, type, pixels, 165162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul &ctx->Unpack, texObj, texImage); 165262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 165438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 165529acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul if (!texImage->FetchTexel) { 165629acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul /* If driver didn't explicitly set this, use the default */ 165729acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel2D; 165829acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul } 1659e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->FetchTexel); 1660f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 1661e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (texImage->IsCompressed) { 1662e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(texImage->CompressedSize > 0); 1663e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1664e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 16650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1666a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1667a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1668afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1669172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul else if (target == GL_PROXY_TEXTURE_2D || 1670172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 16718afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.ARB_texture_cube_map) || 16728afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (target == GL_PROXY_TEXTURE_RECTANGLE_NV && 16738afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.NV_texture_rectangle)) { 1674afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 167538d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 167638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes format, type, 2, 167738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes postConvWidth, postConvHeight, 1, border); 16788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1679a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1680a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1681a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1682a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 16838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 16848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, postConvHeight, 1, 16858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 16868e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 168738d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 16888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, format, type, 16898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul postConvWidth, postConvHeight, 1, border); 169038d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 169138d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1692aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1693cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul const GLint maxLevels = (target == GL_PROXY_TEXTURE_2D) ? 1694cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ctx->Const.MaxTextureLevels : ctx->Const.MaxCubeTextureLevels; 1695cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level >= 0 && level < maxLevels) { 1696f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 1697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1700afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 170108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 1702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1705afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1706afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1707afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 1708afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 1709afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 1710afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1711fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1712b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 1713fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1714fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 1715fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1716afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1717fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1718cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1719afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_3D) { 1721f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 17220293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 17230293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 1724289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 17255535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul if (texture_error_check(ctx, target, level, (GLint) internalFormat, 1726aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul format, type, 3, width, height, depth, border)) { 17278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 1728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1729afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1730f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 17318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 17328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 17330293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 17340293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 1735021a525616bef2bafc8f60edc193b975ed2b0efaBrian Paul texImage = _mesa_alloc_texture_image(); 17360293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texObj->Image[level] = texImage; 17370293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 173808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 17390293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul return; 17400293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 17410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 17420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul else if (texImage->Data) { 1743aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 17440293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texImage->Data = NULL; 1745afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1746f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 17478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 17488afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul width, height, depth, 17498afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 1750afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1751b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 175208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1753fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 17548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage3D); 175562c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 175662c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 0 /* don't make default teximage anymore */ 1757c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (pixels) { 17585535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, (GLint) internalFormat, 17598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 17608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 17618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 17648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *dummy = make_null_texture(width, height, depth, format); 17658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (dummy) { 17665535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, 17675535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul (GLint) internalFormat, 17688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, border, 17698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, GL_UNSIGNED_BYTE, dummy, 17708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &_mesa_native_packing, texObj, texImage); 17718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul FREE(dummy); 17720293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 1773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 177462c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#else 177562c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul /* <pixels> may be null! */ 177662c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 177762c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, height, depth, border, format, type, 177862c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul pixels, &ctx->Unpack, texObj, texImage); 177962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 178138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 178229acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul if (!texImage->FetchTexel) { 178329acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul /* If driver didn't explicitly set this, use the default */ 178429acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel3D; 178529acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul } 1786e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->FetchTexel); 1787f378ab825c0c74aab263e7dec30194eead22c288Brian Paul 1788e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul if (texImage->IsCompressed) { 1789e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(texImage->CompressedSize > 0); 1790e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1791e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 17920293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 1793a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 1794a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 1795afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 179638d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 1797afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 179838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 179938d3f3d660225150715bc06f6b33e394ba803299Brian Paul format, type, 3, width, height, depth, border); 18008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 1801a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 1802a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 1803a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1804a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 18058afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 18063893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 18078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 180838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 180938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, format, type, 181038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 181138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 181238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 1813aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 1814cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level >= 0 && level < ctx->Const.Max3DTextureLevels) { 1815f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 1816afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1818afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1819afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 182008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 1822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1823afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1824afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1825afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1826663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paulvoid 182743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 1828663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1829663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 1830663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 1831663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 18325535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul _mesa_TexImage3D(target, level, internalFormat, width, height, 1833663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 1834663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 1835663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1836663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 1837afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1838fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1839fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 1840fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 1841fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1842fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1844ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 18450293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 18460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 18470293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 18482c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 184975280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 185075280a2c742ee241d392618a3b29548fce1520a9Brian Paul 1851b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 185208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 18532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1854f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1855f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 1856f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1857f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1858afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1859c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 1860a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, 1, 1, format, type)) { 1861f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1862afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1863afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18640293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 18658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 18668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 18670293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1869c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || !pixels) 1870c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1871afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1872347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 1873347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 1874347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 18758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage1D); 18768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 18778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, &ctx->Unpack, 18788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 1879bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1880afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1881afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1882afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1883fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1884fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 1885fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 1886fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 1887fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1888fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1889afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1890ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 18910293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 18920293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 18930293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 18942c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 189575280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 189675280a2c742ee241d392618a3b29548fce1520a9Brian Paul 1897b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 189808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 18992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1900f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 1901f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 1902f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 1903f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 1904f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1905afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1906c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1907a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, postConvHeight, 1, format, type)) { 1908f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1909afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1910afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 19110293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 191235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 19138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 19140293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1915afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1916c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || !pixels) 1917c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1918afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1919347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 1920347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 1921347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 1922347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 19238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage2D); 19248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 19258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, format, type, pixels, 19268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 1927bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1928c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1929afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1930afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1931afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1932fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1933fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 1934fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1935fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 1936fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 1937fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 1938afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 19390293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 19400293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 19410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 19422c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 194375280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 194475280a2c742ee241d392618a3b29548fce1520a9Brian Paul 1945b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 194608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 19472aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 1948c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 1949c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 1950f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 1951afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1952afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 19530293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 19548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 19558e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 19560293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 1957afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1958c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width == 0 || height == 0 || height == 0 || !pixels) 1959c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 1960afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1961347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 1962347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 1963347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 1964347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul zoffset += texImage->Border; 1965347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 19668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage3D); 19678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 19688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 19698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 19708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 19718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage ); 1972bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 1973afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1974afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1975afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1977fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 1978fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 1979fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 1980fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 1981fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 1982afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 19832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 19842aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 19852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 1986ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 1987fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 1988cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1990b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 199108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 1992fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 1993f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 1994f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 1995f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 1996ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 1997ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 1998ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, 1, border)) 1999ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2000ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 20012aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 20022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 20032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 20042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 20052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_alloc_texture_image(); 20063893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 20072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 200808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 2009c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 2010c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 20112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 20122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else if (texImage->Data) { 20132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* free the old texture data */ 2014aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 20152aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage->Data = NULL; 20162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 20177dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 20182aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 20198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1, 20203893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 20217dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 20222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 20232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage1D); 20242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, 20252aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, border); 20262aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2027e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->TexFormat); 202829acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul if (!texImage->FetchTexel) { 202929acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul /* If driver didn't explicitly set this, use the default */ 203029acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel1D; 203129acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul } 2032e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->FetchTexel); 2033e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul 20342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 20352aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 20362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 2037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2038afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2039afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2040afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2041fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 2042fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 2043fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 2044fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 2045afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 20462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 20472aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 20482aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2049ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2050fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2051cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2052afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2053b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 205408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2055fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2056f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 2057f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 2058f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 2059f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2060ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2061ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 2062ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight, border)) 2063ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2064ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 20652aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 20662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 20672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 20682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 20692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage = _mesa_alloc_texture_image(); 20703893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 20712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 207208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 2073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 2074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 20752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 20762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul else if (texImage->Data) { 20772aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* free the old texture data */ 2078aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 20792aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texImage->Data = NULL; 20802aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 20817dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 20822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 20838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 20848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, postConvHeight, 1, 20853893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 2086afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 20872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 20882aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, 20892aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height, border); 20902aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2091e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->TexFormat); 209229acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul if (!texImage->FetchTexel) { 209329acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul /* If driver didn't explicitly set this, use the default */ 209429acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul texImage->FetchTexel = texImage->TexFormat->FetchTexel2D; 209529acfe5bd40e1741c07959c4b44a9bf46d250283Brian Paul } 2096e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->FetchTexel); 2097e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul 20982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 20992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 21002aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 2101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2105fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 2106fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 2107fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 2108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2109347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2110347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_object *texObj; 2111347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2112ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2113fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2114cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2116b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 211708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2118fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2119f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 21208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2121ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2122ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 1, target, level, 2123ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul xoffset, 0, 0, postConvWidth, 1)) 2124ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2125ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2126347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2127347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2128347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2129347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2130347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2131347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2132347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 21332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage1D); 21342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width); 2135bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2140fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 2141fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2142fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2143fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2145347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2146347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_object *texObj; 2147347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2148ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2149fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2150cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2152b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 215308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2154fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2155f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2156f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 2157ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2158ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 2159ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight)) 2160ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2161ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2162347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2163347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2164347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2165347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2166347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2167347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2168347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2169347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 21702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage2D); 21712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 21722aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, x, y, width, height); 2173bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2178fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulvoid 2179fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2180fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2181fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2182afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2183347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2184347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_object *texObj; 2185347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2186ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2187fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2188cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2189afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2190b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 219108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2192fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2193f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2194f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 2195ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2196ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, 2197ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul zoffset, postConvWidth, postConvHeight)) 2198ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2199ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2200347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2201347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2202347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2203347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2204347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2205347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2206347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2207347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul zoffset += texImage->Border; 2208347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 22092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage3D); 22102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 22112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, zoffset, 22122aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height); 2213bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2214afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 22151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 22181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 22191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 2220aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 22211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 22221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 22231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2224aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2225cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2226aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2227289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2228289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2229289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2230289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2231289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2232289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2233289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 223408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); 2235289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2236289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2237289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2238289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2239289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2240289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 2241aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 2242aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2243aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2244aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2245aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2246aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2247aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border)) { 2248aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2249aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2250aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2251aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 22528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 22538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2254aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2255aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2256aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2257aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2258aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 225908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB"); 2260aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2261aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2262aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2263aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2264aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 2265aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2266aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2267aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 22688afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 22693893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 22706628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 22718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 22728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 22738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 22748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, border, 22758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul imageSize, data, 22768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 22778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2278aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2279aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2280aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2281a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2282a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2283aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2284aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2285aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 228638d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 228738d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 1, width, 1, 1, border); 22888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2289a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2290a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2291a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2292a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 22938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 22943893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 22958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 229638d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 229738d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 229838d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 229938d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 230038d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2301aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2302f378ab825c0c74aab263e7dec30194eead22c288Brian Paul if (level >= 0 && level < ctx->Const.MaxTextureLevels) { 2303f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); 2304aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2305aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2306aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2307aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 2308cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)"); 2309aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2310aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 23111207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 23121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 23141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 23151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 2316aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 23171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 23181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 23191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2320aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2321cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2322aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2323289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2324289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2325289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2326289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2327289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2328289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2329289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 233008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); 2331289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2332289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2333289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2334289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2335289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2336289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 23378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 2338a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 23399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 23408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 23418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (ctx->Extensions.NV_texture_rectangle && 23428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_TEXTURE_RECTANGLE_NV)) { 2343aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2344aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2345aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2346aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2347aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 23486c25e3a111e19587b288dcf5384b8e5eda3edc80Brian Paul GL_NONE, GL_NONE, 2, width, height, 1, border)) { 2349aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2350aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2351aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2352aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 23548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2355aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2356aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2357aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2358aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2359aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 236008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); 2361aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2362aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2363aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2364aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2365aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 2366aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2367aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2368aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 23698afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 23708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 23716628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 23728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 23738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 23748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 23758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, width, height, 23768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 23778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 23788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2379aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2380aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2381aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2382a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2383a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2384aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2385aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_2D) { 2386aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 238738d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 238838d3f3d660225150715bc06f6b33e394ba803299Brian Paul GL_NONE, GL_NONE, 2, width, height, 1, border); 23898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2390a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2391a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2392a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2393a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 23948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 23953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 23968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 239738d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 239838d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 239938d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 240038d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 240138d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2402aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2403cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul const GLint maxLevels = (target == GL_PROXY_TEXTURE_2D) ? 2404cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ctx->Const.MaxTextureLevels : ctx->Const.MaxCubeTextureLevels; 2405cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level >= 0 && level < maxLevels) { 2406f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); 2407aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2408aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2409aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2410aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 2411cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)"); 2412aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2413aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 24141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 24151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 24161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 24171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 24181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 2419aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 24201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 24211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 24221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2423aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2424cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2425aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2426289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul switch (internalFormat) { 2427289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_ALPHA_ARB: 2428289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ARB: 2429289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2430289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_INTENSITY_ARB: 2431289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGB_ARB: 2432289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul case GL_COMPRESSED_RGBA_ARB: 243308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); 2434289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul return; 2435289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul default: 2436289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul /* silence compiler warning */ 2437289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul ; 2438289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2439289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 24409540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 2441aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2442aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2443aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 2444aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2445aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 24466c25e3a111e19587b288dcf5384b8e5eda3edc80Brian Paul GL_NONE, GL_NONE, 3, width, height, depth, border)) { 2447aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; /* error in texture image was detected */ 2448aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2449aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2450aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 24518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 24528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2453aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2454aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2455aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage = _mesa_alloc_texture_image(); 2456aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texObj->Image[level] = texImage; 2457aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 245808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); 2459aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2460aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2461aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2462aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (texImage->Data) { 2463aeb4434563c4014a662ea334878b60d3031bb3c1Brian Paul MESA_PBUFFER_FREE(texImage->Data); 2464aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texImage->Data = NULL; 2465aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2466aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 24678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, depth, 24688afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 24696628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 24708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 24718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 24728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 24738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul internalFormat, 24748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 24758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul border, imageSize, data, 24768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 24778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(texImage->CompressedSize > 0); /* sanity */ 2478aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2479aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2480aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2481a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2482a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2483aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2484aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 2485aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 248638d3f3d660225150715bc06f6b33e394ba803299Brian Paul GLenum error = texture_error_check(ctx, target, level, internalFormat, 24876c25e3a111e19587b288dcf5384b8e5eda3edc80Brian Paul GL_NONE, GL_NONE, 3, width, height, depth, border); 24888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 2489a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_unit *texUnit; 2490a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul struct gl_texture_image *texImage; 2491a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2492a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 24938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 24948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul width, height, depth, 24953893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 24968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 249738d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 249838d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 249938d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 250038d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 250138d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2502aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2503cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level >= 0 && level < ctx->Const.Max3DTextureLevels) { 2504f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); 2505aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2506aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2507aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2508aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 2509cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)"); 2510aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 2511aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 25121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 25131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 25161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 25171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei width, GLenum format, 25181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 25191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 25209540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 25219540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 25229540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2523a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 252475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 252575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 25269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 25279540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, 1, 1, format, GL_NONE)) { 25289540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 25299540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 25309540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25319540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 25338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 25349540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 25359540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25369540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || !data) 25379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 25389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage1D) { 25408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 25418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, width, 25428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 25438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 25449540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2545bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 25461207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 25471207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 25501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 25511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 25521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 25531207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 25541207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 25559540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 25569540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 25579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2558a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 255975280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 256075280a2c742ee241d392618a3b29548fce1520a9Brian Paul 25619540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 25629540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, 1, format, GL_NONE)) { 25639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 25649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 25659540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25669540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25679540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 25688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 25699540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 25709540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25719540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || !data) 25729540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 25739540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 25749540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage2D) { 25758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 25768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, width, height, 25778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 25788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 25799540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2580bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 25811207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 25821207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25831207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 25841207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 25851207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 25861207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 25871207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 25881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 25891207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 25909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 25919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 25929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2593a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 259475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 259575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 25969540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 25979540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul width, height, depth, format, GL_NONE)) { 25989540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* error was detected */ 25999540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26009540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26019540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26029540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 26038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 26049540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 26059540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26069540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (width == 0 || height == 0 || depth == 0 || !data) 26079540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 26089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26099540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage3D) { 26108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 26118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 26128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 26138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 26148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 26159540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 2616bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 26171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 26181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 26191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 26201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paulvoid 26219540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 26221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 26238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 26249540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul const struct gl_texture_object *texObj; 26259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 2626cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels; 2627a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 2628cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 26299540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 2630cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2631cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2632cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (!texObj) { 2633cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB"); 2634cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 2635cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2636cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2637cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D) { 2638cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxTextureLevels; 2639cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2640cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else if (target == GL_TEXTURE_3D) { 2641cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.Max3DTextureLevels; 2642cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2643cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul else { 2644cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 2645cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2646cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2647cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(maxLevels > 0); 2648cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2649cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 2650cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 26519540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 26529540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26539540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (is_proxy_target(target)) { 265508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 26568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 26579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26589540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 26609540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage) { 2661e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul /* probably invalid mipmap level */ 266208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 26639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 26649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26659540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26669540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage->IsCompressed) { 266708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); 26689540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 26699540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26709540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26719540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!img) 26729540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 26739540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 26748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (ctx->Extensions.ARB_texture_compression) { 26758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.GetCompressedTexImage); 26769540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, 26779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texImage); 26789540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 26791207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 2680