teximage.c revision 0899afae33a29d1f6d15ebc96dc6ea8a8371cdb6
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library 34618a9bfc2cd57c47ddf3590782c751ec194d362Brian Paul * Version: 6.5 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 5add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 135e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 165e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 26add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * Texture images manipulation functions. 29add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \note Mesa's native texture data type is GLchan. Native formats are 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, and 32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * GL_COLOR_INDEX. 33add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * 34add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \note Device drivers are free to implement any internal format they want. 35add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 36add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 37add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 38fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 39b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 41f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul#include "convolve.h" 42afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 433c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 44ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 45fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 472c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes#include "texformat.h" 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 49afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 503893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul#include "texstore.h" 515e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 53afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 544cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 554cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 564cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 574cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 584cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 594cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 604cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 614cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 624cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 634cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 774e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul#if 0 784e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paulstatic void PrintTexture(GLcontext *ctx, const struct gl_texture_image *img) 794827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul{ 80f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#if CHAN_TYPE == GL_FLOAT 81f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul _mesa_problem(NULL, "PrintTexture doesn't support float channels"); 82f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#else 83b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul GLuint i, j, c; 84b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul const GLchan *data = (const GLchan *) img->Data; 85b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 86b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul if (!data) { 873c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("No texture data\n"); 88b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul return; 89b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 90b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 91b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul switch (img->Format) { 92b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_ALPHA: 93b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_LUMINANCE: 94b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_INTENSITY: 95b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_COLOR_INDEX: 96b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 1; 97b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 98b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_LUMINANCE_ALPHA: 99b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 2; 100b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 101b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_RGB: 102b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 3; 103b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 104b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul case GL_RGBA: 105b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul c = 4; 106b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul break; 107b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul default: 108b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul _mesa_problem(NULL, "error in PrintTexture\n"); 109b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul return; 110b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 111b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul 112b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul for (i = 0; i < img->Height; i++) { 113b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul for (j = 0; j < img->Width; j++) { 114b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul if (c==1) 1153c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("%02x ", data[0]); 116b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==2) 1173c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("%02x%02x ", data[0], data[1]); 118b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==3) 1193c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("%02x%02x%02x ", data[0], data[1], data[2]); 120b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul else if (c==4) 1213c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]); 122681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul data += (img->RowStride - img->Width) * c; 123b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 1243c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("\n"); 125b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 126f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif 1274827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul} 1284827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul#endif 1294827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1304827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 131f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 132887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)). 133973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1. 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 135fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 136fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 141973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n < 0) 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 143973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul 144973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n == 0) 145973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul return 0; 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 152887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul return log2 - 1; 153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1621749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 1631749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1661749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 17089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 17189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 17289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 174b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 1751749a25ca889d514889b34cf6311c8014d97bf66Brian Paul_mesa_base_tex_format( GLcontext *ctx, GLint internalFormat ) 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1771749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 181afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 182afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 186afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 187afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 189afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 190afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 191afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 194afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 196afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 197afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 198afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 199afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 200afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 201afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 202afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 203afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 204afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 208afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 209afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 210afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 211afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 212afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 213afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 214afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 215afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 216afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 217afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 218afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 219afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 220afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 221afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 222afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 223afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 224afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 225afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 226f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 234f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 239e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 242f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 2454618a9bfc2cd57c47ddf3590782c751ec194d362Brian Paul if (ctx->Extensions.SGIX_depth_texture || 2464618a9bfc2cd57c47ddf3590782c751ec194d362Brian Paul ctx->Extensions.ARB_depth_texture) { 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT16_SGIX: 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT24_SGIX: 251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT32_SGIX: 252f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 25789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_compression) { 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 260f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_ALPHA: 26189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_ALPHA; 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_LUMINANCE: 26389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_LUMINANCE; 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_LUMINANCE_ALPHA: 26589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_LUMINANCE_ALPHA; 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_INTENSITY: 26789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INTENSITY; 268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB: 26989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 270f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA: 27189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 275f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 278f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 28089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 28289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 288f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 289f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2908f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2918f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 292f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 293f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 294f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 29540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 296f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 297f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 298f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 299f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 300f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 301f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 302f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 303f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 304f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 305663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 306f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 307f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 308663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 309f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 310f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 311f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 312f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 31389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 314f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 315f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 316f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 317f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 3181749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 319f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 320f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 321f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 322f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 323f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 324f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 325f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 326f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 327f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 328f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 329f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 330f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 331f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 332f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 333f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 334f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 335f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 336f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 337f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 338f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 339f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 3408f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 341f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 342afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 343f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 3441ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3451ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3461ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3471ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3481ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3491ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3501ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3511ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3521ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3531ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 354f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 355afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 356afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 357afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 3593405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a color/RGBA format (i.e., not color 3603405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * index, depth, stencil, etc). 3613405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * \param format the image format value (may by an internal texture format) 3621749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. 363f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul */ 364f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 3653405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_color_format(GLenum format) 366f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 3673405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 368ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_RED: 369ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_GREEN: 370ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_BLUE: 371f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA: 372f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA4: 373f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA8: 374f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA12: 375f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA16: 376f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 1: 377f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE: 378f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4: 379f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8: 380f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12: 381f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16: 382f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 2: 383f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE_ALPHA: 384f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4_ALPHA4: 385f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE6_ALPHA2: 386f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8_ALPHA8: 387f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA4: 388f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA12: 389f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16_ALPHA16: 390f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY: 391f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY4: 392f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY8: 393f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY12: 394f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY16: 395f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 3: 396f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB: 397beef59e73aad91ca52d72fd0224e696826038318Brian Paul case GL_BGR: 398f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_R3_G3_B2: 399f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB4: 400f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5: 401f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB8: 402f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10: 403f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB12: 404f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB16: 405f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 4: 406f252f64430ccb957698fcf85e84c9d64008147ebBrian Paul case GL_ABGR_EXT: 407f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA: 408beef59e73aad91ca52d72fd0224e696826038318Brian Paul case GL_BGRA: 409f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA2: 410f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA4: 411f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5_A1: 412f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA8: 413f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10_A2: 414f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA12: 415f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA16: 416f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul /* float texture formats */ 417f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 418f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 419f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 420f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 421f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 422f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 423f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 424f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 425f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 426f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 427f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 428f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 4293405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul /* compressed formats */ 4303405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_ALPHA: 4313405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_LUMINANCE: 4323405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_LUMINANCE_ALPHA: 4333405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_INTENSITY: 4343405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB: 4353405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA: 436997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGB_S3TC: 437997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGB4_S3TC: 438997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGBA_S3TC: 439997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGBA4_S3TC: 4403405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 4413405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 4423405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 4433405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 4443405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 4453405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 446f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 447c5b995066020191982b2315fc45d05e068eee761Brian Paul case GL_YCBCR_MESA: /* not considered to be RGB */ 448f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 449f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 450f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 451f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 452f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 453f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 4546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 4553405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a color index format. 4566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 457f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 4583405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_index_format(GLenum format) 459f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 4603405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 461f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX: 462f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX1_EXT: 463f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX2_EXT: 464f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX4_EXT: 465f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX8_EXT: 466f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX12_EXT: 467f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX16_EXT: 468f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 469f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 470f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 471f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 472f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 473f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 47589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 4763405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a depth component format. 4771749a25ca889d514889b34cf6311c8014d97bf66Brian Paul */ 4781749a25ca889d514889b34cf6311c8014d97bf66Brian Paulstatic GLboolean 4793405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_depth_format(GLenum format) 4801749a25ca889d514889b34cf6311c8014d97bf66Brian Paul{ 4813405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 4821749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_DEPTH_COMPONENT16_ARB: 4831749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_DEPTH_COMPONENT24_ARB: 4841749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_DEPTH_COMPONENT32_ARB: 4851749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_DEPTH_COMPONENT: 4861749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_TRUE; 4871749a25ca889d514889b34cf6311c8014d97bf66Brian Paul default: 4881749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_FALSE; 4891749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 4901749a25ca889d514889b34cf6311c8014d97bf66Brian Paul} 4911749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 4921749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 4931749a25ca889d514889b34cf6311c8014d97bf66Brian Paul/** 4943405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a YCbCr format. 4951749a25ca889d514889b34cf6311c8014d97bf66Brian Paul */ 4961749a25ca889d514889b34cf6311c8014d97bf66Brian Paulstatic GLboolean 4973405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_ycbcr_format(GLenum format) 4981749a25ca889d514889b34cf6311c8014d97bf66Brian Paul{ 4993405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 5001749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_YCBCR_MESA: 5011749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_TRUE; 5021749a25ca889d514889b34cf6311c8014d97bf66Brian Paul default: 5031749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_FALSE; 5041749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 5051749a25ca889d514889b34cf6311c8014d97bf66Brian Paul} 5061749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5071749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5081749a25ca889d514889b34cf6311c8014d97bf66Brian Paul/** 5091ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul * Test if the given image format is a Depth/Stencil format. 5101ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul */ 5111ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paulstatic GLboolean 5121ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paulis_depthstencil_format(GLenum format) 5131ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul{ 5141ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (format) { 5151ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 5161ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 5171ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_TRUE; 5181ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 5191ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_FALSE; 5201ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 5211ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul} 5221ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 5231ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 5241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 5251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul/** 5266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if it is a supported compressed format. 5276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat the internal format token provided by the user. 5296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \ret GL_TRUE if \p internalFormat is a supported compressed format, or 5316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_FALSE otherwise. 5326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX 5346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * are supported. 535aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 536aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paulstatic GLboolean 53740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borcais_compressed_format(GLcontext *ctx, GLenum internalFormat) 538aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 539a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) ctx; 54089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul switch (internalFormat) { 54189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 54289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 54340bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 54440bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 54540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 54640bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 547663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca case GL_RGB_S3TC: 548663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca case GL_RGB4_S3TC: 549663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca case GL_RGBA_S3TC: 550663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca case GL_RGBA4_S3TC: 551e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 55289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul default: 553e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_FALSE; 554e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 555aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 556aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 557aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 5586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 5666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 568afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5693893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5703893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5713893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 573fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 574fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 575fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 576fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 5779228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_1D: 578fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 5799228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_3D: 58018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell tObj->Image[0][level] = texImage; 581a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul break; 582fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 583fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 584fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 585fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 586fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 5870d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 5880d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul { 5890d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul GLuint face = ((GLuint) target - 5900d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 5910d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul tObj->Image[face][level] = texImage; 5920d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul } 5930d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul break; 5948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 5958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 59618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell tObj->Image[0][level] = texImage; 597a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul break; 598fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 5993893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(NULL, "bad target in _mesa_set_tex_image()"); 600fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 601fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 602a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 603a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 604fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 605fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 606fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 607a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 6086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 6096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 610a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 611a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 6126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 6146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 61577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 61677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 617a3f137094cd965d27e1b088499dd609b81a91906Brian Paul_mesa_new_texture_image( GLcontext *ctx ) 61877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 619a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 62077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 62177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 62277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 62377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 624a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 6253e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 6264cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 6273e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6283e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * \param teximage texture image. 6293e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6303e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 6313e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 6323e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 6334cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texture_image_data(GLcontext *ctx, 6344cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 6353e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 6363e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 6373e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 6384cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 6393e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 6403e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6413e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 6423e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 6433e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6443e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6453e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param teximage texture image. 6496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6503e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 651a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 65277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6533e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell_mesa_delete_texture_image( GLcontext *ctx, struct gl_texture_image *texImage ) 65477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6553e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data) { 6563e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 65777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul } 6583e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 6593e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell FREE( texImage ); 66077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 66177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 66277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 669aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 6708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLboolean 6718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulis_proxy_target(GLenum target) 672aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 6738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 67627f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 67727f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV); 678aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 679aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 680aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the texture object that corresponds to the target of the given texture unit. 6836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 6856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 6866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 6896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 69135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 69235d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 69301e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 69435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 69535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 69635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 69735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 698a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current1D; 69935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 70035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy1D; 70135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 702a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current2D; 70335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 70435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy2D; 70535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 706a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul return texUnit->Current3D; 70735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 70835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return ctx->Texture.Proxy3D; 70935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 71035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 71135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 71235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 71335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 71435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7155ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 716a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 71735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? texUnit->CurrentCubeMap : NULL; 71835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 719a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 72035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul ? ctx->Texture.ProxyCubeMap : NULL; 7218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ? texUnit->CurrentRect : NULL; 7248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7258afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7268afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ? ctx->Texture.ProxyRect : NULL; 72735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 72808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 72935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 73135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 73235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 73335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 7356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the texture image struct which corresponds to target and level 7366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * of the given texture unit. 7376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 7406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture image structure on success, or NULL on failure. 7446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 746fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 747fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 748fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 749fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul GLenum target, GLint level) 750fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 751fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texUnit); 752cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 753fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 754fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_1D: 75518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return texUnit->Current1D->Image[0][level]; 756fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_1D: 75718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return ctx->Texture.Proxy1D->Image[0][level]; 758fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 75918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return texUnit->Current2D->Image[0][level]; 760fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_2D: 76118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return ctx->Texture.Proxy2D->Image[0][level]; 762fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_3D: 76318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return texUnit->Current3D->Image[0][level]; 764fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_3D: 76518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return ctx->Texture.Proxy3D->Image[0][level]; 766fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 767fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 768fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 769fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 770fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 77118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 77218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 77318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell GLuint face = ((GLuint) target - 77418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 77518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return texUnit->CurrentCubeMap->Image[face][level]; 77618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell } 777fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 778fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 779fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 780a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 78118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return ctx->Texture.ProxyCubeMap->Image[0][level]; 782fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 783fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 7848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (ctx->Extensions.NV_texture_rectangle) { 7868afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 78718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return texUnit->CurrentRect->Image[0][level]; 7888afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 7908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return NULL; 7918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7928afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (ctx->Extensions.NV_texture_rectangle) { 7948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 79518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell return ctx->Texture.ProxyRect->Image[0][level]; 7968afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 7978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 7988afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return NULL; 7998afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 800fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 80108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(ctx, "bad target in _mesa_select_tex_image()"); 802fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 803fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 804fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 805fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 806fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 807a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 808a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 810a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 811a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 812a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 813a3f137094cd965d27e1b088499dd609b81a91906Brian Paul_mesa_get_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 818a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 819a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_object *texObj; 820a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul ASSERT(texObj); 827a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 828a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 829a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 830a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 838a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul_mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level) 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 842a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 843a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 847a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 848a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 849a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 85118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImage = ctx->Texture.Proxy1D->Image[0][level]; 852a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 853a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 855a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 856a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 857a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 85818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell ctx->Texture.Proxy1D->Image[0][level] = texImage; 859a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 860a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = ctx->Texture.Proxy1D; 861a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 862a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 863a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 865a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImage = ctx->Texture.Proxy2D->Image[0][level]; 867a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 868a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 870a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 871a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 872a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 87318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell ctx->Texture.Proxy2D->Image[0][level] = texImage; 874a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 875a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = ctx->Texture.Proxy2D; 876a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 877a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 878a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 879a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 880a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 88118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImage = ctx->Texture.Proxy3D->Image[0][level]; 882a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 883a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 884a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 885a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 886a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 887a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 88818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell ctx->Texture.Proxy3D->Image[0][level] = texImage; 889a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 890a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = ctx->Texture.Proxy3D; 891a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 892a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 893a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 894a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 895a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 89618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImage = ctx->Texture.ProxyCubeMap->Image[0][level]; 897a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 898a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 899a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 900a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 901a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 902a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 90318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell ctx->Texture.ProxyCubeMap->Image[0][level] = texImage; 904a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 905a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = ctx->Texture.ProxyCubeMap; 906a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 907a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 908a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 909a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 910a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 91118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImage = ctx->Texture.ProxyRect->Image[0][level]; 912a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 913a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 914a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 915a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 916a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 917a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 91818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell ctx->Texture.ProxyRect->Image[0][level] = texImage; 919a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 920a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = ctx->Texture.ProxyRect; 921a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 922a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 923a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 924a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 925a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 926a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 927a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 928a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 9296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 9306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 9316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 9336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 9346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 941ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul_mesa_max_texture_levels(GLcontext *ctx, GLenum target) 942ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 943ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 944ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 945ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 946ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 947ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 948ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 949ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 950ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 951ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 952ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 953ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 954ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 955ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 956ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 957ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 958add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 959ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 960ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxCubeTextureLevels; 961ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 962ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 963ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 1; 964ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 965ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 966ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 967ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 968ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 969ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 970fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 97162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 972f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 973afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 974afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 9758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 9788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 9808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 9818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 9828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 984a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 985afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 987afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 988afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 99165d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 992afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 993afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 994afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 995afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 996afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 997afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1000afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1001afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1013afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1017a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 102162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1025738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1026f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10309c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10319c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1032f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1033f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1034f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10359c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10369c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1037f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10389c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10399c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 10409c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Format = 0; 104116a8e986cebae6560d00992b6b9f54549e1d03c6Gareth Hughes img->IntFormat = 0; 10429c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10439c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10449c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10459c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1046681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 10479c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10489c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10499c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10509c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10519c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10529c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10539c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10542c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes img->TexFormat = &_mesa_null_texformat; 10554f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10564f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10579c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IsCompressed = 0; 10589c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->CompressedSize = 0; 10599c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10609c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10619c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10636628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 10666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 10676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 10686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 10696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 10706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 10716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 10726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 10736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1075887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 10766628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 10773893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 10788afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul_mesa_init_teximage_fields(GLcontext *ctx, GLenum target, 10793893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 10803893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 10813893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint border, GLenum internalFormat) 10826628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 10836628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 108438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes img->Format = _mesa_base_tex_format( ctx, internalFormat ); 1085e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul ASSERT(img->Format > 0); 108616a8e986cebae6560d00992b6b9f54549e1d03c6Gareth Hughes img->IntFormat = internalFormat; 10876628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 10886628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 10896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 10906628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1091681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = width; 10926628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->WidthLog2 = logbase2(width - 2 * border); 10936628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (height == 1) /* 1-D texture */ 10946628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 10956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 10966628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = logbase2(height - 2 * border); 10976628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul if (depth == 1) /* 2-D texture */ 10986628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 10996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul else 11006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = logbase2(depth - 2 * border); 1101887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->Width2 = width - 2 * border; /*1 << img->WidthLog2;*/ 1102887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->Height2 = height - 2 * border; /*1 << img->HeightLog2;*/ 1103887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->Depth2 = depth - 2 * border; /*1 << img->DepthLog2;*/ 11046628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 110540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca img->IsCompressed = is_compressed_format(ctx, internalFormat); 110689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (img->IsCompressed) 11078f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul img->CompressedSize = ctx->Driver.CompressedTextureSize(ctx, width, 11088f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul height, depth, internalFormat); 110989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else 111089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul img->CompressedSize = 0; 111189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1112887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((width == 1 || _mesa_bitcount(width - 2 * border) == 1) && 1113887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (height == 1 || _mesa_bitcount(height - 2 * border) == 1) && 1114887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (depth == 1 || _mesa_bitcount(depth - 2 * border) == 1)) 1115887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1116887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1117887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1118887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 11198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11208afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11258afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11268afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11288afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11298afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11308afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11316628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11326628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11336628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1134738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1135738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1136738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1137738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1138738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1139738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1140738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1141738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1142738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1143738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1144738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1145738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1146738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1147738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1148738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1149738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1150738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1151738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1152738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1153738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1154738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1155738318bb75dea8dac4465f53850987f6062a732dBrian Paul_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, 1156738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1157738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1158738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1159738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 11609c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1161738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1162738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1163738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1164738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1165738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1166738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1167738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1168738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1169887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1170887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(width - 2 * border) != 1) || 1171738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1172738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or level */ 1173738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1174738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1175738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1176738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1177738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1178738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1179887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1180887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(width - 2 * border) != 1) || 1181738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1182887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1183887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(height - 2 * border) != 1) || 1184738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1185738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1186738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1187738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1188738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1189738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1190738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1191738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1192887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1193887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(width - 2 * border) != 1) || 1194738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1195887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1196887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(height - 2 * border) != 1) || 1197738318bb75dea8dac4465f53850987f6062a732dBrian Paul depth < 2 * border || depth > 2 + maxSize || 1198887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1199887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(depth - 2 * border) != 1) || 1200738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.Max3DTextureLevels) { 1201738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or depth or level */ 1202738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1203738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1204738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1205738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1206738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 1 || width > ctx->Const.MaxTextureRectSize || 1207738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 1 || height > ctx->Const.MaxTextureRectSize || 1208738318bb75dea8dac4465f53850987f6062a732dBrian Paul level != 0) { 1209738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1210738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1211738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1212738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1214738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1216887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1217887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(width - 2 * border) != 1) || 1218738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1219887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1220887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul _mesa_bitcount(height - 2 * border) != 1) || 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxCubeTextureLevels) { 1222738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height */ 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1229738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1232738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 12346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 12356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 12366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 12376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 12386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 12396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 12406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 12416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 12426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 12436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 12446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 12456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 12466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 12476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 12486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 12496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 12506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 12516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 12526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1253afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1254c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1255c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paultexture_error_check( GLcontext *ctx, GLenum target, 1256c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1257c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 12585b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLuint dimensions, 1259c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1260c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1261afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1262738318bb75dea8dac4465f53850987f6062a732dBrian Paul const GLboolean isProxy = is_proxy_target(target); 1263738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 1264714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1265afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1266738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1267738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1268738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1269738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1270738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 12718afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1273738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1274738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1277738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1279738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1280738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1281738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1282738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1283738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1284738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1285738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1286973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1287f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1288f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1289973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1290f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1291f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1292f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1293f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 1294738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1295738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1296738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1297738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 1298738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { 1299738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 1300738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1301738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1302738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, 1, 1, border); 13038afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 13048afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 130508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1306afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1307afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1308afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1309afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 1310738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) { 1311738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 1312738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1313738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1314738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1315738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1316738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 1317738318bb75dea8dac4465f53850987f6062a732dBrian Paul (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1318738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 13198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 13208afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 13218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 13228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1323738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = (width == height) && 1324738318bb75dea8dac4465f53850987f6062a732dBrian Paul ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 1325738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, format, type, 1326738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 13278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1328738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV || 1329738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_TEXTURE_RECTANGLE_NV) { 13308afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 13318afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 13328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 13338afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1334738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1335738318bb75dea8dac4465f53850987f6062a732dBrian Paul GL_PROXY_TEXTURE_RECTANGLE_NV, 1336738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1337738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1338738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 13398afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 13408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 13418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 13428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 13438afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1344afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1345afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 1346738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) { 1347738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_3D, 1348738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1349738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1350738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, depth, border); 13518afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 13528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 135308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1354afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1355afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1356afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1357afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 135808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 1359afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1360afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1361afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1362738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1363c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 13644e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1365738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1366738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1367c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1368afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1369afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1370afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1371738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 137289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1373c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 13744e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 13754e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(internalFormat=0x%x)", 13764e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul dimensions, internalFormat); 1377c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1378afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1379afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1380afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1381738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1382f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 138338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 138438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 138538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 138638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 138789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 13884e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(format or type)", dimensions); 1389c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 139038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1391afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1392afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1393601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 1394714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca colorFormat = is_color_format(format); 1395714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca indexFormat = is_index_format(format); 1396714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca if ((is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1397714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca (is_index_format(internalFormat) && !indexFormat) || 1398601df9c742939c1f77de489561fe3e1d02f49618Brian Paul (is_depth_format(internalFormat) != is_depth_format(format)) || 13991ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul (is_ycbcr_format(internalFormat) != is_ycbcr_format(format)) || 14001ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul (is_depthstencil_format(internalFormat) != is_depthstencil_format(format))) { 1401601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1402601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1403601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(internalFormat/format)"); 1404601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1405601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1406601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1407601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1408601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1409c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1410601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1411601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1412c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 141336b518a7ca98e49d95c3fe54544700004716cdefBrian Paul _mesa_sprintf(message, 1414601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage%d(format/type YCBCR mismatch", dimensions); 1415c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, message); 1416c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1417c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1418d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1419d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1420d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1421d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1422d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1423d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1424d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1425d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1426d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1427d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1428d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 142936b518a7ca98e49d95c3fe54544700004716cdefBrian Paul _mesa_sprintf(message, 1430d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul "glTexImage%d(format=GL_YCBCR_MESA and border=%d)", 1431d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul dimensions, border); 1432d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1433d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1434d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1435d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1436c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1437c5b995066020191982b2315fc45d05e068eee761Brian Paul 1438601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1439601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 1440601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* Only 1D and 2D textures supported */ 1441601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1442601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1443601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 1444601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_2D) { 1445601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1446601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1447601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1448601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1449601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1450601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1451601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1452601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 145340bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (is_compressed_format(ctx, internalFormat)) { 145489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D) { 145589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* OK */ 145689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 145789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (ctx->Extensions.ARB_texture_cube_map && 145889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP || 145989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && 146089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { 146189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* OK */ 146289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 146389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 146489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 146589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 146689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexImage%d(target)", dimensions); 146789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 146889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 146989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 147089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 147189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 147289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 147389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexImage%D(border!=0)", dimensions); 147489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 147589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 147689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 147789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 147889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1479afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1481afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1482afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1483afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 14846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1485c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 14866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 14886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 14896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 14906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 14916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 14926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 14936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 14946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 14956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 14966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 14976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 14986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 14996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 15046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1506c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1507fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 1508c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1509c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1510c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1511c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1514c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *destTex; 1515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1516738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target */ 1517c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 1518738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target != GL_TEXTURE_1D) { 151908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 1520c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1521afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1522c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1523c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 1524738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1525d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target <=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1526738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 1527738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1528738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1529738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1530fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1531d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul else if (ctx->Extensions.NV_texture_rectangle && 1532d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target == GL_TEXTURE_RECTANGLE_NV) { 1533738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.NV_texture_rectangle) { 1534738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1535738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1536738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1537d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1538738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target != GL_TEXTURE_2D) { 153908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1540c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1541afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1542c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1543c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 1544738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target != GL_TEXTURE_3D) { 154508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 1546c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1548c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1549c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 1550738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem( ctx, "invalid dims in texture_error_check" ); 1551c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1552c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1554738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1555738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 15564e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1557c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1558c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1560c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 15614e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 15624e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1563c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1564c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1565c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 15664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 15674e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1568c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1569c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1570c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1571738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1572738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1573c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1574c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1575afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1576f2718b0966f54049056e16e7cca08718341557b2Brian Paul destTex = _mesa_select_tex_image(ctx, texUnit, target, level); 1577f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1578c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1579738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1580738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1581c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1582c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1584c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1585738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1586738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1587c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1588afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1589c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1590738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1591738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1592c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1593c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1594c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1595c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1596738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1597738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1598c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1599afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1600c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1601738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1602738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1603c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1604afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1606c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1607c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 160808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1609c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1610c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 161138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 161208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1613c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1614c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1615afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1617f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 16184e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 16194e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(format or type)", dimensions); 162038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1621c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1622afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 162389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (destTex->IsCompressed) { 162489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul const struct gl_texture_unit *texUnit; 162589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul const struct gl_texture_image *texImage; 162689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 162789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 162889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 162989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D) { 163089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* OK */ 163189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (ctx->Extensions.ARB_texture_cube_map && 163389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP || 163489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && 163589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { 163689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* OK */ 163789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 163989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 164089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(target)", dimensions); 1641e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1642e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 164389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 164489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 1645e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 164689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(xoffset or yoffset)", dimensions); 1647e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1648e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 164989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 or equal to whole texture size */ 1650798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) && (GLuint) width != texImage->Width) { 1651e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 165289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(width)", dimensions); 1653e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 165489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1655798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) && (GLuint) height != texImage->Height) { 165689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 165789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(width)", dimensions); 165889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 165989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1660e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1661e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1662c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1663c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1665afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1667c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 16686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 16706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 16716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 16726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 16736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 16746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 16756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 16766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 16776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 16786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 16806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 16826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 16836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1684afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1685c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1686fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 1687c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1688c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1689afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 16900899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLenum type; 1691738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 16920899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1693afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1694738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1695738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1696738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1697738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage%dD(level=%d)", dimensions, level); 1698738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1699738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1700738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1701738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1702738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1703738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1704738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1705738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1706738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1707738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1708738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 17090899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 17100899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17110899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 17120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 17130899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 17140899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 17150899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* NOTE: the format and type aren't really significant for 17160899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul * TestProxyTexImage(). Only the internalformat really matters. 17170899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul */ 1718738318bb75dea8dac4465f53850987f6062a732dBrian Paul type = GL_FLOAT; 1719738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1720738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1721738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1722738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1723fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1724738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_1D) { 1725738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 1726738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1727738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1728738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, 1, 1, border); 1729738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1730738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 173108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 1732fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1733fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1734c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1735fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1736738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_2D) { 1737738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 1738738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1739738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1740738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1741738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1742738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1743738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 17448afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 17458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 17468afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 17478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1748738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = (width == height) && 1749738318bb75dea8dac4465f53850987f6062a732dBrian Paul ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 1750738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, format, type, 1751738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 17528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 17538afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 17548afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 175508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1756fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1757fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1758738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1759738318bb75dea8dac4465f53850987f6062a732dBrian Paul GL_PROXY_TEXTURE_RECTANGLE_NV, 1760738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1761738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1762738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1763fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1764738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 176508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1766fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1767fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1768c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1769738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1770738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "invalid dimensions in copytexture_error_check"); 1771c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1772c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1773c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1774738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1775738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 17764e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1777738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1779738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1780738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1781738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1782738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1783ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1784c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1785c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 178740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (is_compressed_format(ctx, internalFormat)) { 178889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target != GL_TEXTURE_2D) { 178989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 179089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexImage%d(target)", dimensions); 179189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 179289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 179389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 179489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 179589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexImage%D(border!=0)", dimensions); 179689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 179789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 179889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 17990899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul else if (is_depth_format(internalFormat)) { 18000899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 18010899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (!ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer) { 18020899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18030899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%D(no depth)", dimensions); 18040899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 18050899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 18060899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 18070899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul else if (is_depthstencil_format(internalFormat)) { 18080899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 18090899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (!ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer || 18100899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul !ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer) { 18110899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%D(no depth/stencil buffer)", dimensions); 18130899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 18140899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 18150899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 181689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1817c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1818c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1819c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1821c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 18226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 18236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test glCopyTexImage[12]D() parameters for errors. 18246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 18306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 18316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 18326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 18396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 18406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 1841c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1842fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 1843c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1844c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 18455b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLsizei width, GLsizei height ) 1846c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 1847c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul struct gl_texture_image *teximage; 1849c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1850738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target */ 1851fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1852fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 185308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 1854fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1855fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1856c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1857fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1858fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1859fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1860fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 1861fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1862fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul return GL_TRUE; 1863fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 1864fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 1865fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 1866fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 186708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1868fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1869fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1870fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1871fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 187208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1873fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1874fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1875c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1876fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 1877fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_3D) { 187808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 1879fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1880fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1881c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1882c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1883738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 1884738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 18854e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 18864e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 1887c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1888c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1889c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1890738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check size */ 1891c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 18924e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 18934e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 1894c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1895c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1896c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1 && height < 0) { 18974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 18984e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 1899c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1901c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1902a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul teximage = _mesa_select_tex_image(ctx, texUnit, target, level); 1903c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 19044e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1905b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 1906b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 1907c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1908c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1909c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 19114e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19124e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 1913c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1914c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 191538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 19164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19174e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 1918c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1919c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1920c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1921c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 19224e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19234e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 1924c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1925c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1926c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 192738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 19284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19294e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 1930c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1931c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1932c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1933c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1934c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1935c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 19364e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19374e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 1938c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1939c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 194038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 19414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19424e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 1943c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1944c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1945c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1946c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 194789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (teximage->IsCompressed) { 194889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target != GL_TEXTURE_2D) { 194989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 195089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%d(target)", dimensions); 1951e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1952e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 195389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 195489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 195589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 195689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(xoffset or yoffset)", dimensions); 1957e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1958e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 195989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 1960798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 196189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 196289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(width)", dimensions); 1963e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 196489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1965798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 196689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 196789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(height)", dimensions); 196889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 196989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1970e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1971e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1972d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (teximage->IntFormat == GL_YCBCR_MESA) { 1973d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 1974d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1975d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1976d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 19770899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (teximage->Format == GL_DEPTH_COMPONENT) { 19780899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (!ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer) { 19790899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19800899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexSubImage%D(no depth buffer)", 19810899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 19820899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19830899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19840899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19850899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul else if (teximage->Format == GL_DEPTH_STENCIL_EXT) { 19860899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (!ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer || 19870899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul !ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer) { 19880899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19890899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexSubImage%D(no depth/stencil buffer)", 19900899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 19910899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19920899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19930899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19940899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 1995c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1996c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1997c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1998c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1999c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 20011749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Get texture image. Called by glGetTexImage. 20026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 20046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 20051749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param format pixel data format for returned image. 20061749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param type pixel data type for returned image. 20071749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param pixels returned pixel data. 20086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2009c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 20108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 20118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum type, GLvoid *pixels ) 2012289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul{ 20138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 20148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_object *texObj; 201557aca2bf6e82cdab43575123530fce2ba54bf9c7Brian Paul const struct gl_texture_image *texImage; 2016cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 20172c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 20188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 20198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2020cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 2021cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2022cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (!texObj || is_proxy_target(target)) { 2023cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 2024cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 2025cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2026cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2027ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul maxLevels = _mesa_max_texture_levels(ctx, target); 2028ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 2029cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2030cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 203108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 20328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 2033289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2034289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 203562c36a2ff39d775c1f1bc377b9ddbc69e2340799Brian Paul if (_mesa_sizeof_packed_type(type) <= 0) { 203608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 20378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 20388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 20398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2040f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (_mesa_components_in_format(format) <= 0 || 2041f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul format == GL_STENCIL_INDEX) { 204208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 20438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 20448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 20458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2046f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { 204708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2048f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2049f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 20504618a9bfc2cd57c47ddf3590782c751ec194d362Brian Paul if (!ctx->Extensions.SGIX_depth_texture && 20514618a9bfc2cd57c47ddf3590782c751ec194d362Brian Paul !ctx->Extensions.ARB_depth_texture && is_depth_format(format)) { 205208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2053f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2054f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 20551749a25ca889d514889b34cf6311c8014d97bf66Brian Paul if (!ctx->Extensions.MESA_ycbcr_texture && is_ycbcr_format(format)) { 2056c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2057c5b995066020191982b2315fc45d05e068eee761Brian Paul } 2058c5b995066020191982b2315fc45d05e068eee761Brian Paul 20591ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (!ctx->Extensions.EXT_packed_depth_stencil 20601ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul && is_depthstencil_format(format)) { 20611ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 20621ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 20631ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 20648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!pixels) 20658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 20668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 20678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 20688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!texImage) { 20698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* invalid mipmap level, not an error */ 20708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 20718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 20728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 20731749a25ca889d514889b34cf6311c8014d97bf66Brian Paul /* Make sure the requested image format is compatible with the 20740899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul * texture's format. Note that a color index texture can be converted 20750899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul * to RGBA so that combo is allowed. 20761749a25ca889d514889b34cf6311c8014d97bf66Brian Paul */ 20771749a25ca889d514889b34cf6311c8014d97bf66Brian Paul if (is_color_format(format) 20783cc28c96cd2003f9a598a36520305bba58d6489fDaniel Borca && !is_color_format(texImage->TexFormat->BaseFormat) 20793cc28c96cd2003f9a598a36520305bba58d6489fDaniel Borca && !is_index_format(texImage->TexFormat->BaseFormat)) { 20801749a25ca889d514889b34cf6311c8014d97bf66Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 20811749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return; 20821749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 20831749a25ca889d514889b34cf6311c8014d97bf66Brian Paul else if (is_index_format(format) 20841749a25ca889d514889b34cf6311c8014d97bf66Brian Paul && !is_index_format(texImage->TexFormat->BaseFormat)) { 20851749a25ca889d514889b34cf6311c8014d97bf66Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 20861749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return; 20871749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 20881749a25ca889d514889b34cf6311c8014d97bf66Brian Paul else if (is_depth_format(format) 20890899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul && !is_depth_format(texImage->TexFormat->BaseFormat) 20900899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul && !is_depthstencil_format(texImage->TexFormat->BaseFormat)) { 20911749a25ca889d514889b34cf6311c8014d97bf66Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 20921749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return; 20931749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 20941749a25ca889d514889b34cf6311c8014d97bf66Brian Paul else if (is_ycbcr_format(format) 20951749a25ca889d514889b34cf6311c8014d97bf66Brian Paul && !is_ycbcr_format(texImage->TexFormat->BaseFormat)) { 20961749a25ca889d514889b34cf6311c8014d97bf66Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 20971ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return; 20981ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 20991ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul else if (is_depthstencil_format(format) 21001ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul && !is_depthstencil_format(texImage->TexFormat->BaseFormat)) { 21011ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 21021749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return; 21031749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 21041749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 210568d293b03535ca50daf70650b32db780f1718a3bBrian Paul /* typically, this will call _mesa_get_teximage() */ 210668d293b03535ca50daf70650b32db780f1718a3bBrian Paul ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels, 210768d293b03535ca50daf70650b32db780f1718a3bBrian Paul texObj, texImage); 2108289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul} 2109289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 2110289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 21118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2112289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 2113c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 2114c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2115c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 211643911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2117fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 2118fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 2119c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2120ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2121fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2122cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2123c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2124f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 2125f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2126f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2127f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 21288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 21298c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 2130f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 21310293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 21320293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2133f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2134aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2135f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 1, postConvWidth, 1, 1, border)) { 21368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2137c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2138c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2139f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2141a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 21420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul 21430293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 2144a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 2145a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 21460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 21473e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 21483e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 2149c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 21503e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 2151f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 21528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 21538afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, 1, 1, 21543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 2155c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2156b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 215708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2158fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 21598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage1D); 216062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 216189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* Give the texture to the driver! <pixels> may be null! */ 216262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 216362c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, border, format, type, pixels, 216462c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul &ctx->Unpack, texObj, texImage); 2165c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 216638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 21674f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 21680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 2169a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2170a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2171c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 217238d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2173c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 2174738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2175738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2176738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2177738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1, postConvWidth, 1, 1, border)) { 2178738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2179a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2180a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2181c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 218289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 218389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2184738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(texImage); 218589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 218689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul postConvWidth, 1, 1, 218789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 2188738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2189738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 219089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2191c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2192c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 219308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 2194c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 2195c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2196c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2197c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2198c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2199c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 220043911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2201fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 2202fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2203fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2204c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2205ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2206fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2207cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2208c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2209f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 2210f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 221138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes &postConvHeight); 2212f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2213f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 22148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 2215a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 2216fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 22178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 22188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (ctx->Extensions.NV_texture_rectangle && 22198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target == GL_TEXTURE_RECTANGLE_NV)) { 22208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2221f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 22220293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 22230293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2224f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2225aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2226f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 2, postConvWidth, postConvHeight, 2227f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 1, border)) { 22288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2229c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2230c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2231f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 223235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2233a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 22340293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 2235a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 2236a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 22370293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 22383e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 22393e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 2240c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 22413e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 2242f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 22438afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 22448afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, postConvHeight, 1, 22458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 2246c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2247b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 224808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2249fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 22508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage2D); 225162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 225289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* Give the texture to the driver! <pixels> may be null! */ 225362c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 225462c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, height, border, format, type, pixels, 225562c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul &ctx->Unpack, texObj, texImage); 2256afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 225738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 22584f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 22590293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 2260a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2261a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2262afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2263172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul else if (target == GL_PROXY_TEXTURE_2D || 2264172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 22658afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.ARB_texture_cube_map) || 22668afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (target == GL_PROXY_TEXTURE_RECTANGLE_NV && 22678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.NV_texture_rectangle)) { 2268afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2269738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2270738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2271738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2272738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 2, postConvWidth, postConvHeight, 2273738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1, border)) { 2274738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2275a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 227618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell clear_teximage_fields(ctx->Texture.Proxy2D->Image[0][level]); 2277afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 227889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 227989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 228089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 228189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul postConvWidth, postConvHeight, 1, 228289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 2283738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2284738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 228589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2286afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2287afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 228808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 2289afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2290afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2291afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2292afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2293afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2294afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2295afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2296afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2297afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2298c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2299b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2300fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2301fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2302fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2303afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2304fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2305cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2306afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 23078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_3D) { 2308f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 23090293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 23100293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 23118c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 2312289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 23135535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul if (texture_error_check(ctx, target, level, (GLint) internalFormat, 2314aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul format, type, 3, width, height, depth, border)) { 23158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2316afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2317afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2318f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2320a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 23210293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul if (!texImage) { 2322a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 2323a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 23240293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul } 23253e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 23263e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 2327afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 23283e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 2329f378ab825c0c74aab263e7dec30194eead22c288Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 23308afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 23318afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul width, height, depth, 23328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 2333afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2334b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 233508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2336fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 23378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexImage3D); 233862c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 233989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* Give the texture to the driver! <pixels> may be null! */ 234062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 234162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul width, height, depth, border, format, type, 234262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul pixels, &ctx->Unpack, texObj, texImage); 2343afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 234438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes ASSERT(texImage->TexFormat); 23454f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 23460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul /* state update */ 2347a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2348a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2349afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 235038d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 2351afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2352738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2353738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2354738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2355738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 3, width, height, depth, border)) { 2356738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2357a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2358a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2359afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 236089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 236189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 236289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 236389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 2364738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2365738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 236689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2367afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2368afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 236908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 2370afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2371afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2372afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2373afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2374afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2375c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 237643911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2377663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2378663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2379663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2380663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 238189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2382663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2383663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2384663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2385663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2386afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2387c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2388fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 2389fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 2390fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2391fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2392afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2393ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 23940293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 23950293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 23960293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 23972c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 239875280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 239975280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2400b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 240108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 24022aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2403f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2404f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 2405f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2406f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2407afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2408c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 2409a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, 1, 1, format, type)) { 2410f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2411afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2412afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 24130293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 24148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 24158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 24160293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 2417afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2418529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0) 2419c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 2420afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2421347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2422347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2423347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 24248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage1D); 24258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 24268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, &ctx->Unpack, 24278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 2428bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2429afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2430afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2431afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2432c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2433fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2434fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2435fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2436fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2437fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2438afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2439ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 24400293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 24410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24420293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 24432c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 244475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 244575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2446b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 244708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 24482aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2449f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2450f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(format)) { 2451f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 2452f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 2453f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2454afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2455c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 2456a805bb969199a0f2a5ca7224898a87112ccd2177Brian Paul postConvWidth, postConvHeight, 1, format, type)) { 2457f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2458afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2459afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 24600293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 246135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 24628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 24630293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 2464afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2465529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0 || height == 0) 2466c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 2467afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2468347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2469347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2470347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2471347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 24728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage2D); 24738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 24748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, format, type, pixels, 24758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage); 2476bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2477c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2478afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2479afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2481c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2482fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2483fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2484fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2485fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2486fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2487afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 24880293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 24890293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 24912c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 249275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 249375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2494b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 249508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 24962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2497c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 2498c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 2499f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2500afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2501afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 25020293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 25048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 25050293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul assert(texImage); 2506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2507529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0 || height == 0 || height == 0) 2508c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; /* no-op, not an error */ 2509afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2510347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2511347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2512347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2513347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul zoffset += texImage->Border; 2514347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 25158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TexSubImage3D); 25168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.TexSubImage3D)(ctx, target, level, 25178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 25188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 25198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, type, pixels, 25208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul &ctx->Unpack, texObj, texImage ); 2521bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2522afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2523afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2525afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2526c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2527fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 2528fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 2529fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 2530fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 2531afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 25322aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 25332aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 25342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2535ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2536fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2537cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2539b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 254008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2541fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2542f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 2543f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2544f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2545ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2546ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 2547ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, 1, border)) 2548ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2549ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 25502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25512aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2552a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 25532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 2554a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 2555a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 25562aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 25573e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 25583e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 25592aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 25603e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 25617dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 25622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 25638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1, 25643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 25657dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 25662aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 25672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage1D); 25682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, 25692aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, border); 25702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2571e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->TexFormat); 25724f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 25732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 25742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 25752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 2576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2577afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2578afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2579afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2580c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2581fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 2582fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 2583fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 2584afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 25852aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 25862aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 25872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2588ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2589fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2590cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2592b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 259308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2594fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2595f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (is_color_format(internalFormat)) { 2596f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 2597f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 2598f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2599ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2600ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 2601ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight, border)) 2602ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2603ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 26042aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26052aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2606a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 26072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul if (!texImage) { 2608a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 2609a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 26102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 26113e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 26123e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 26132aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul } 26143e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 26157dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 26162aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul clear_teximage_fields(texImage); /* not really needed, but helpful */ 26178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 26188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul postConvWidth, postConvHeight, 1, 26193893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 2620afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26212aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 26222aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, 26232aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height, border); 26242aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2625e116d3b3e55a70ceb4af270ecd1b614117f631a2Brian Paul ASSERT(texImage->TexFormat); 26264f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 26272aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul /* state update */ 26282aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj->Complete = GL_FALSE; 26292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ctx->NewState |= _NEW_TEXTURE; 2630afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2631afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2632afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2633afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2634c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2635fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 2636fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 2637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2638347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2639347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2640ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2641fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2642cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2644b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 264508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2646fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2647f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 26488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2649ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2650ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 1, target, level, 2651ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul xoffset, 0, 0, postConvWidth, 1)) 2652ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2653ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2654347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2655347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2656a3f137094cd965d27e1b088499dd609b81a91906Brian Paul ASSERT(texImage); 2657347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2658347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2659347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2660347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 26612aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage1D); 26622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width); 2663bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2665afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2667afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2668c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2669fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2670fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2671fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2672afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2673347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2674347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2675ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2676fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2677cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2679b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 268008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2681fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2682f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2683f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 2684ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2685ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 2686ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight)) 2687ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2688ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2689347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2690347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2691a3f137094cd965d27e1b088499dd609b81a91906Brian Paul ASSERT(texImage); 2692347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2693347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2694347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2695347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2696347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 26972aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage2D); 26982aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 26992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, x, y, width, height); 2700bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2701afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2705c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2706fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2707fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2708fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2709afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2710347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 2711347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 2712ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2713fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2714cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2716b23f5b5a5ccf5910f1d11d749c2e440e6a46259bBrian Paul if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 271708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2718fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2719f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 2720f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 2721ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2722ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, 2723ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul zoffset, postConvWidth, postConvHeight)) 2724ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2725ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2726347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2727347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2728a3f137094cd965d27e1b088499dd609b81a91906Brian Paul ASSERT(texImage); 2729347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2730347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2731347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul xoffset += texImage->Border; 2732347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul yoffset += texImage->Border; 2733347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul zoffset += texImage->Border; 2734347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 27352aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul ASSERT(ctx->Driver.CopyTexSubImage3D); 27362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 27372aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul xoffset, yoffset, zoffset, 27382aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul x, y, width, height); 2739bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 2740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 27411207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 27421207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 27431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 274489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 274589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 274689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 274789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 274889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 274989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 275089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 275189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 275289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 275389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 275489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 275589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulcompressed_texture_error_check(GLcontext *ctx, GLint dimensions, 275689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 275789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 275889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 275989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei imageSize) 276089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 276189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 276289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 276389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 276489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 276589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 276689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 276789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 276889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 276989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 277089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 277189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 277289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 277389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 277489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 277589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 277689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 277789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 277889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 277989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 278089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 278189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 278289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 278389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 278489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 278589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 278689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 278789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 278889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 278989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 279089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 279189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 279289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 279389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 279489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 279589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 279640bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (!is_compressed_format(ctx, internalFormat)) 279789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 279889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2799a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick if (_mesa_base_tex_format(ctx, internalFormat) < 0) 2800a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 2801a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 280289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) 280389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 280489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2805887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul /* 2806887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * XXX We should probably use the proxy texture error check function here. 2807887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul */ 2808887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize || 28092982dce27e242c89e4bc99979a878263df33ad2fDaniel Borca (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(width) != 1)) 281089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 281189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2812887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize || 28132982dce27e242c89e4bc99979a878263df33ad2fDaniel Borca (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(height) != 1)) 281489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 281589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 281689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2817887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((depth < 1 || depth > maxTextureSize || 28182982dce27e242c89e4bc99979a878263df33ad2fDaniel Borca (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(depth) != 1)) 281989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 2) 282089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 282189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 282289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 282389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 282489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 282589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 282689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 282789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 282889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 282989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 28308f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul expectedSize = ctx->Driver.CompressedTextureSize(ctx, width, height, depth, 28318f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul internalFormat); 283289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 283389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 283489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 283589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 283689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 283789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 283889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 283989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 284089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 28412371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 28422371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 28432371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 284489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 284589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 284689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 284789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulcompressed_subtexture_error_check(GLcontext *ctx, GLint dimensions, 284889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 284989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 285089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 285189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 285289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 285389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 2854a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 285589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 285689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 285789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 285889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 285989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 286089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 286189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 286289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 286389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 286489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 286589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 286689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 286789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 286889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 286989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 287089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 287189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 287289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 287389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 287489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 287589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 287689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 287789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 287889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 287989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 288089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 288189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 288289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 288389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 288489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 288589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 288689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 288789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 288889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 288940bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (!is_compressed_format(ctx, format)) 289089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 289189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2892887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 289389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 289489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2895887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 289689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 289789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 289889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 289989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 290089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 290189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 29022371033bbaf6e7477bfa893654a0467a084f335bBrian Paul /* XXX these tests are specific to the compressed format. 29032371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * this code should be generalized in some way. 29042371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 290589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) != 0 || (yoffset & 3) != 0) 290689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 290789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 290889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((width & 3) != 0 && width != 2 && width != 1) 290989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 291089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 291189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((height & 3) != 0 && height != 2 && height != 1) 291289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 291389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 29148f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul expectedSize = ctx->Driver.CompressedTextureSize(ctx, width, height, depth, 29158f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul format); 291689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 291789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 291889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 291989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 292089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 292189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 292289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 292389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2924c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 29251207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 2926aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 29271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 29281207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 29291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 2930aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 2931cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2932aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2933aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 29348c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 2935aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 2936aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 2937aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 293889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 293989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 294089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 294189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage1D"); 294289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 2943aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2944aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2945aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 29468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 2947a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 2948aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 2949a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D"); 2950a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 2951aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 29523e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 29533e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 2954aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 29553e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 2956aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 29578afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 29583893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul border, internalFormat); 29596628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 296089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 296189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 296289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, border, 296389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul imageSize, data, 296489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texObj, texImage); 2965aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 2966aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 2967a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 2968a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 2969aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2970aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2971aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 297289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 297389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 29748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 29758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 297638d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 297738d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 297838d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 297938d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 298038d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 2981aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 2982a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 2983a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2984a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2985a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2986aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 298789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 298889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 298989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 299089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 299189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 299289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 299389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 299489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 299589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2996aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 2997aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 299889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1D(target)"); 2999aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3000aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 30011207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 30021207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 30031207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3004c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 30051207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 3006aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 30071207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 30081207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 30091207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3010aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3011cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3012aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 30138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 3014a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 30159540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 301689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 30178c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3018aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 3019aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3020aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 302189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 302289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 302389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 302489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage2D"); 302589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3026aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3027aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3028aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3030a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 3031aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 3032a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); 3033a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 3034aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 30353e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 30363e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 3037aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 30383e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 3039aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 30408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 30418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 30426628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 304389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 304489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 304589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 304689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, imageSize, data, 304789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texObj, texImage); 3048aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3049aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 3050a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 3051a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 3052aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 305389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_2D || 305489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 305589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ctx->Extensions.ARB_texture_cube_map)) { 3056aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 305789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 305889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 30598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 30608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 306138d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 306238d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 306338d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 306438d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 306538d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3066aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3067a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3068a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3069a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3070a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3071aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 307289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 307389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 307489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 307589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 307689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 307789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 307889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 307989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 308089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3081aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3082aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 308389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(target)"); 3084aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3085aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 30861207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 30871207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 30881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3089c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 30901207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 3091aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 30921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 30931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 30941207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3095aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3096cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3097aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 30989540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 30998c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3100aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 3101aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3102aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 310389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 310489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 310589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 310689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage3D"); 310789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3108aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3109aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3110aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 31118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3112a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 3113aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (!texImage) { 3114a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D"); 3115a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return; 3116aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 31173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell else if (texImage->Data) { 31183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 3119aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 31203e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 3121aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 31228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, depth, 31238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul border, internalFormat); 31246628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 312589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 312689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 312789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, 312889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul width, height, depth, 312989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, imageSize, data, 313089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texObj, texImage); 3131aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3132aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* state update */ 3133a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul texObj->Complete = GL_FALSE; 3134a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell ctx->NewState |= _NEW_TEXTURE; 3135aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3136aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 3137aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 313889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 313989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 31408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 31418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 314238d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 314338d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 314438d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 314538d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 314638d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3147aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3148a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3149a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3150a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3151a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3152aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 315389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 315489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 315589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 315689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 315789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 315889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 315989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 316089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul depth, border, internalFormat); 316189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3162aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3163aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 316489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3D(target)"); 3165aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3166aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 31671207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 31681207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 31691207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3170c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 31711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 31721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei width, GLenum format, 31731207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 31741207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 31759540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 31769540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 31779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 317889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3179a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 318075280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 318175280a2c742ee241d392618a3b29548fce1520a9Brian Paul 318289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 1, target, level, 318389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul xoffset, 0, 0, width, 1, 1, format, imageSize); 318489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 318589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexSubImage1D"); 318689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 31879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 31889540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 31899540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 31909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 31918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 31929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 31939540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3194798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((GLint) format != texImage->IntFormat) { 319589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 319689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCompressedTexSubImage1D(format)"); 319789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 319889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 319989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3200798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width == 1 || width == 2) && (GLuint) width != texImage->Width) { 320189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage1D(width)"); 320289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 320389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 320489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3205529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0) 32069540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 32079540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 32089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage1D) { 32098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 32108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, width, 32118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 32128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 32139540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 3214bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 32151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 32161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3218c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 32191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 32201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 32211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 32221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 32231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32249540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 32259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 32269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 322789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3228a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 322975280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 323075280a2c742ee241d392618a3b29548fce1520a9Brian Paul 323189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 2, target, level, 323289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul xoffset, yoffset, 0, width, height, 1, format, imageSize); 323389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 3234b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul /* XXX proxy target? */ 323589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexSubImage2D"); 323689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 32379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 32389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 32399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 32409540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 32418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 32429540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 32439540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3244798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((GLint) format != texImage->IntFormat) { 324589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 324689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCompressedTexSubImage2D(format)"); 324789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 324889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 324989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3250798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 3251798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz ((height == 1 || height == 2) && (GLuint) height != texImage->Height)) { 325289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage2D(size)"); 325389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 325489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 325589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3256529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0 || height == 0) 32579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 32589540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 32599540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage2D) { 32608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 32618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, width, height, 32628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 32638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 32649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 3265bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 32661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 32671207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32681207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3269c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 32701207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 32711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 32721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 32731207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 32741207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32759540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 32769540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 32779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 327889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3279a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 328075280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 328175280a2c742ee241d392618a3b29548fce1520a9Brian Paul 328289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 3, target, level, 328389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul xoffset, yoffset, zoffset, width, height, depth, format, imageSize); 328489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 328589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexSubImage2D"); 328689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 32879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 32889540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 32899540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 32909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 32918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 32929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul assert(texImage); 32939540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3294798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((GLint) format != texImage->IntFormat) { 329589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 329689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCompressedTexSubImage3D(format)"); 329789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 329889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 329989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3300798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 3301798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz ((height == 1 || height == 2) && (GLuint) height != texImage->Height) || 3302798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz ((depth == 1 || depth == 2) && (GLuint) depth != texImage->Depth)) { 330389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage3D(size)"); 330489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 330589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 330689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3307529e0a98d477e33f41f680926f8b9c745aebbe90Brian Paul if (width == 0 || height == 0 || depth == 0) 33089540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; /* no-op, not an error */ 33099540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 33109540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (ctx->Driver.CompressedTexSubImage3D) { 33118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 33128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul xoffset, yoffset, zoffset, 33138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul width, height, depth, 33148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul format, imageSize, data, 33158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj, texImage); 33169540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 3317bf8b5f99a11ad43bb3404ed4ae04eceb3027bbabBrian Paul ctx->NewState |= _NEW_TEXTURE; 33181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 33191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 33201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3321c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 33229540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 33231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 33248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 33259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul const struct gl_texture_object *texObj; 33269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 3327cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels; 3328a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 3329cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 33309540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3331cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 3332cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3333cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (!texObj) { 3334cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB"); 3335cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 3336cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 3337cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 3338ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul maxLevels = _mesa_max_texture_levels(ctx, target); 3339ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 3340cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 3341cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 3342cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 33439540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 33449540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 33459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 33468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (is_proxy_target(target)) { 334708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 33488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 33499540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 33509540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 33518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 33529540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage) { 3353e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul /* probably invalid mipmap level */ 335408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 33559540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 33569540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 33579540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 33589540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (!texImage->IsCompressed) { 335908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); 33609540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 33619540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 33629540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 336368d293b03535ca50daf70650b32db780f1718a3bBrian Paul /* this typically calls _mesa_get_compressed_teximage() */ 336468d293b03535ca50daf70650b32db780f1718a3bBrian Paul ctx->Driver.GetCompressedTexImage(ctx, target, level, img, texObj,texImage); 33651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3366