teximage.c revision 8a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian * mesa 3-D graphics library 380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Version: 7.5 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 59f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 33fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 34b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 3634a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 37f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul#include "convolve.h" 3834a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 3934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 4034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 412897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.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{ 8071f71c2c8ab0b8af95cddc99df5dd01e4ca6af68Brian Paul#if CHAN_TYPE != GL_UNSIGNED_BYTE 8171f71c2c8ab0b8af95cddc99df5dd01e4ca6af68Brian Paul _mesa_problem(NULL, "PrintTexture not supported"); 82f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#else 83b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul GLuint i, j, c; 8471f71c2c8ab0b8af95cddc99df5dd01e4ca6af68Brian Paul const GLubyte *data = (const GLubyte *) 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 } 124ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul /* XXX use img->ImageStride here */ 1253c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul _mesa_printf("\n"); 126b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul } 127f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif 1284827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul} 1294827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul#endif 1304827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 1314827179cc0d314f69671e97dcb016f5a3b90a213Brian Paul 132f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 133887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)). 134973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1. 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 136fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 137fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 142973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n < 0) 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 144973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul 145973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n == 0) 146973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul return 0; 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 153887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul return log2 - 1; 154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1631749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 1641749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1671749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 17189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 17289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 17389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 175b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 1761749a25ca889d514889b34cf6311c8014d97bf66Brian Paul_mesa_base_tex_format( GLcontext *ctx, GLint internalFormat ) 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1781749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 181afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 182afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 186afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 187afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 189afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 190afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 191afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 194afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 196afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 197afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 198afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 199afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 200afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 201afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 202afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 203afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 204afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 208afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 209afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 210afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 211afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 212afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 213afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 214afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 215afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 216afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 217afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 218afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 219afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 220afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 221afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 222afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 223afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 224afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 225afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 226afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 234f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 240e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 242f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 2464741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 2494741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 2504741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 2514741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 252f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 25789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 25833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 25933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 26033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 26133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 26233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 26333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 26433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 26533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 26633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 26733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 26833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 26933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 27033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 27133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 27233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 275f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 27889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 28089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 282f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2888f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2898f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 290f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 291f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 292f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 29340bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 294f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 295f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 296f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 297f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 298f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 299f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 300f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 301f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 302f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 303663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 304f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 305f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 306663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 307f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 308f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 309f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 310f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 31189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 313f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 314f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 315f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 3161749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 317f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 318f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 319f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 320f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 321f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 322f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 323f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 324f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 325f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 326f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 327f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 328f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 329f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 330f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 331f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 332f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 333f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 334f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 335f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 336f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 337f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 3388f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 339f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 340afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 341f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 342114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 343114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 344114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 345114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 346114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 347114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 348114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 349114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 350114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 351114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 352114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3531ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3541ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3551ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3561ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3571ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3581ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3591ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3601ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3611ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3621ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3630a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3640a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3650a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3660a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3670a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3680a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3690a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3700a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3710a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3720a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3730a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3740a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3750a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3760a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3770a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3780a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3790a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3800a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_EXT: 3810a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3820a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3830a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3840a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3850a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3860a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 3870a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul ; /* fallthrough */ 3880a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3890a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3900a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 3910a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3920a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 393f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 394afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 395afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 396afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 3983405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a color/RGBA format (i.e., not color 3993405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * index, depth, stencil, etc). 4003405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * \param format the image format value (may by an internal texture format) 4011749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. 40222e442544bc451f114288f07cf9cc1584ca357a1Brian Paul * XXX maybe move this func to image.c 403f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul */ 40422e442544bc451f114288f07cf9cc1584ca357a1Brian PaulGLboolean 40522e442544bc451f114288f07cf9cc1584ca357a1Brian Paul_mesa_is_color_format(GLenum format) 406f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 4073405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 408ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_RED: 409ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_GREEN: 410ebe8d3152d864b9f4a0501c868c54e472c9d67a4Brian Paul case GL_BLUE: 411f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA: 412f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA4: 413f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA8: 414f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA12: 415f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_ALPHA16: 416f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 1: 417f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE: 418f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4: 419f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8: 420f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12: 421f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16: 422f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 2: 423f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE_ALPHA: 424f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE4_ALPHA4: 425f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE6_ALPHA2: 426f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE8_ALPHA8: 427f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA4: 428f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE12_ALPHA12: 429f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_LUMINANCE16_ALPHA16: 430f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY: 431f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY4: 432f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY8: 433f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY12: 434f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_INTENSITY16: 435f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 3: 436f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB: 437beef59e73aad91ca52d72fd0224e696826038318Brian Paul case GL_BGR: 438f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_R3_G3_B2: 439f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB4: 440f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5: 441f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB8: 442f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10: 443f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB12: 444f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB16: 445f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case 4: 446f252f64430ccb957698fcf85e84c9d64008147ebBrian Paul case GL_ABGR_EXT: 447f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA: 448beef59e73aad91ca52d72fd0224e696826038318Brian Paul case GL_BGRA: 449f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA2: 450f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA4: 451f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB5_A1: 452f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA8: 453f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGB10_A2: 454f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA12: 455f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_RGBA16: 456f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul /* float texture formats */ 457f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 458f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 459f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 460f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 461f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 462f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 463f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 464f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 465f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 466f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 467f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 468f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 4693405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul /* compressed formats */ 4703405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_ALPHA: 4713405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_LUMINANCE: 4723405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_LUMINANCE_ALPHA: 4733405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_INTENSITY: 4743405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB: 4753405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA: 476997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGB_S3TC: 477997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGB4_S3TC: 478997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGBA_S3TC: 479997e81fe75ce32ed3d8bb4d8f73a226644cf3a2fRoland Scheidegger case GL_RGBA4_S3TC: 4803405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 4813405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 4823405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 4833405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 4843405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 4853405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 4860a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 4870a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 4880a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 4890a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 4900a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 4910a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 4920a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 4930a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 4940a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 4950a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 4960a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 4970a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 4980a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 4990a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 5000a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 5010a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_EXT: 5020a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 5030a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 504f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 505c5b995066020191982b2315fc45d05e068eee761Brian Paul case GL_YCBCR_MESA: /* not considered to be RGB */ 50622e442544bc451f114288f07cf9cc1584ca357a1Brian Paul /* fall-through */ 507f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 508f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 509f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 510f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 511f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 512f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 5136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5143405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a color index format. 5156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 516f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paulstatic GLboolean 5173405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_index_format(GLenum format) 518f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul{ 5193405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 520f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX: 521f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX1_EXT: 522f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX2_EXT: 523f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX4_EXT: 524f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX8_EXT: 525f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX12_EXT: 526f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul case GL_COLOR_INDEX16_EXT: 527f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_TRUE; 528f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul default: 529f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_FALSE; 530f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 531f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul} 532f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 53489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 5353405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a depth component format. 5361749a25ca889d514889b34cf6311c8014d97bf66Brian Paul */ 5371749a25ca889d514889b34cf6311c8014d97bf66Brian Paulstatic GLboolean 5383405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_depth_format(GLenum format) 5391749a25ca889d514889b34cf6311c8014d97bf66Brian Paul{ 5403405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 5414741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 5424741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 5434741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 5441749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_DEPTH_COMPONENT: 5451749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_TRUE; 5461749a25ca889d514889b34cf6311c8014d97bf66Brian Paul default: 5471749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_FALSE; 5481749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 5491749a25ca889d514889b34cf6311c8014d97bf66Brian Paul} 5501749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5511749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5521749a25ca889d514889b34cf6311c8014d97bf66Brian Paul/** 5533405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul * Test if the given image format is a YCbCr format. 5541749a25ca889d514889b34cf6311c8014d97bf66Brian Paul */ 5551749a25ca889d514889b34cf6311c8014d97bf66Brian Paulstatic GLboolean 5563405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paulis_ycbcr_format(GLenum format) 5571749a25ca889d514889b34cf6311c8014d97bf66Brian Paul{ 5583405708e21ae36ce3ea92bbaea900bacc70a0034Brian Paul switch (format) { 5591749a25ca889d514889b34cf6311c8014d97bf66Brian Paul case GL_YCBCR_MESA: 5601749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_TRUE; 5611749a25ca889d514889b34cf6311c8014d97bf66Brian Paul default: 5621749a25ca889d514889b34cf6311c8014d97bf66Brian Paul return GL_FALSE; 5631749a25ca889d514889b34cf6311c8014d97bf66Brian Paul } 5641749a25ca889d514889b34cf6311c8014d97bf66Brian Paul} 5651749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5661749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 5671749a25ca889d514889b34cf6311c8014d97bf66Brian Paul/** 5681ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul * Test if the given image format is a Depth/Stencil format. 5691ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul */ 5701ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paulstatic GLboolean 5711ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paulis_depthstencil_format(GLenum format) 5721ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul{ 5731ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (format) { 5741ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 5751ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 5761ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_TRUE; 5771ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 5781ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_FALSE; 5791ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 5801ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul} 5811ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 582114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger/** 583114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger * Test if the given image format is a dudv format. 584114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger */ 585114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggerstatic GLboolean 586114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggeris_dudv_format(GLenum format) 587114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger{ 588114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (format) { 589114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 590114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 591114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_TRUE; 592114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 593114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_FALSE; 594114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 595114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger} 5961ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 5971ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 5981ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul/** 5996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if it is a supported compressed format. 6006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat the internal format token provided by the user. 6026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \ret GL_TRUE if \p internalFormat is a supported compressed format, or 6046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_FALSE otherwise. 6056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX 6076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * are supported. 608aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 609aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paulstatic GLboolean 61040bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borcais_compressed_format(GLcontext *ctx, GLenum internalFormat) 611aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 612c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul GLint supported[100]; /* 100 should be plenty */ 613c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul GLuint i, n; 614c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 615008ed1df83735c72c2731c509a3665938d3c7209Brian Paul n = _mesa_get_compressed_formats(ctx, supported, GL_TRUE); 616c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul ASSERT(n < 100); 617c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul for (i = 0; i < n; i++) { 618c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul if ((GLint) internalFormat == supported[i]) { 619e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 620c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul } 621e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 622c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul return GL_FALSE; 623aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 624aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 625aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 626e93243f8b7d43695654a36334c8cc5cea140d23cBrian/** 627e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 628e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 629e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 630e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 631e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 632519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 633519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 634519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 635519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 636519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 637519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 638519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 639519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 640519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 641519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 6426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 6448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 6456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 6496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 6506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 6533893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 6543893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 6553893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 6563893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 657fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 658fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 659fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 660e93243f8b7d43695654a36334c8cc5cea140d23cBrian /* XXX simplify this with _mesa_tex_target_to_face() */ 661fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 6629228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_1D: 663fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 6649228e17bb5bf219269daeed5cbfdd912c118e926Brian Paul case GL_TEXTURE_3D: 665bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 666bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 66718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell tObj->Image[0][level] = texImage; 668a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul break; 669fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 670fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 671fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 672fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 673fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 6740d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 6750d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul { 6760d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul GLuint face = ((GLuint) target - 6770d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 6780d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul tObj->Image[face][level] = texImage; 6790d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul } 6800d22b9054094c863062c7787b45e1fb4d3834a67Brian Paul break; 6818afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 6828afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ASSERT(level == 0); 68318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell tObj->Image[0][level] = texImage; 684a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul break; 685fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 6863893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul _mesa_problem(NULL, "bad target in _mesa_set_tex_image()"); 687fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return; 688fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 689a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 690a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 691fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 692fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 693fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 694a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 6956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 6966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 697a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 698a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 6996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 7016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 70277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 70377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 704a3f137094cd965d27e1b088499dd609b81a91906Brian Paul_mesa_new_texture_image( GLcontext *ctx ) 70577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 706a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 70777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 70877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 70977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 71077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 711a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 7123e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 7134cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 7143e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 7153e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * \param teximage texture image. 7163e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 7173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 7183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 7193e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 7204cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texture_image_data(GLcontext *ctx, 7214cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 7223e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 723c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 724c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 7253e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 7263e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 7274cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 7283e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 7293e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 7303e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 7313e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 7323e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 7333e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 7343e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 7356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 7366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param teximage texture image. 7386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7393e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 740a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 74177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 7423e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell_mesa_delete_texture_image( GLcontext *ctx, struct gl_texture_image *texImage ) 74377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 7445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 7455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 7465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 7475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.FreeTexImageData); 7485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 7495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 7503e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 751b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 752b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul _mesa_free(texImage->ImageOffsets); 753b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul _mesa_free(texImage); 75477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 75577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 75677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 7576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 7586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 7596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 763aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 76477ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 76577ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 766aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 7678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 7688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 7698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 77027f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 771bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 772bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 773bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 774aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 775aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 776aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 7776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 7786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the texture object that corresponds to the target of the given texture unit. 7796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 7826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 7856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 78735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 78835d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 78901e54753ff2bc1831359b04a1906f462d39f33e1Brian Paul_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 79035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 79135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 79235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 79335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7949818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 79535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 796fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 79735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7989818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 79935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 800fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 80135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 8029818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 80335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 804fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 80535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 80635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 80735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 80835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 80935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 81035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 8115ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 812a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 8139818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 81435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 815a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 816fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 8178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 8188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 8199818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 8208afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 8218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 822fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 823bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 824bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 8259818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 826bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 827bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 828fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 829bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 830bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 8319818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 832bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 833bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 834fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 83535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 83608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 83735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 83835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 83935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 84035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 84135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 8426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 8436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the texture image struct which corresponds to target and level 8446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * of the given texture unit. 8456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 8476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 8486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 8496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 8506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture image structure on success, or NULL on failure. 8526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 854fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 855fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 8565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_object *texObj, 8575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 858fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 8595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texObj); 8605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (level < 0 || level >= MAX_TEXTURE_LEVELS) 8625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 864e93243f8b7d43695654a36334c8cc5cea140d23cBrian /* XXX simplify this with _mesa_tex_target_to_face() */ 865fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul switch (target) { 866fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_1D: 867fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_1D: 868fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_2D: 869fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_2D: 870fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_3D: 871fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_3D: 8725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return texObj->Image[0][level]; 8735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 874fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 875fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 876fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 877fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 878fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 87918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 88018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell if (ctx->Extensions.ARB_texture_cube_map) { 88118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell GLuint face = ((GLuint) target - 88218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 8835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return texObj->Image[face][level]; 88418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell } 885fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 886fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 8875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 888fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 889a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell if (ctx->Extensions.ARB_texture_cube_map) 8905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return texObj->Image[0][level]; 891fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else 892fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 8935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 8958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 8965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (ctx->Extensions.NV_texture_rectangle && level == 0) 8975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return texObj->Image[0][level]; 8985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else 8998afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return NULL; 9005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 901bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 902bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 903bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 904bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 905bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return (ctx->Extensions.MESA_texture_array) 906bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick ? texObj->Image[0][level] : NULL; 907bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 908fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul default: 909fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return NULL; 910fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 911fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 912fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 913fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 914a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 915a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 916a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 917a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 918a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 919a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 9205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell_mesa_get_tex_image(GLcontext *ctx, struct gl_texture_object *texObj, 921a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 922a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 923a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 9245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 9255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 9265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 9275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 9285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 929a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 930a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 931a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 932a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 933a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 934a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 9355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 936a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 937a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 9385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 939a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 940a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 941a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 942a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 943a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 944a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 945a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 946a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 947a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 948a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 949a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 950a3f137094cd965d27e1b088499dd609b81a91906Brian Paul_mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level) 951a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 952a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 95380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 954a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 955a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 956a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 957a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 958a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 959a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 960a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 961a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 96280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 96380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 964a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 965a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 966a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 96780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 96880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 969a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 970a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 971a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 97280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 97380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 974a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 975a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 976a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 97780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 97880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 979a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 980a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 981a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 98280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 98380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 984bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 985bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 986bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 98780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 98880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 989bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 990bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 991bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 99280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 99380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 994a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 995a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 996a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 99780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 99880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 99980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 100080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 100180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 100280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 100380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 100480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 100580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 100680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 100780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 100880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 100980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 1010a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 1011a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 1012a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 10136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 10156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 10176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 10186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 10206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 10216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 1023ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 1024ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 1025ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul_mesa_max_texture_levels(GLcontext *ctx, GLenum target) 1026ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 1027ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 1028ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 1029ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 1030ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 1031ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 1032bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 1033bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1034bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 1035bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1036ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 1037ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 1038ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 1039ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 1040ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 1041ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 1042ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 1043ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 1044ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 1045ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 1046add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 1047ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1048ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxCubeTextureLevels; 1049ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1050ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1051ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 1; 1052ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 1053ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 1054ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 1055ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 1056ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 1057ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 1058fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 105962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 1060f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 1061afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 1062afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 10638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 1064afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 10668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 1067afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 10688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 10698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 10708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 1071afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1072a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 1073afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 1074afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 1075afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 1076afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 1077afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 107965d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1080afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1081afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1082afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1083afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1084afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1085afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1086afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1087afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1088afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1089afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 11008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1105a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 11068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 11078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 110962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1113738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1114f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 11156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 11176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11189c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 11199c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1120f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1121f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1122f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 11239c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 11249c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1125f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 11269c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 11279c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1128a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1129a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 11309c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 11319c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 11329c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 11339c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1134681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1135b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 1136b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul _mesa_free(img->ImageOffsets); 1137b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1138b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 11399c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 11409c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 11419c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 11429c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 11439c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 11449c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 11459c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 11462c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes img->TexFormat = &_mesa_null_texformat; 11474f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 11484f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 11499c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->IsCompressed = 0; 11509c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->CompressedSize = 0; 11519c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 11529c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 11539c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 11546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 11556628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 11566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1158b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 11596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 11606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 11616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 11626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 11636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 11646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 11656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1167887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 11686628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 11693893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 11708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul_mesa_init_teximage_fields(GLcontext *ctx, GLenum target, 11713893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 11723893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 11733893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLint border, GLenum internalFormat) 11746628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 1175b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul GLint i; 1176b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11776628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11788bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11798bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11808bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1181b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1182a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1183a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1184a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11856628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11866628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11876628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11886628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1189c813b545ab4726fc5030f123ec6255224d64ad82Brian 11904d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 11914d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->WidthLog2 = logbase2(img->Width2); 1192c813b545ab4726fc5030f123ec6255224d64ad82Brian 1193c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1194c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 11956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1196c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1197c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1198c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 11994d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->HeightLog2 = logbase2(img->Height2); 1200c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1201c813b545ab4726fc5030f123ec6255224d64ad82Brian 1202c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1203c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 12046628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1205c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1206c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1207c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 12084d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->DepthLog2 = logbase2(img->Depth2); 1209c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1210c813b545ab4726fc5030f123ec6255224d64ad82Brian 12116628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1212c813b545ab4726fc5030f123ec6255224d64ad82Brian 12135999c5b620236fb6a996cf56759aec31f01c126bBrian Paul img->IsCompressed = GL_FALSE; 12145999c5b620236fb6a996cf56759aec31f01c126bBrian Paul img->CompressedSize = 0; 121589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1216be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1217be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1218be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1219887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1220887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1221887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1222887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1223b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1224b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1225b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1226b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1227b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1228b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1229b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = (GLuint *) _mesa_malloc(depth * sizeof(GLuint)); 1230b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1231b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1232b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1233b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 12348afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 12358afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 12368afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 12378afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 12388afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 12398afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 12408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 12418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 12428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 12438afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 12448afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 12458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 12466628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 12476628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 12486628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1249738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1250738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1251738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1252738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1253738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1254738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1255738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1256aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1257aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1258aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1259aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1260738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1261738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1262738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1263738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1264738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1265738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1266738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1267738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1268738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1269738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1270738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1271738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1273738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1274738318bb75dea8dac4465f53850987f6062a732dBrian Paul_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1277738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12799c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1280738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1281738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1282738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1283738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1284738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1285738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1286738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1287738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1288887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1289be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width >0 && !_mesa_is_pow_two(width - 2 * border)) || 1290738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1291738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or level */ 1292738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1293738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1294738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1295738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1296738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1297738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1298887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1299be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1300738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1301887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1302be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1303738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1304738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1305738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1306738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1307738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1308738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1309738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1310738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1311887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1312be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1313738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1314887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1315be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1316738318bb75dea8dac4465f53850987f6062a732dBrian Paul depth < 2 * border || depth > 2 + maxSize || 1317887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1318be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) || 1319738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.Max3DTextureLevels) { 1320738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or depth or level */ 1321738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1322738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1323738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1324738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1325aa328291c5b015e74ebfd9c5cdb39227265b3000Brian if (width < 0 || width > ctx->Const.MaxTextureRectSize || 1326aa328291c5b015e74ebfd9c5cdb39227265b3000Brian height < 0 || height > ctx->Const.MaxTextureRectSize || 1327738318bb75dea8dac4465f53850987f6062a732dBrian Paul level != 0) { 1328738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1329738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1330738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1331738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1332738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1333738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1334738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1335887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1336be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1337738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1338887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1339be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1340738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxCubeTextureLevels) { 1341738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height */ 1342738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1343738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1344738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1345bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1346bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1347bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (width < 2 * border || width > 2 + maxSize || 1348bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1349be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1350bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level >= ctx->Const.MaxTextureLevels) { 1351bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick /* bad width or level */ 1352bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1353bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1354bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 1355bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) { 1356bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1357bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1358bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1359bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1360bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1361bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (width < 2 * border || width > 2 + maxSize || 1362bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1363be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1364bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick height < 2 * border || height > 2 + maxSize || 1365bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1366be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1367bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level >= ctx->Const.MaxTextureLevels) { 1368bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick /* bad width or height or level */ 1369bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1370bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1371bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) { 1372bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1373bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1374bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1375738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1376738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1377738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1378738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1379738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1380738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1381738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1382738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1383064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick * Helper function to determine whether a target supports compressed textures 1384064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1385064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 1386064cd7c78c3108012f5d15206c70470f7b500259Ian Romanicktarget_can_be_compressed(GLcontext *ctx, GLenum target) 1387064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 1388064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return (((target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D)) 1389064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick || ((ctx->Extensions.ARB_texture_cube_map && 1390064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick (target == GL_PROXY_TEXTURE_CUBE_MAP || 1391064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && 1392817181ea5044b222f7612a425562bbc9313d5c75Ian Romanick target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)))) 1393817181ea5044b222f7612a425562bbc9313d5c75Ian Romanick || ((ctx->Extensions.MESA_texture_array && 1394d834a870e600684382b50d202a2bfc6d98cf6a0bIan Romanick ((target == GL_PROXY_TEXTURE_2D_ARRAY_EXT) || 1395d834a870e600684382b50d202a2bfc6d98cf6a0bIan Romanick (target == GL_TEXTURE_2D_ARRAY_EXT))))); 1396064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1397064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1398064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1399064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 14006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 14016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 14036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 14046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 14056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 14066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 14076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 14086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 14096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 14106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 14116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 14126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 14136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 14156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 14176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 14186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1419afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1420c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1421c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paultexture_error_check( GLcontext *ctx, GLenum target, 1422c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1423c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 14245b37c322741f019118a618bc6220f37adba4fbcdBrian Paul GLuint dimensions, 1425c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1426c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1427afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 142877ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul const GLboolean isProxy = _mesa_is_proxy_texture(target); 1429e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1430714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1431e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLenum proxy_target; 1432afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1433738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1434738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1435738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1436738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1437738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 14388afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1439738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1440738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1441738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1442738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1443738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1444738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1445738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1446738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1447738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1448738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1449738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1450738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1451738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1452738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1453973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1454f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1455f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1456973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1457f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1458f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1459f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1460f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 1461738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1462738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1463738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1464738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 1465738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { 1466e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_1D; 1467e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick height = 1; 14687c4c82fc6d5301e27643868517aeb23fcb5c40e6Brian depth = 1; 14698afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 14708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 147108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1472afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1473afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1475afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 1476e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth = 1; 1477738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) { 1478e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_2D; 1479738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1480738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 1481738318bb75dea8dac4465f53850987f6062a732dBrian Paul (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1482738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 14838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 14848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 14858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 14868afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1487e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_CUBE_MAP_ARB; 1488e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick sizeOK = (width == height); 14898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1490738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV || 1491738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_TEXTURE_RECTANGLE_NV) { 14928afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 14938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 14948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 14958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1496e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_RECTANGLE_NV; 14978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1498bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 1499bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_1D_ARRAY_EXT) { 1500bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick proxy_target = GL_PROXY_TEXTURE_1D_ARRAY_EXT; 1501bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 15028afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 15038afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 15048afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 15058afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1507afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 1508738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) { 1509e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_3D; 15108afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1511bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_2D_ARRAY_EXT || 1512bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_2D_ARRAY_EXT) { 1513bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick proxy_target = GL_PROXY_TEXTURE_2D_ARRAY_EXT; 1514bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 15158afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 151608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1517afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1518afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1519afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1520afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 152108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 1522afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1523afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1525e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxy_target, level, 1526e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1527e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1528e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1529738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1530c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15314e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1532738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1533738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1534c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1535afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1536afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1537afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1538738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 153989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1540c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 15424e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexImage%dD(internalFormat=0x%x)", 15434e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul dimensions, internalFormat); 1544c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1548738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1549f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 155038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 155138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 155238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 155338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 155489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 15558a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 15568a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1557c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 155838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1561601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 156222e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1563714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca indexFormat = is_index_format(format); 156422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1565714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca (is_index_format(internalFormat) && !indexFormat) || 1566601df9c742939c1f77de489561fe3e1d02f49618Brian Paul (is_depth_format(internalFormat) != is_depth_format(format)) || 15671ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul (is_ycbcr_format(internalFormat) != is_ycbcr_format(format)) || 1568114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger (is_depthstencil_format(internalFormat) != is_depthstencil_format(format)) || 1569114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger (is_dudv_format(internalFormat) != is_dudv_format(format))) { 1570601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1571601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 15728a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 15738a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1574601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1575601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1576601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1577601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1578601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1579c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1580601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1581601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1582c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 158336b518a7ca98e49d95c3fe54544700004716cdefBrian Paul _mesa_sprintf(message, 1584601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage%d(format/type YCBCR mismatch", dimensions); 1585c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, message); 1586c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1587c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1588d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1589d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1590d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1591d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1592d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1593d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1594d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1595d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1596d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1597d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1598d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 159936b518a7ca98e49d95c3fe54544700004716cdefBrian Paul _mesa_sprintf(message, 1600d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul "glTexImage%d(format=GL_YCBCR_MESA and border=%d)", 1601d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul dimensions, border); 1602d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, message); 1603d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1604d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1605d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1606c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1607c5b995066020191982b2315fc45d05e068eee761Brian Paul 1608601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1609601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 16102b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */ 1611601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1612601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1613601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16142b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 16152b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16162b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1617601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1618601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1619601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1620601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1621601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1622601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1623601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1624601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 162540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (is_compressed_format(ctx, internalFormat)) { 1626064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick if (!target_can_be_compressed(ctx, target) && !isProxy) { 1627064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick _mesa_error(ctx, GL_INVALID_ENUM, 1628064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick "glTexImage%d(target)", dimensions); 1629064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 163089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 163289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 163389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 163489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexImage%D(border!=0)", dimensions); 163589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 163789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1640afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1641afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1642afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1646c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 16476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 16496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 16506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 16516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 16526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 16536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 16546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 16556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 16566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 16576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 16586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 16596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 16606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 16626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 16646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 16656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1667c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1668fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 1669c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1670c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1671c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1672c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1673afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1674738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target */ 1675c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 1676738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target != GL_TEXTURE_1D) { 167708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 1678c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1680c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1681c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 1682738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1683da62bcecfb92978d7243928cfa0fb076b3de762dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1684738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 1685738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1686738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1687738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1688fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 16895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (target == GL_TEXTURE_RECTANGLE_NV) { 1690738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.NV_texture_rectangle) { 1691738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1692738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1693738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1694d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1695bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 1696bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1697bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1698bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1699bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1700bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1701738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target != GL_TEXTURE_2D) { 170208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1703c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1705c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1706c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 1707bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (target == GL_TEXTURE_2D_ARRAY_EXT) { 1708bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1709bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 1710bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1711bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1712bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1713bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target != GL_TEXTURE_3D) { 171408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 1715c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1716afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1717c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1718c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 1719738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem( ctx, "invalid dims in texture_error_check" ); 1720c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1721c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1722afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1723738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1724738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17254e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1726c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1727c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 17304e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17314e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1732c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1733c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1734c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 17354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17364e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1737c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1738c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1739c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1740738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1741738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1742c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1743c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1744afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 17465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_ENUM, 17478a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 17488a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 17495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 17505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 17515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 17525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 17535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1754f2718b0966f54049056e16e7cca08718341557b2Brian Paul 17555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 17565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellsubtexture_error_check2( GLcontext *ctx, GLuint dimensions, 17575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 17585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 17595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 17605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 17615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 17625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1763c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1764738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1765738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1766c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1769c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1770738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1771738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1772c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1774c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1775738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1776738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1777c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1779c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1780c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1781738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1782738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1783c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1784afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1785c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1786738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1787738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1788c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1789afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1790afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1791c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1792c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 179308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1794c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1795c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 179638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 179708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1798c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1799c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1800afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1801afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18020a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 18030a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (destTex->InternalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT || 18040a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT || 18050a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT || 18060a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) { 18070a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if ((width & 0x3) || (height & 0x3) || 18080a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul (xoffset & 0x3) || (yoffset & 0x3)) 18090a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18100a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul "glTexSubImage%dD(size or offset not multiple of 4)", 18110a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul dimensions); 18120a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_TRUE; 18130a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 18140a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif 18150a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 181689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (destTex->IsCompressed) { 1817064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick if (!target_can_be_compressed(ctx, target)) { 181889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 181989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(target)", dimensions); 1820e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1821e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 182289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 182389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 1824e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 182589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(xoffset or yoffset)", dimensions); 1826e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1827e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 182889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 or equal to whole texture size */ 18295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((width & 3) && (GLuint) width != destTex->Width) { 1830e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 183189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(width)", dimensions); 1832e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 183389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 18345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((height & 3) && (GLuint) height != destTex->Height) { 183589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 183689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glTexSubImage%D(width)", dimensions); 183789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 183889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1839e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1840e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1841c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1842c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1846c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 18566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 18576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * __GLcontextRec::Const and the supported extensions, and according to the 18626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * OpenGL specification. 1863afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1864c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1865fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 1866c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1867c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 18690899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLenum type; 1870738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 18710899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1872afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1873738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1874738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 18755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 18765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 18775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 18785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 188034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 188134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 188234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 188334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 188434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 188534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 188634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 188734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 188834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 188934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1890738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1891738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1892738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1893738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1894738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1895738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1896738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1897738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 18980899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 18990899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19000899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 19010899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19020899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19030899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 19040899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* NOTE: the format and type aren't really significant for 19050899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul * TestProxyTexImage(). Only the internalformat really matters. 190634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 190734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 190834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 190934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 191034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 191134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 19120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul */ 1913738318bb75dea8dac4465f53850987f6062a732dBrian Paul type = GL_FLOAT; 1914738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1915738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1916738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1917738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1918fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1919738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_1D) { 1920738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 1921738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1922738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1923738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, 1, 1, border); 1924738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1925738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 192608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 1927fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1928fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1929c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1930fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1931738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_2D) { 1932738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 1933738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1934738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1935738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1936738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1937738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1938738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 19398afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 19408afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 19418afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 19428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1943738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = (width == height) && 1944738318bb75dea8dac4465f53850987f6062a732dBrian Paul ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 1945738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, format, type, 1946738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 19478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 19488afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 19498afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 195008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1951fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1952fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1953738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1954738318bb75dea8dac4465f53850987f6062a732dBrian Paul GL_PROXY_TEXTURE_RECTANGLE_NV, 1955738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1956738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1957738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1958fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1959bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 1960bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1961bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)"); 1962bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1963bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1964bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1965bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick GL_PROXY_TEXTURE_1D_ARRAY_EXT, 1966bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level, internalFormat, 1967bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick format, type, 1968bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick width, height, 1, border); 1969bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1970738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 197108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1972fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1973fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1974c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1975738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1976738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "invalid dimensions in copytexture_error_check"); 1977c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1978c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1979c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1980738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1981738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1983738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1984c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1985738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1986738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1987738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1988738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1989ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1990c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1991c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1992c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 199340bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (is_compressed_format(ctx, internalFormat)) { 199453cf87be1b93c760228e6a9af8115d2a9ff99337Brian if (!target_can_be_compressed(ctx, target)) { 199589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 199689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexImage%d(target)", dimensions); 199789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 199889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 199989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 200089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 200189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexImage%D(border!=0)", dimensions); 200289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 200389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 200489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 20050899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul else if (is_depth_format(internalFormat)) { 20060899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 20071a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 20080899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20090899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%D(no depth)", dimensions); 20100899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20110899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20130899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul else if (is_depthstencil_format(internalFormat)) { 20140899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 20151a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 20160899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20170899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%D(no depth/stencil buffer)", dimensions); 20180899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20190899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20200899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 202189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2022c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2023c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2024c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2025c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2026c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 202834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 20299dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 20309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 20316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 20336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 20346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 20356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 20366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 20386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2039c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 20409dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paulcopytexsubimage_error_check1( GLcontext *ctx, GLuint dimensions, 20419dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 2042c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 204334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 204434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 204534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 204634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 204734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 204834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 204934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 205034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 205134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 205234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 20539dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check target */ 2054fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 2055fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 205608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 2057fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 2058fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2059c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2060fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 2061fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 2062fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 2063fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 2064fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2065fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul return GL_TRUE; 2066fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 2067fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 2068fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 2069fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 207008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2071fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 2072fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2073fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2074bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 2075bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 2076bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2077bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 2078bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 2079bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 2080fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 208108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2082fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 2083fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2084c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2085fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 2086bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (((target != GL_TEXTURE_2D_ARRAY_EXT) || 2087bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.MESA_texture_array)) 2088bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick && (target != GL_TEXTURE_3D)) { 2089bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 2090bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 2091fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2092c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2093c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2094738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2095738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20964e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2098c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2099c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2100c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 21025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 21035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 21049dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 21059dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 21069dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 21079dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 21089dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 21099dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 21109dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 21119dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 21129dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 21135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 21145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellcopytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions, 21155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 21165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 21175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 21185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 21195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 21209dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2121c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 21224e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2123b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2124b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2125c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2126c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2127c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21289dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 21299dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 21309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21319dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 21329dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 21339dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 21349dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 21359dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21369dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 21379dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 21389dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 21399dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 21409dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2141c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 21424e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21434e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2144c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2145c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 214638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 21474e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21484e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2149c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2150c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2151c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2152c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 21534e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21544e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2155c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2156c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2157c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 215838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 21594e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21604e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2161c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2162c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2163c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2164c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21659dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2166c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2167c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 21684e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21694e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2170c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2171c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 217238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 21734e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21744e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2175c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2176c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2177c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2178c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 217989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (teximage->IsCompressed) { 218053cf87be1b93c760228e6a9af8115d2a9ff99337Brian if (!target_can_be_compressed(ctx, target)) { 218189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 218289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%d(target)", dimensions); 2183e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2184e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 218589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 218689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 218789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 218889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(xoffset or yoffset)", dimensions); 2189e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2190e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 219189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2192798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 219389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 219489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(width)", dimensions); 2195e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 219689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2197798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 219889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 219989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul "glCopyTexSubImage%D(height)", dimensions); 220089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 220189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2202e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2203e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2204a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2205d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2206d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2207d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2208d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2209985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2210985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2211803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2212803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2213985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2214985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2215985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2216a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 22171a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 22180899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 22190899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexSubImage%D(no depth buffer)", 22200899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 22210899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 22220899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 22230899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2224a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 22251a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 22260899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 22270899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexSubImage%D(no depth/stencil buffer)", 22280899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 22290899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 22300899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 22310899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 22320899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2233c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2234c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2235c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2236c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2237c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 22391749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Get texture image. Called by glGetTexImage. 22406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 22416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 22426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 22431749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param format pixel data format for returned image. 22441749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param type pixel data type for returned image. 22451749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param pixels returned pixel data. 22466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2247c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 22488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 22498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLenum type, GLvoid *pixels ) 2250289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul{ 22518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 2252ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul struct gl_texture_object *texObj; 2253ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul struct gl_texture_image *texImage; 2254cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels = 0; 22552c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 22568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 22578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2258cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 2259cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 226077ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul if (!texObj || _mesa_is_proxy_texture(target)) { 2261cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 2262cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 2263cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 2264cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2265ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul maxLevels = _mesa_max_texture_levels(ctx, target); 2266ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 2267cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 2268cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 226908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 22708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 2271289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul } 2272289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 227362c36a2ff39d775c1f1bc377b9ddbc69e2340799Brian Paul if (_mesa_sizeof_packed_type(type) <= 0) { 227408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 22758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 22768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 22778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2278f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (_mesa_components_in_format(format) <= 0 || 2279f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul format == GL_STENCIL_INDEX) { 228008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 22818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 22828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 22838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2284f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { 228508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2286df926955be59a0128eea44141eb46fc52556dc05Brian Paul return; 2287f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2288f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 22894741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (!ctx->Extensions.ARB_depth_texture && is_depth_format(format)) { 229008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2291df926955be59a0128eea44141eb46fc52556dc05Brian Paul return; 2292f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 2293f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul 22941749a25ca889d514889b34cf6311c8014d97bf66Brian Paul if (!ctx->Extensions.MESA_ycbcr_texture && is_ycbcr_format(format)) { 2295c5b995066020191982b2315fc45d05e068eee761Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2296df926955be59a0128eea44141eb46fc52556dc05Brian Paul return; 2297c5b995066020191982b2315fc45d05e068eee761Brian Paul } 2298c5b995066020191982b2315fc45d05e068eee761Brian Paul 22991ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (!ctx->Extensions.EXT_packed_depth_stencil 23001ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul && is_depthstencil_format(format)) { 23011ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2302df926955be59a0128eea44141eb46fc52556dc05Brian Paul return; 23031ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 23041ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 2305114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (!ctx->Extensions.ATI_envmap_bumpmap 2306114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger && is_dudv_format(format)) { 2307114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 2308114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 2309114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 2310114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 23115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 23125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 23135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 23145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 23155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* invalid mipmap level, not an error */ 23165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 23191749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 23205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Make sure the requested image format is compatible with the 23215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * texture's format. Note that a color index texture can be converted 23225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * to RGBA so that combo is allowed. 23235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 232422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(format) 232522e442544bc451f114288f07cf9cc1584ca357a1Brian Paul && !_mesa_is_color_format(texImage->TexFormat->BaseFormat) 23265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_index_format(texImage->TexFormat->BaseFormat)) { 23275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 23285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (is_index_format(format) 23315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_index_format(texImage->TexFormat->BaseFormat)) { 23325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 23335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (is_depth_format(format) 23365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_depth_format(texImage->TexFormat->BaseFormat) 23375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_depthstencil_format(texImage->TexFormat->BaseFormat)) { 23385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 23395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (is_ycbcr_format(format) 23425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_ycbcr_format(texImage->TexFormat->BaseFormat)) { 23435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 23445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (is_depthstencil_format(format) 23475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell && !is_depthstencil_format(texImage->TexFormat->BaseFormat)) { 23485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 23495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2351114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (is_dudv_format(format) 2352114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger && !is_dudv_format(texImage->TexFormat->BaseFormat)) { 2353114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 2354114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger goto out; 2355114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 23565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 23575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (ctx->Pack.BufferObj->Name) { 23585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* packing texture image into a PBO */ 23595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2; 23605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width, 23615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage->Height, texImage->Depth, 23625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, type, pixels)) { 23635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, 23645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glGetTexImage(invalid PBO access)"); 23655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 23665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2367ad15866ef0e77478508eeb534b28f0136462b644Brian Paul } 2368ad15866ef0e77478508eeb534b28f0136462b644Brian Paul 23695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* typically, this will call _mesa_get_teximage() */ 23705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels, 23715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 23725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 23735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 23745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 23755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2376289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul} 2377289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 2378289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 23792897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 23802897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 23812897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 23822897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLcontext *ctx; 23832897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 23842897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 23852897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 23862897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 23878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2388519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 23892897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2390519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2391519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 23922897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2393519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 23942897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 23952897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 23962897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLcontext *ctx = info->ctx; 23972897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 23982897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 23992897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 24012897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2402519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 24032897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2404519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 24052897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2406519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2407519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2408519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2409519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2410519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]); 2411519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2412ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 24132897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 24142897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2415519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2416519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2417519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2418519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2419519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2420519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 24212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 24222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 24232897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 24242897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 24252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 24262897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 24272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 24282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulupdate_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj, 24292897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 24302897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 24312897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 24322897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 24332897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 24342897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 24352897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 24362897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 24372897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 24382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 24392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 24402897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 24412897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24422897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 2443519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2444289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 2445c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 2446c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2447c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 244843911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2449fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 2450fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 2451c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2452ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2453fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2454cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2455c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 245634a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 245722e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(internalFormat)) { 2458f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2459f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 246034a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 2461f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 24628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 24638c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 2464f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 24650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24660293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2467e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2468f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2469aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2470f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 1, postConvWidth, 1, 1, border)) { 24718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2472c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2473c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24741ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 24755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2476fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 24775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 24785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 24795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 24825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 24835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 24845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 24855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 24865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 24875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 24885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 24895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 249062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 24915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 2492c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell clear_teximage_fields(texImage); /* not really needed, but helpful */ 24945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, 24955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, 1, 1, 24965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 24975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 24985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexImage1D); 24994f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 25005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Give the texture to the driver! <pixels> may be null! */ 25015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 25025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, border, format, type, pixels, 25035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell &ctx->Unpack, texObj, texImage); 25045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 25055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->TexFormat); 2506519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 25075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell update_fbo_texture(ctx, texObj, face, level); 25085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 25095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 2510227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 25115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 25125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 25135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 25145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2515c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 251638d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2517c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 2518738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2519738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2520738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2521738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1, postConvWidth, 1, 1, border)) { 2522738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2523a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2524a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2525c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 252689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 252789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2528738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(texImage); 252989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 253089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul postConvWidth, 1, 1, 253189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 2532738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2533738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 253489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2535c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2536c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 253708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 2538c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 2539c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2540c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2541c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2542c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2543c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 254443911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2545fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 2546fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2547fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2548c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2549ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 2550fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2551cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2552c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 255334a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 255422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(internalFormat)) { 2555f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 255638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes &postConvHeight); 2557f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 255834a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 2559f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 25608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 2561a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 2562fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 25638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 25648afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (ctx->Extensions.NV_texture_rectangle && 2565bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_RECTANGLE_NV) || 2566bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2567bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_1D_ARRAY_EXT)) { 25688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2569f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 25700293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 25710293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2572e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2573f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2574aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (texture_error_check(ctx, target, level, internalFormat, 2575f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul format, type, 2, postConvWidth, postConvHeight, 2576f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul 1, border)) { 25778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2578c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2579c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 25801ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 25815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2582fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 25835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 25855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 25865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 25875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 25885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 25895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 25905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 25915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 25925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 25935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 25945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 25955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 25965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 25975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 25985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell clear_teximage_fields(texImage); /* not really needed, but helpful */ 25995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, 26005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, postConvHeight, 1, 26015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 26025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexImage2D); 26045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Give the texture to the driver! <pixels> may be null! */ 26065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 26075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, border, format, type, pixels, 26085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell &ctx->Unpack, texObj, texImage); 26095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->TexFormat); 26115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell update_fbo_texture(ctx, texObj, face, level); 26135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 2615227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 26165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 26175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 26195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2620afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2621172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul else if (target == GL_PROXY_TEXTURE_2D || 2622172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 26238afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.ARB_texture_cube_map) || 26248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (target == GL_PROXY_TEXTURE_RECTANGLE_NV && 2625bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick ctx->Extensions.NV_texture_rectangle) || 2626bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2627bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT)) { 2628afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2629738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2630738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2631738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2632738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 2, postConvWidth, postConvHeight, 2633738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1, border)) { 2634738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2635a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2636ea4b183b8c3730ec2c6b5152cad1a68889634487Brian Paul clear_teximage_fields(texImage); 2637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 263889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 263989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 264089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 264189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul postConvWidth, postConvHeight, 1, 264289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul border, internalFormat); 2643738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2644738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 264589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 264808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 2649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2650afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2651afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2655afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2657afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2658c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2659b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2660fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2661fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2662fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2664fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2665cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2667bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (target == GL_TEXTURE_3D || 2668bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2669bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_2D_ARRAY_EXT)) { 2670519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* non-proxy target */ 2671f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul struct gl_texture_unit *texUnit; 26720293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 26730293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2674e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2675289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 26765535aca5dffdfb8ad9a1970a062e6109227aa17fBrian Paul if (texture_error_check(ctx, target, level, (GLint) internalFormat, 2677aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul format, type, 3, width, height, depth, border)) { 26788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26811ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 26825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 26835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 2684f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 26865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 26895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 26905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 26915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 26925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 26955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 26965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 26985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 26995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell clear_teximage_fields(texImage); /* not really needed, but helpful */ 27005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, 27015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, 27025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 2703fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 27045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexImage3D); 270562c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 27065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Give the texture to the driver! <pixels> may be null! */ 27075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 27085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, border, format, type, 27095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell pixels, &ctx->Unpack, texObj, texImage); 2710afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->TexFormat); 27124f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 27135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell update_fbo_texture(ctx, texObj, face, level); 2714519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 27155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 2716227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 27175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 27185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 27205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2721afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2722bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_3D || 2723bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2724bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT)) { 2725afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2726738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2727738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 2728738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (texture_error_check(ctx, target, level, internalFormat, 2729738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 3, width, height, depth, border)) { 2730738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2731a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2732a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 273489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 273589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 27369f6022d0567dc1288888212d7128acc48795b306Brian _mesa_init_teximage_fields(ctx, target, texImage, width, height, 27379f6022d0567dc1288888212d7128acc48795b306Brian depth, border, internalFormat); 2738738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 2739738318bb75dea8dac4465f53850987f6062a732dBrian Paul internalFormat, format, type); 274089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2742afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 274308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 2744afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2745afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2747afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2748afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2749c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 275043911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2751663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2752663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2753663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2754663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 275589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2756663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2757663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2758663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2759663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2760afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2761c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2762fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 2763fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 2764fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2765fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2767ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 27680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 27690293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 27705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_image *texImage = NULL; 27712c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 277275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 277375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 27741ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 277508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 27762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 277734a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 2778f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 277922e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(format)) { 2780f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2781f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 278234a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 2783afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2784c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 27855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, 1, 1, format, type)) { 2786f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 27900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 27918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 27925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texObj); 2793afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2797afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (subtexture_error_check2(ctx, 1, target, level, xoffset, 0, 0, 27995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, 1, 1, format, type, texImage)) { 28005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* error was detected */ 28015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0) 28045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 28055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 28075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 2808347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 28095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexSubImage1D); 28105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 28115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, type, pixels, &ctx->Unpack, 28125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 28135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 28145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 28165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2818afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2819afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2820c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2821fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2822fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2823fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2824fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2825fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2826afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2827ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 28280293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 28290293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 28300293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 28312c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 283275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 283375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 28341ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 283508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 28362aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 283734a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 2838f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul /* XXX should test internal format */ 283922e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(format)) { 2840f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 2841f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 2842f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 284334a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 2844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2845c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 28465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, postConvHeight, 1, format, type)) { 2847f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2848afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2849afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28500293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 285135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 28525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2855afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (subtexture_error_check2(ctx, 2, target, level, xoffset, yoffset, 0, 28575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, postConvHeight, 1, format, type, 28585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage)) { 28595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* error was detected */ 28605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2861afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0 || height == 0) 28635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 2864347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 28655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 28665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 28675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell yoffset += texImage->Border; 28685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexSubImage2D); 28705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 28715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, format, type, pixels, 28725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell &ctx->Unpack, texObj, texImage); 28735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 28745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 28765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2877c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2878afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2879afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2880afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2881c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2882fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2883fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2884fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2885fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2886fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2887afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28880293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_unit *texUnit; 28890293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 28900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 28912c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 289275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 289375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 28941ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 289508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 28962aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2897c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 2898c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 2899f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2900afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2901afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29020293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 29038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 29045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 29085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (subtexture_error_check2(ctx, 3, target, level, xoffset, yoffset, zoffset, 29105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, format, type, texImage)) { 29115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* error was detected */ 29125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0 || height == 0 || height == 0) 29155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 29165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 29185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 29195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell yoffset += texImage->Border; 29205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell zoffset += texImage->Border; 29215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.TexSubImage3D); 29235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.TexSubImage3D)(ctx, target, level, 29245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, yoffset, zoffset, 29255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, 29265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, type, pixels, 29275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell &ctx->Unpack, texObj, texImage ); 29285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 29295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 29315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2932afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2933afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2934afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2935afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2936c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2937fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 2938fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 2939fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 2940fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 2941afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 29422aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 29432aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 29442aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2945ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 2946e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2947fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2948cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2949afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29501ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 295108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2952fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 295334a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 295422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(internalFormat)) { 2955f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 2956f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 295734a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 2958ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2959ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 2960ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, 1, border)) 2961ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2962ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 29632aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 29642aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 29655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 29685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 29695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 29705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 29715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 29745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 29755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 29787dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 29795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell clear_teximage_fields(texImage); /* not really needed, but helpful */ 29805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1, 29815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 29827dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 29832aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 29845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.CopyTexImage1D); 29855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, 29865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell x, y, width, border); 29872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 29885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->TexFormat); 29894f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 29905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell update_fbo_texture(ctx, texObj, face, level); 2991519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 29925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 2993227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 29945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 29955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 29975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3000afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3001afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3002c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3003fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 3004fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 3005fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 3006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 30072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_unit *texUnit; 30082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 30092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 3010ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 3011e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 3012fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3013cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 30151ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 301608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3017fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 301834a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#if FEATURE_convolve 301922e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if (_mesa_is_color_format(internalFormat)) { 3020f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 3021f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul &postConvHeight); 3022f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul } 302334a61c66fd1b625a5606b795d192a49632ff1787Keith Whitwell#endif 302495c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul 3025ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 3026ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul postConvWidth, postConvHeight, border)) 3027ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3028ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 30292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30302aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 30317dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 30325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 30335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 30345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 3035afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 30365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 30375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 30385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 30395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 30425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 30435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 30462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 30475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell clear_teximage_fields(texImage); /* not really needed, but helpful */ 30485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, 30495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, postConvHeight, 1, 30505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 30515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.CopyTexImage2D); 30535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, 30545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell x, y, width, height, border); 30555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->TexFormat); 30574f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 30585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell update_fbo_texture(ctx, texObj, face, level); 3059519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 30605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 3061227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 30625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 30635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 30655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3066afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3067afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3068afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3069c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3070fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 3071fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 3072afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3073347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 30745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3075347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 3076ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width; 307703bafd1f9fa000abdb794b2ae344a68840c83201Brian GLint yoffset = 0; 307803bafd1f9fa000abdb794b2ae344a68840c83201Brian GLsizei height = 1; 307903bafd1f9fa000abdb794b2ae344a68840c83201Brian 3080fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3081cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3082afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 30831ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 308408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3085fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 30869dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 1, target, level)) 3087ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3088ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3089347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 30915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 30935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 30945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 30955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 309695c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#if FEATURE_convolve 309795c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul if (texImage && _mesa_is_color_format(texImage->InternalFormat)) { 309895c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 309995c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul } 310095c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#endif 310195c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul 31025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (copytexsubimage_error_check2(ctx, 1, target, level, 31035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, 0, 0, postConvWidth, 1, 31045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage)) 31055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 31065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 3107347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 31085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 31095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 3110347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 311103bafd1f9fa000abdb794b2ae344a68840c83201Brian if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 311203bafd1f9fa000abdb794b2ae344a68840c83201Brian &width, &height)) { 311303bafd1f9fa000abdb794b2ae344a68840c83201Brian ASSERT(ctx->Driver.CopyTexSubImage1D); 311403bafd1f9fa000abdb794b2ae344a68840c83201Brian ctx->Driver.CopyTexSubImage1D(ctx, target, level, 311503bafd1f9fa000abdb794b2ae344a68840c83201Brian xoffset, x, y, width); 311603bafd1f9fa000abdb794b2ae344a68840c83201Brian } 311703bafd1f9fa000abdb794b2ae344a68840c83201Brian 31185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 31195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 31205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 31215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3126c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3127fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 3128fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 3129fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3131347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 31325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3133347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 3134ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 3135fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3136cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 31381ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 313908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3140fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 31419dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 2, target, level)) 3142ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3143ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3144347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 31455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 31465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 31475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 31485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 31495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 3150347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 315195c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#if FEATURE_convolve 315295c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul if (texImage && _mesa_is_color_format(texImage->InternalFormat)) { 315395c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, 315495c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul &postConvWidth, &postConvHeight); 315595c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul } 315695c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#endif 315795c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul 31585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (copytexsubimage_error_check2(ctx, 2, target, level, xoffset, yoffset, 0, 31595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell postConvWidth, postConvHeight, texImage)) 31605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 3161347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 31625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 31635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 31645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell yoffset += texImage->Border; 316503bafd1f9fa000abdb794b2ae344a68840c83201Brian 316603bafd1f9fa000abdb794b2ae344a68840c83201Brian if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 316703bafd1f9fa000abdb794b2ae344a68840c83201Brian &width, &height)) { 316803bafd1f9fa000abdb794b2ae344a68840c83201Brian ASSERT(ctx->Driver.CopyTexSubImage2D); 316903bafd1f9fa000abdb794b2ae344a68840c83201Brian ctx->Driver.CopyTexSubImage2D(ctx, target, level, 31705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, yoffset, x, y, width, height); 317103bafd1f9fa000abdb794b2ae344a68840c83201Brian } 317203bafd1f9fa000abdb794b2ae344a68840c83201Brian 31735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 31745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 31755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 31765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3181c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3182fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 3183fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 3184fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3186347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_unit *texUnit; 31875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3188347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 3189ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul GLsizei postConvWidth = width, postConvHeight = height; 3190fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3191cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 31931ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 319408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3195fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 31969dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 3, target, level)) 3197ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3198ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3199347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 32005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 3201347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 32025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 32035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 32045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 3205347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 320695c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#if FEATURE_convolve 320795c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul if (texImage && _mesa_is_color_format(texImage->InternalFormat)) { 320895c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul _mesa_adjust_image_for_convolution(ctx, 2, 320995c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul &postConvWidth, &postConvHeight); 321095c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul } 321195c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul#endif 321295c04cccfef2e5743279e1f5a6a13f3925c7024cBrian Paul 32135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (copytexsubimage_error_check2(ctx, 3, target, level, xoffset, yoffset, 32145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell zoffset, postConvWidth, postConvHeight, 32155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage)) 32165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 32175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* If we have a border, xoffset=-1 is legal. Bias by border width */ 32195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset += texImage->Border; 32205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell yoffset += texImage->Border; 32215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell zoffset += texImage->Border; 32225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 322303bafd1f9fa000abdb794b2ae344a68840c83201Brian if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 322403bafd1f9fa000abdb794b2ae344a68840c83201Brian &width, &height)) { 322503bafd1f9fa000abdb794b2ae344a68840c83201Brian ASSERT(ctx->Driver.CopyTexSubImage3D); 322603bafd1f9fa000abdb794b2ae344a68840c83201Brian ctx->Driver.CopyTexSubImage3D(ctx, target, level, 32275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, yoffset, zoffset, 32285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell x, y, width, height); 322903bafd1f9fa000abdb794b2ae344a68840c83201Brian } 323003bafd1f9fa000abdb794b2ae344a68840c83201Brian 32315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 32325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 32335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 32345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3235afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 32361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32371207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32381207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 323989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 324089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 324189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 324289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 324389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 324489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 324589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 324689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 324789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 324889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 324989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 325089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulcompressed_texture_error_check(GLcontext *ctx, GLint dimensions, 325189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 325289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 325389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 325489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei imageSize) 325589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 3256c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 325789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 325889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 325989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 326089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 326189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 326389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 326489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 326589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 326789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 326889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 327089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 327189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 327289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 327389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 327489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 327589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 327689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 327789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 327889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 327989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 328089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 328189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 328289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 328389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 328489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 328589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 328689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 328789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 328889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 328989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 329089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3291c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 329240bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (!is_compressed_format(ctx, internalFormat)) 329389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 329489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3295c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3296a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick if (_mesa_base_tex_format(ctx, internalFormat) < 0) 3297a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3298a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 329989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) 330089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 330189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3302887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul /* 3303887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * XXX We should probably use the proxy texture error check function here. 3304887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul */ 3305887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize || 3306be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(width))) 330789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 330889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3309887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize || 3310be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(height))) 331189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 331289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 331389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3314887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((depth < 1 || depth > maxTextureSize || 3315be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(depth))) 331689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 2) 331789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 331889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 331989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 332089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 332189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 332289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 332389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 332489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 332589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 332689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3327c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height, 3328c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul depth, internalFormat); 332989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 333089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 333189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 33320a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 33330a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if ((internalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT || 33340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT || 33350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT || 33360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) 33370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul && border != 0) { 33380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_INVALID_OPERATION; 33390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 33400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif 33410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 334289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 334389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 334489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 334589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 334689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 334789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 33482371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 33492371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 33502371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 335189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 335289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 335389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 335489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulcompressed_subtexture_error_check(GLcontext *ctx, GLint dimensions, 335589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 335689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 335789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 335889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 335989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 336089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 3361a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 336289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 336389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 336489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 336589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 336689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 336789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 336889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 336989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 337089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 337289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 337389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 337589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 337689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 337789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 337889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 338089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 338189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 338289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 338389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 338489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 338589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 338689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 338789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 338889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 338989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 339089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 339189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 339289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 339389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 339489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 339589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3396c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 339740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca if (!is_compressed_format(ctx, format)) 339889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 339989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3400887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 340189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3403887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 340489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 340589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 340789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 340889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 34102371033bbaf6e7477bfa893654a0467a084f335bBrian Paul /* XXX these tests are specific to the compressed format. 34112371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * this code should be generalized in some way. 34122371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 341389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) != 0 || (yoffset & 3) != 0) 341489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 341589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 341689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((width & 3) != 0 && width != 2 && width != 1) 341789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 341889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 341989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((height & 3) != 0 && height != 2 && height != 1) 342089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 342189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3422c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul expectedSize = _mesa_compressed_texture_size_glenum(ctx, width, height, 3423c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul depth, format); 342489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 342589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 342689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 342789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 342889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 342989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 343089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 343189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3432c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 34331207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 3434aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 34351207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 34361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 34371207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3438aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3439cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3440aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3441aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 34428c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3443aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 3444aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3445aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 344689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 344789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 344889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 344989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage1D"); 345089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3451aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3452aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3453aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 34548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3455aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 34565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 34595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 34605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D"); 34615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 34625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 34635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 34645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 34655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 34665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 34675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 34685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 34695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 34705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 34716628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 34725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.CompressedTexImage1D); 34735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 34745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell internalFormat, width, border, 34755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell imageSize, data, 34765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 3477aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 34785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 3479227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 34805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 34815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 34825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 34835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3484aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3485aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 3486aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 348789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 348889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 34898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 34908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 349138d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 349238d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 349338d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 349438d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 349538d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3496aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3497a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3498a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3499a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3500a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3501aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 350289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 350389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 350489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 35055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 350689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 350789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 35085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 35095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 35105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 35115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 35125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 35135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 35145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 35155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 351789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3518aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3519aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 352089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1D(target)"); 3521aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3522aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 35231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35241207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35251207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3526c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 3528aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 35291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 35301207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35311207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3532aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3533cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3534aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 35358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 3536a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 35379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 353889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 35398c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3540aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 3541aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3542aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 354389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 354489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 354589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 354689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage2D"); 354789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3548aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3549aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3550aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 35518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3552aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 35535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 35545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 35555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 35565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 35575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); 35585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 35595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 35615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 35625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 35635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 35656628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 35665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 35675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 3568aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 35695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.CompressedTexImage2D); 35705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 35715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell internalFormat, width, height, 35725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, imageSize, data, 35735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 35745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 35755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 3576227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 35775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 35785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 35805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3581aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 358289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_2D || 358389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 358489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ctx->Extensions.ARB_texture_cube_map)) { 3585aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 358689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 358789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 35888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 35898e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 359038d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 359138d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 359238d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 359338d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 359438d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3595aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3596a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3597a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3598a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3599a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3600aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 360189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 360289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 360389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 36045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 360589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 360689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 36075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 36085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 36095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 36105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 36115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 36125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 36135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 36145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 36155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 361689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3617aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3618aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 361989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(target)"); 3620aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3621aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 36221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 36231207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 36241207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3625c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 36261207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 3627aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 36281207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 36291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 36301207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3631aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3632cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3633aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 36349540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 36358c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3636aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_unit *texUnit; 3637aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3638aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 363989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 364089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 364189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 364289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage3D"); 364389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3644aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3645aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3646aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 36478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 36485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 36495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 36505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 36515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 36525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D"); 36535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 36545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 36555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 36565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (texImage->Data) { 36575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 36585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 36595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(texImage->Data == NULL); 36606628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 36615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, depth, 36625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, internalFormat); 3663aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 36645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.CompressedTexImage3D); 36655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 36665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell internalFormat, 36675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, 36685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell border, imageSize, data, 36695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 36705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 36715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* state update */ 3672227315278dea9095cee6e508d03b28720b2e7880Brian texObj->_Complete = GL_FALSE; 36735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 36745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 36755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 36765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3677aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3678aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 3679aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 368089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 368189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 36828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 36838e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 368438d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 368538d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 368638d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 368738d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 368838d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3689aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3690a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3691a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3692a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3693a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3694aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 369589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 369689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 369789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_unit *texUnit; 36985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 369989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 370089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 37015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj = _mesa_select_tex_object(ctx, texUnit, target); 37025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 37045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 37055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, 37065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell depth, border, internalFormat); 37075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 37085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 370989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3710aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3711aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 371289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3D(target)"); 3713aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3714aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 37151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3718c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 37191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 37201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei width, GLenum format, 37211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 37221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 37239540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 37249540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 37259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 372689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3727a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 372875280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 372975280a2c742ee241d392618a3b29548fce1520a9Brian Paul 373089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 1, target, level, 3731c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 3732c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul width, 1, 1, /* size */ 3733c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 373489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 373589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexSubImage1D"); 373689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 37379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 37389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 37399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 37409540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 37415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 37435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 37445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 37459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 37465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((GLint) format != texImage->InternalFormat) { 37475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, 37485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCompressedTexSubImage1D(format)"); 37495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 37505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 375189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 37525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((width == 1 || width == 2) && (GLuint) width != texImage->Width) { 37535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage1D(width)"); 37545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 37555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 375689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 37575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0) 37585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 37599540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 37605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (ctx->Driver.CompressedTexSubImage1D) { 37615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 37625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, width, 37635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, imageSize, data, 37645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 37655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 37665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 37679540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 37685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 37695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 37701207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3773c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 37741207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 37751207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 37761207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 37771207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 37781207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 37799540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 37809540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 37819540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 378289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3783a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 378475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 378575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 378689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 2, target, level, 3787c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, yoffset, 0, /* pos */ 3788c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul width, height, 1, /* size */ 3789c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 379089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 3791b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul /* XXX proxy target? */ 379289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexSubImage2D"); 379389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 37949540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 37959540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 37969540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 37979540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 37985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 38005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 38015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 38029540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((GLint) format != texImage->InternalFormat) { 38045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, 38055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCompressedTexSubImage2D(format)"); 38065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 38075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 380889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 38095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 38105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ((height == 1 || height == 2) && (GLuint) height != texImage->Height)) { 38115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage2D(size)"); 38125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 38135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 381489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 38155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0 || height == 0) 38165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 38179540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (ctx->Driver.CompressedTexSubImage2D) { 38195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 38205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, yoffset, width, height, 38215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, imageSize, data, 38225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 38235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 38245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 38259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 38265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 38275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 38281207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 38291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 38301207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3831c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 38321207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 38331207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 38341207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 38351207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 38361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 38379540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_unit *texUnit; 38389540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 38399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 384089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3841a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 384275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 384375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 384489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul error = compressed_subtexture_error_check(ctx, 3, target, level, 3845c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, yoffset, zoffset,/*pos*/ 3846c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul width, height, depth, /*size*/ 3847c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 384889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 3849144e1e439faf994ad25901aaf2a9d60a1078eed9Brian _mesa_error(ctx, error, "glCompressedTexSubImage3D"); 385089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 38519540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 38529540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38539540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 38549540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 38555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 38565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 38575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 38585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 38599540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if ((GLint) format != texImage->InternalFormat) { 38615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_OPERATION, 38625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCompressedTexSubImage3D(format)"); 38635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 38645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 386589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 38665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 38675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ((height == 1 || height == 2) && (GLuint) height != texImage->Height) || 38685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ((depth == 1 || depth == 2) && (GLuint) depth != texImage->Depth)) { 38695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage3D(size)"); 38705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; 38715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 387289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 38735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (width == 0 || height == 0 || depth == 0) 38745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell goto out; /* no-op, not an error */ 38759540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (ctx->Driver.CompressedTexSubImage3D) { 38775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 38785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell xoffset, yoffset, zoffset, 38795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell width, height, depth, 38805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell format, imageSize, data, 38815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texObj, texImage); 38825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 38835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->NewState |= _NEW_TEXTURE; 38849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 38855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell out: 38865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 38871207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 38881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 38891207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3890c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 38919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 38921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 38938e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const struct gl_texture_unit *texUnit; 38945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 38959540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 3896cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul GLint maxLevels; 3897a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 3898cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 38999540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3900cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 3901cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul texObj = _mesa_select_tex_object(ctx, texUnit, target); 3902cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (!texObj) { 3903cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB"); 3904cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul return; 3905cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul } 3906cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 3907ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul maxLevels = _mesa_max_texture_levels(ctx, target); 3908ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 3909cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul 3910cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul if (level < 0 || level >= maxLevels) { 3911cd1cefae9146fc14b35ee93a04bdb1b1590fba7bBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 39129540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul return; 39139540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 39149540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 391577ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul if (_mesa_is_proxy_texture(target)) { 391608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 39178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; 39189540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 39199540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 39205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 39215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 39225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 3923144e1e439faf994ad25901aaf2a9d60a1078eed9Brian if (texImage) { 3924144e1e439faf994ad25901aaf2a9d60a1078eed9Brian if (texImage->IsCompressed) { 3925144e1e439faf994ad25901aaf2a9d60a1078eed9Brian /* this typically calls _mesa_get_compressed_teximage() */ 3926144e1e439faf994ad25901aaf2a9d60a1078eed9Brian ctx->Driver.GetCompressedTexImage(ctx, target, level, img, 3927144e1e439faf994ad25901aaf2a9d60a1078eed9Brian texObj, texImage); 3928144e1e439faf994ad25901aaf2a9d60a1078eed9Brian } 3929144e1e439faf994ad25901aaf2a9d60a1078eed9Brian else { 3930144e1e439faf994ad25901aaf2a9d60a1078eed9Brian _mesa_error(ctx, GL_INVALID_OPERATION, 3931144e1e439faf994ad25901aaf2a9d60a1078eed9Brian "glGetCompressedTexImageARB"); 3932144e1e439faf994ad25901aaf2a9d60a1078eed9Brian } 39335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3934144e1e439faf994ad25901aaf2a9d60a1078eed9Brian else { 3935144e1e439faf994ad25901aaf2a9d60a1078eed9Brian /* probably invalid mipmap level */ 3936144e1e439faf994ad25901aaf2a9d60a1078eed9Brian _mesa_error(ctx, GL_INVALID_VALUE, 3937144e1e439faf994ad25901aaf2a9d60a1078eed9Brian "glGetCompressedTexImageARB(level)"); 39385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 39395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 39405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 39411207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3942