teximage.c revision a156b49800c1419785d0709b78ef0d35e6dab5df
12019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/* 22019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Mesa 3-D graphics library 32019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Version: 6.1 42019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 52019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 62019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 72019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Permission is hereby granted, free of charge, to any person obtaining a 82019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * copy of this software and associated documentation files (the "Software"), 92019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * to deal in the Software without restriction, including without limitation 102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * the rights to use, copy, modify, merge, publish, distribute, sublicense, 112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * and/or sell copies of the Software, and to permit persons to whom the 122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Software is furnished to do so, subject to the following conditions: 132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * The above copyright notice and this permission notice shall be included 152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * in all copies or substantial portions of the Software. 162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \file teximage.c 282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Texture images manipulation functions. 292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \note Mesa's native texture data type is GLchan. Native formats are 312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, and 322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_COLOR_INDEX. 332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \note Device drivers are free to implement any internal format they want. 352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "glheader.h" 392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "context.h" 402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "convolve.h" 412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "image.h" 422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "imports.h" 43428dfdd50cd81fda921f9bfc5f6451adc591aeffflorian#include "macros.h" 442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "state.h" 452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "texcompress.h" 462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "texformat.h" 472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "teximage.h" 482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "texstate.h" 492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "texstore.h" 502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#include "mtypes.h" 512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#if 0 54b4df768d103fab8a7cb260812cde6789d1128878florianstatic void PrintTexture(GLcontext *ctx, const struct gl_texture_image *img) 55b4df768d103fab8a7cb260812cde6789d1128878florian{ 56b4df768d103fab8a7cb260812cde6789d1128878florian#if CHAN_TYPE == GL_FLOAT 57b4df768d103fab8a7cb260812cde6789d1128878florian _mesa_problem(NULL, "PrintTexture doesn't support float channels"); 58b4df768d103fab8a7cb260812cde6789d1128878florian#else 59b4df768d103fab8a7cb260812cde6789d1128878florian GLuint i, j, c; 60b4df768d103fab8a7cb260812cde6789d1128878florian const GLchan *data = (const GLchan *) img->Data; 61b4df768d103fab8a7cb260812cde6789d1128878florian 62b4df768d103fab8a7cb260812cde6789d1128878florian if (!data) { 63b4df768d103fab8a7cb260812cde6789d1128878florian _mesa_printf("No texture data\n"); 642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (img->Format) { 682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA: 692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE: 702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY: 712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX: 722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj c = 1; 732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA: 752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj c = 2; 762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB: 782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj c = 3; 792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA: 812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj c = 4; 822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(NULL, "error in PrintTexture\n"); 852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (i = 0; i < img->Height; i++) { 892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (j = 0; j < img->Width; j++) { 902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (c==1) 912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_printf("%02x ", data[0]); 922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (c==2) 932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_printf("%02x%02x ", data[0], data[1]); 942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (c==3) 952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_printf("%02x%02x%02x ", data[0], data[1], data[2]); 962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (c==4) 972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]); 982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj data += (img->RowStride - img->Width) * c; 992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_printf("\n"); 1012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#endif 1032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 1042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#endif 1052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/* 1082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Compute floor(log_base_2(n)). 1092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * If n < 0 return -1. 1102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 1112019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic int 1122019a976f07ff418dde2dfc7cc74667ef66d7764sewardjlogbase2( int n ) 113b4df768d103fab8a7cb260812cde6789d1128878florian{ 1142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint i = 1; 1152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint log2 = 0; 1162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (n < 0) 1182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return -1; 1192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (n == 0) 1218844a6329d275814456e3a2a5a7bffac75da0957florian return 0; 1222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj while ( n > i ) { 1242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj i *= 2; 1252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj log2++; 1262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (i != n) { 1282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return log2 - 1; 1292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 1312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return log2; 1322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 1342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 1382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Return the simple base format for a given internal texture format. 1392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 1412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 1422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 1442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 1462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 1478844a6329d275814456e3a2a5a7bffac75da0957florian * This is the format which is used during texture application (i.e. the 1488844a6329d275814456e3a2a5a7bffac75da0957florian * texture format and env mode determine the arithmetic used. 1492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 1502019a976f07ff418dde2dfc7cc74667ef66d7764sewardjGLint 1512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_base_tex_format( GLcontext *ctx, GLint internalFormat ) 1522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 1532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 1542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA: 1552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA4: 1562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA8: 1572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA12: 1582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA16: 1592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_ALPHA; 1602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 1: 1612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE: 1622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE4: 1632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE8: 1642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12: 1652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE16: 1662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE; 1672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 2: 1682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA: 1692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE4_ALPHA4: 1702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE6_ALPHA2: 1712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE8_ALPHA8: 1722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12_ALPHA4: 1732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12_ALPHA12: 1742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE16_ALPHA16: 1752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE_ALPHA; 1762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY: 1772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY4: 1782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY8: 1792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY12: 1802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY16: 1812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INTENSITY; 1828844a6329d275814456e3a2a5a7bffac75da0957florian case 3: 1832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB: 1842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_R3_G3_B2: 1852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB4: 1862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB5: 1872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB8: 1882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB10: 1892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB12: 1902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB16: 1912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 1922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 4: 1932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA: 1942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA2: 1952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA4: 1962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB5_A1: 1972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA8: 1982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB10_A2: 1992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA12: 2002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA16: 2012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 2022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.EXT_paletted_texture) { 2072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX: 2092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX1_EXT: 2102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX2_EXT: 2112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX4_EXT: 2122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX8_EXT: 2132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX12_EXT: 2142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX16_EXT: 2152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_COLOR_INDEX; 2162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.SGIX_depth_texture) { 2222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT: 2242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT16_SGIX: 2252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT24_SGIX: 2262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT32_SGIX: 2272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_DEPTH_COMPONENT; 2282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.ARB_texture_compression) { 2342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_ALPHA: 2362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_ALPHA; 2372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_LUMINANCE: 2382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE; 2392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_LUMINANCE_ALPHA: 2402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE_ALPHA; 2412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_INTENSITY: 2422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INTENSITY; 2432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGB: 2442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 2452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA: 2462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 2472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.TDFX_texture_compression_FXT1) { 2532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGB_FXT1_3DFX: 2552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 2562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_FXT1_3DFX: 2572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 2582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.EXT_texture_compression_s3tc) { 2642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 2672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 2682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 2692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 2702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 2712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.S3_s3tc) { 2772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB_S3TC: 2792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB4_S3TC: 2802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 2812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA_S3TC: 2822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA4_S3TC: 2832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 2842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 2852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 2862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.MESA_ycbcr_texture) { 2902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (internalFormat == GL_YCBCR_MESA) 2912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_YCBCR_MESA; 2922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.ARB_texture_float) { 2952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 2962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA16F_ARB: 2972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA32F_ARB: 2982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_ALPHA; 2992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA16F_ARB: 3002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA32F_ARB: 3012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGBA; 3022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB16F_ARB: 3032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB32F_ARB: 3042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_RGB; 3052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY16F_ARB: 3062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY32F_ARB: 3072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INTENSITY; 3082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE16F_ARB: 3092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE32F_ARB: 3102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE; 3112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA16F_ARB: 3122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA32F_ARB: 3132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_LUMINANCE_ALPHA; 3142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 3152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ; /* fallthrough */ 3162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 3172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 3182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 3192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return -1; /* error */ 3202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 3212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 3222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 3232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 3242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if the given internal texture format is a color/RGBA format 3252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * (i.e., not color index, depth, stencil, etc). 3262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat an internal texture format token (or 1, 2, 3, or 4) 3272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. 3282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 3292019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 3302019a976f07ff418dde2dfc7cc74667ef66d7764sewardjis_color_format(GLenum internalFormat) 3312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 3322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 3332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA: 3342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA4: 3352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA8: 3362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA12: 3372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA16: 3382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 1: 3392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE: 3402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE4: 3412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE8: 3422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12: 3432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE16: 3442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 2: 3452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA: 3462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE4_ALPHA4: 3472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE6_ALPHA2: 3482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE8_ALPHA8: 3492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12_ALPHA4: 3502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE12_ALPHA12: 351b4df768d103fab8a7cb260812cde6789d1128878florian case GL_LUMINANCE16_ALPHA16: 3522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY: 3532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY4: 3542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY8: 3552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY12: 3562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY16: 3572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 3: 3582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB: 3592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_R3_G3_B2: 3602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB4: 3612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB5: 3622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB8: 3632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB10: 3642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB12: 3652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB16: 3662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case 4: 3672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA: 3682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA2: 3692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA4: 3702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB5_A1: 3712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA8: 372b4df768d103fab8a7cb260812cde6789d1128878florian case GL_RGB10_A2: 3732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA12: 3742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA16: 3752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* float texture formats */ 3762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA16F_ARB: 3772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_ALPHA32F_ARB: 3782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE16F_ARB: 3792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE32F_ARB: 3802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA16F_ARB: 3812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_LUMINANCE_ALPHA32F_ARB: 3822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY16F_ARB: 3832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_INTENSITY32F_ARB: 3842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB16F_ARB: 3852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB32F_ARB: 3862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA16F_ARB: 3872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA32F_ARB: 3882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 3892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_YCBCR_MESA: /* not considered to be RGB */ 3902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 3912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 3922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 3932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 394b4df768d103fab8a7cb260812cde6789d1128878florian 3952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 3962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 3972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if the given internal texture format is a color index format. 3982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 3992019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 400b4df768d103fab8a7cb260812cde6789d1128878florianis_index_format(GLenum internalFormat) 4012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 4022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 4032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX: 4042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX1_EXT: 4052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX2_EXT: 4062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX4_EXT: 4072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX8_EXT: 4082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX12_EXT: 4092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COLOR_INDEX16_EXT: 4102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 4112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 4122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 4132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 4142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 4152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 4182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if the given internal texture format is a depth component format. 4192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 4202019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 4212019a976f07ff418dde2dfc7cc74667ef66d7764sewardjis_depth_format(GLenum internalFormat) 4222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 4232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 4242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT16_ARB: 4252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT24_ARB: 426b4df768d103fab8a7cb260812cde6789d1128878florian case GL_DEPTH_COMPONENT32_ARB: 4272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_DEPTH_COMPONENT: 4282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 4292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 4302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 4312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 4322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 4332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 434b4df768d103fab8a7cb260812cde6789d1128878florian 4352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 4362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if the given internal texture format is a YCbCr format. 4372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 4382019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 4392019a976f07ff418dde2dfc7cc74667ef66d7764sewardjis_ycbcr_format(GLenum internalFormat) 4402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 4412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 4422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_YCBCR_MESA: 4432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 444b4df768d103fab8a7cb260812cde6789d1128878florian default: 4452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 4462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 4472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 4482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 4512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if it is a supported compressed format. 4522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 4532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat the internal format token provided by the user. 4542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 4552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \ret GL_TRUE if \p internalFormat is a supported compressed format, or 4562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_FALSE otherwise. 4572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 4582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX 4592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * are supported. 4602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 4612019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 4622019a976f07ff418dde2dfc7cc74667ef66d7764sewardjis_compressed_format(GLcontext *ctx, GLenum internalFormat) 4632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 4642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (internalFormat) { 4652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGB_FXT1_3DFX: 4662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_FXT1_3DFX: 4672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 4682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 4692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 4702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 4712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB_S3TC: 4722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGB4_S3TC: 4732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA_S3TC: 4742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_RGBA4_S3TC: 4752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 4762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 4772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 4782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 4792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 4802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 4822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 4832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Store a gl_texture_image pointer in a gl_texture_object structure 4842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * according to the target and level parameters. 4852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 4862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param tObj texture object. 4872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 4882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level. 4892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param texImage texture image. 4902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 4912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * This was basically prompted by the introduction of cube maps. 4922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 4932019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid 4942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_set_tex_image(struct gl_texture_object *tObj, 4952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum target, GLint level, 4962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage) 4972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 4982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(tObj); 4992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage); 5002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 5012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_1D: 5022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_2D: 5032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_3D: 5042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj tObj->Image[0][level] = texImage; 5052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 5062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 5072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 5082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 5092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 5102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 5112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: { 5122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLuint face = ((GLuint) target - 5132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 5142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj tObj->Image[face][level] = texImage; 5152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 5162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 5172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_RECTANGLE_NV: 5182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(level == 0); 5192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj tObj->Image[0][level] = texImage; 5202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 5212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 5222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(NULL, "bad target in _mesa_set_tex_image()"); 5232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 5242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 5252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 5262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = tObj; 5272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 528b4df768d103fab8a7cb260812cde6789d1128878florian 5292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 5312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Allocate a texture image structure. 5322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Called via ctx->Driver.NewTextureImage() unless overriden by a device 5342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * driver. 5352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return a pointer to gl_texture_image struct with all fields initialized to 5372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * zero. 5382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 5392019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstruct gl_texture_image * 5402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_new_texture_image( GLcontext *ctx ) 5412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 5422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (void) ctx; 5432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return CALLOC_STRUCT(gl_texture_image); 5442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 5452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 5482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Free texture image. 5492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param teximage texture image. 5512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Free the texture image structure and the associated image data if it's not 5532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * marked as client data. 5542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 5552019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid 5562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_delete_texture_image( struct gl_texture_image *teximage ) 5572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 5582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (teximage->Data && !teximage->IsClientData) { 5592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE( teximage->Data ); 5602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj teximage->Data = NULL; 5612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 5622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj FREE( teximage ); 5632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 5642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 5672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test if a target is a proxy target. 5682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 5702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 5722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 5732019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 5742019a976f07ff418dde2dfc7cc74667ef66d7764sewardjis_proxy_target(GLenum target) 5752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 5762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return (target == GL_PROXY_TEXTURE_1D || 5772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_PROXY_TEXTURE_2D || 5782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_PROXY_TEXTURE_3D || 5792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 5802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_PROXY_TEXTURE_RECTANGLE_NV); 5812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 5822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 5842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 5852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Get the texture object that corresponds to the target of the given texture unit. 586611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj * 587611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj * \param ctx GL context. 588611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj * \param texUnit texture unit. 589611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj * \param target texture target. 5902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return pointer to the texture object on success, or NULL on failure. 5922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 5932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \sa gl_texture_unit. 5942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 5952019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstruct gl_texture_object * 5962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, 5972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum target) 5982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 5992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 6002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_1D: 6012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current1D; 6022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_1D: 6032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy1D; 6042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_2D: 6052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current2D; 6062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_2D: 6072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy2D; 6082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_3D: 6092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current3D; 6102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_3D: 6112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy3D; 6122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 6132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 6142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 6152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 6162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 6172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 6182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_ARB: 6192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Extensions.ARB_texture_cube_map 6202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ? texUnit->CurrentCubeMap : NULL; 6212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 6222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Extensions.ARB_texture_cube_map 6232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ? ctx->Texture.ProxyCubeMap : NULL; 6242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_RECTANGLE_NV: 6252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Extensions.NV_texture_rectangle 6262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ? texUnit->CurrentRect : NULL; 6272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_RECTANGLE_NV: 6282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Extensions.NV_texture_rectangle 6292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ? ctx->Texture.ProxyRect : NULL; 6302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 6312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 6322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 6332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 6342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 6352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 6362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 6372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 6382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Get the texture image struct which corresponds to target and level 6392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * of the given texture unit. 6402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 6412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 6422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param texUnit texture unit. 6432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 6442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level. 6452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 6462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return pointer to the texture image structure on success, or NULL on failure. 6472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 6482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \sa gl_texture_unit. 6492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 6502019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstruct gl_texture_image * 6512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 6522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum target, GLint level) 6532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 6542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texUnit); 6552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(level < MAX_TEXTURE_LEVELS); 6562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 6572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_1D: 6582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current1D->Image[0][level]; 6592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_1D: 6602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy1D->Image[0][level]; 6612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_2D: 6622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current2D->Image[0][level]; 6632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_2D: 6642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy2D->Image[0][level]; 6652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_3D: 6662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->Current3D->Image[0][level]; 6672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_3D: 6682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.Proxy3D->Image[0][level]; 6692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 6702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 6712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 6722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 6732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 6742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 6752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.ARB_texture_cube_map) { 6762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLuint face = ((GLuint) target - 6772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); 6782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->CurrentCubeMap->Image[face][level]; 6792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 6802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 6812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 6822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 6832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.ARB_texture_cube_map) 6842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.ProxyCubeMap->Image[0][level]; 6852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 6862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 6872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_RECTANGLE_NV: 6882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.NV_texture_rectangle) { 6892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(level == 0); 6902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texUnit->CurrentRect->Image[0][level]; 6912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 6922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 6932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 6942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 6952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_RECTANGLE_NV: 6962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Extensions.NV_texture_rectangle) { 6972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(level == 0); 6982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Texture.ProxyRect->Image[0][level]; 6992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 7012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 7042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(ctx, "bad target in _mesa_select_tex_image()"); 705a52e37e8547ed42060a262d510047eea202dbe9fsewardj return NULL; 706ad43b3aab3af108802ea091bc58d12903ec002a8florian } 707ad43b3aab3af108802ea091bc58d12903ec002a8florian} 708a52e37e8547ed42060a262d510047eea202dbe9fsewardj 709a52e37e8547ed42060a262d510047eea202dbe9fsewardj 7108844a6329d275814456e3a2a5a7bffac75da0957florian/** 7118844a6329d275814456e3a2a5a7bffac75da0957florian * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 7128844a6329d275814456e3a2a5a7bffac75da0957florian * it and install it. Only return NULL if passed a bad parameter or run 7138844a6329d275814456e3a2a5a7bffac75da0957florian * out of memory. 7148844a6329d275814456e3a2a5a7bffac75da0957florian */ 7158844a6329d275814456e3a2a5a7bffac75da0957florianstruct gl_texture_image * 7168844a6329d275814456e3a2a5a7bffac75da0957florian_mesa_get_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, 7178844a6329d275814456e3a2a5a7bffac75da0957florian GLenum target, GLint level) 7188844a6329d275814456e3a2a5a7bffac75da0957florian{ 7198844a6329d275814456e3a2a5a7bffac75da0957florian struct gl_texture_image *texImage; 7208844a6329d275814456e3a2a5a7bffac75da0957florian texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 7218844a6329d275814456e3a2a5a7bffac75da0957florian if (!texImage) { 7228844a6329d275814456e3a2a5a7bffac75da0957florian struct gl_texture_object *texObj; 7238844a6329d275814456e3a2a5a7bffac75da0957florian texImage = ctx->Driver.NewTextureImage(ctx); 7248844a6329d275814456e3a2a5a7bffac75da0957florian if (!texImage) { 7258844a6329d275814456e3a2a5a7bffac75da0957florian _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 7268844a6329d275814456e3a2a5a7bffac75da0957florian return NULL; 7278844a6329d275814456e3a2a5a7bffac75da0957florian } 7288844a6329d275814456e3a2a5a7bffac75da0957florian texObj = _mesa_select_tex_object(ctx, texUnit, target); 7298844a6329d275814456e3a2a5a7bffac75da0957florian ASSERT(texObj); 7308844a6329d275814456e3a2a5a7bffac75da0957florian _mesa_set_tex_image(texObj, target, level, texImage); 7318844a6329d275814456e3a2a5a7bffac75da0957florian } 7328844a6329d275814456e3a2a5a7bffac75da0957florian return texImage; 7332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 7342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 7352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 7362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 7372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Return pointer to the specified proxy texture image. 7382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Note that proxy textures are per-context, not per-texture unit. 7392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return pointer to texture image or NULL if invalid target, invalid 7402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * level, or out of memory. 7412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 7422019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstruct gl_texture_image * 7432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level) 7442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 7452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 7462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 7472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 ) 7482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 7502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 7512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_1D: 7522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level >= ctx->Const.MaxTextureLevels) 7532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Texture.Proxy1D->Image[0][level]; 7552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Driver.NewTextureImage(ctx); 7572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 7592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 761b4df768d103fab8a7cb260812cde6789d1128878florian ctx->Texture.Proxy1D->Image[0][level] = texImage; 7622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 7632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = ctx->Texture.Proxy1D; 7642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texImage; 7662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_2D: 7672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level >= ctx->Const.MaxTextureLevels) 7682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Texture.Proxy2D->Image[0][level]; 7702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Driver.NewTextureImage(ctx); 7722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 7742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Texture.Proxy2D->Image[0][level] = texImage; 7772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 7782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = ctx->Texture.Proxy2D; 7792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texImage; 7812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_3D: 7822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level >= ctx->Const.Max3DTextureLevels) 7832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Texture.Proxy3D->Image[0][level]; 7852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Driver.NewTextureImage(ctx); 7872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 7882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 7892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Texture.Proxy3D->Image[0][level] = texImage; 7922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 7932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = ctx->Texture.Proxy3D; 7942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 7952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texImage; 7962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_CUBE_MAP: 7972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level >= ctx->Const.MaxCubeTextureLevels) 7982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 7992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Texture.ProxyCubeMap->Image[0][level]; 8002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 8012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = ctx->Driver.NewTextureImage(ctx); 8022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 8032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 8042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 8052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Texture.ProxyCubeMap->Image[0][level] = texImage; 8072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 8082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = ctx->Texture.ProxyCubeMap; 8092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texImage; 8112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_RECTANGLE_NV: 8122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level > 0) 813611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj return NULL; 814611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj texImage = ctx->Texture.ProxyRect->Image[0][level]; 815611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj if (!texImage) { 816611b06e7d8f45e291dbfadcfa42e2f55021d73f5sewardj texImage = ctx->Driver.NewTextureImage(ctx); 8172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 8182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 8192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 8202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Texture.ProxyRect->Image[0][level] = texImage; 8222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Set the 'back' pointer */ 8232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexObject = ctx->Texture.ProxyRect; 8242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return texImage; 8262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 8272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return NULL; 8282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 8302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 8332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Get the maximum number of allowed mipmap levels. 8342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 8352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 8362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 8372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 8382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return the maximum number of allowed mipmap levels for the given 8392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * texture target, or zero if passed a bad target. 8402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 8412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \sa gl_constants. 8422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 8432019a976f07ff418dde2dfc7cc74667ef66d7764sewardjGLint 8442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_max_texture_levels(GLcontext *ctx, GLenum target) 8452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 8462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 8472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_1D: 8482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_1D: 8492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_2D: 8502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_2D: 8512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Const.MaxTextureLevels; 8522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_3D: 8532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_3D: 8542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Const.Max3DTextureLevels; 8552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 8562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 8572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 8582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 8592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 8602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 8612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_CUBE_MAP_ARB: 8622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 8632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return ctx->Const.MaxCubeTextureLevels; 8642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 8652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_TEXTURE_RECTANGLE_NV: 8662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_RECTANGLE_NV: 8672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return 1; 8682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj break; 8692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 8702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return 0; /* bad target */ 8712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 8722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 8732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#if 000 /* not used anymore */ 8772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/* 8782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * glTexImage[123]D can accept a NULL image pointer. In this case we 8792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * create a texture image with unspecified image contents per the OpenGL 8802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * spec. 8812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 8822019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLubyte * 8832019a976f07ff418dde2dfc7cc74667ef66d7764sewardjmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 8842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 8852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLint components = _mesa_components_in_format(format); 8862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLint numPixels = width * height * depth; 8872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 8882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 8892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#ifdef DEBUG 8902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* 8912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Let's see if anyone finds this. If glTexImage2D() is called with 8922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * a NULL image pointer then load the texture image with something 8932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * interesting instead of leaving it indeterminate. 8942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 8952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (data) { 8962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj static const char message[8][32] = { 8972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X XXXXX XXX X ", 8982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " XX XX X X X X X ", 8992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X X X X X X ", 9002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X XXXX XXX XXXXX ", 9012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X X X X X ", 9022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X X X X X X ", 9032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " X X XXXXX XXX X X ", 9042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj " " 9052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj }; 9062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 9072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLubyte *imgPtr = data; 9082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint h, i, j, k; 9092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (h = 0; h < depth; h++) { 9102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (i = 0; i < height; i++) { 9112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint srcRow = 7 - (i % 8); 9122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (j = 0; j < width; j++) { 9132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint srcCol = j % 32; 9142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 9152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (k = 0; k < components; k++) { 9162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj *imgPtr++ = texel; 9172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 9182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 9192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 9202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 9212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 9222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#endif 9232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 9242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return data; 9252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 9262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj#endif 9272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 928a52e37e8547ed42060a262d510047eea202dbe9fsewardj 929ad43b3aab3af108802ea091bc58d12903ec002a8florian 930ad43b3aab3af108802ea091bc58d12903ec002a8florian/** 931a52e37e8547ed42060a262d510047eea202dbe9fsewardj * Reset the fields of a gl_texture_image struct to zero. 932a52e37e8547ed42060a262d510047eea202dbe9fsewardj * 9338844a6329d275814456e3a2a5a7bffac75da0957florian * \param img texture image structure. 9348844a6329d275814456e3a2a5a7bffac75da0957florian * 9358844a6329d275814456e3a2a5a7bffac75da0957florian * This is called when a proxy texture test fails, we set all the 9368844a6329d275814456e3a2a5a7bffac75da0957florian * image members (except DriverData) to zero. 9378844a6329d275814456e3a2a5a7bffac75da0957florian * It's also used in glTexImage[123]D as a safeguard to be sure all 9388844a6329d275814456e3a2a5a7bffac75da0957florian * required fields get initialized properly by the Driver.TexImage[123]D 9398844a6329d275814456e3a2a5a7bffac75da0957florian * functions. 9408844a6329d275814456e3a2a5a7bffac75da0957florian */ 9418844a6329d275814456e3a2a5a7bffac75da0957florianstatic void 9428844a6329d275814456e3a2a5a7bffac75da0957florianclear_teximage_fields(struct gl_texture_image *img) 9438844a6329d275814456e3a2a5a7bffac75da0957florian{ 9448844a6329d275814456e3a2a5a7bffac75da0957florian ASSERT(img); 9458844a6329d275814456e3a2a5a7bffac75da0957florian img->Format = 0; 9468844a6329d275814456e3a2a5a7bffac75da0957florian img->IntFormat = 0; 9478844a6329d275814456e3a2a5a7bffac75da0957florian img->Border = 0; 9488844a6329d275814456e3a2a5a7bffac75da0957florian img->Width = 0; 9498844a6329d275814456e3a2a5a7bffac75da0957florian img->Height = 0; 9508844a6329d275814456e3a2a5a7bffac75da0957florian img->Depth = 0; 9518844a6329d275814456e3a2a5a7bffac75da0957florian img->RowStride = 0; 9528844a6329d275814456e3a2a5a7bffac75da0957florian img->Width2 = 0; 9538844a6329d275814456e3a2a5a7bffac75da0957florian img->Height2 = 0; 9548844a6329d275814456e3a2a5a7bffac75da0957florian img->Depth2 = 0; 9558844a6329d275814456e3a2a5a7bffac75da0957florian img->WidthLog2 = 0; 9568844a6329d275814456e3a2a5a7bffac75da0957florian img->HeightLog2 = 0; 9578844a6329d275814456e3a2a5a7bffac75da0957florian img->DepthLog2 = 0; 9582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Data = NULL; 9592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->TexFormat = &_mesa_null_texformat; 9602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->FetchTexelc = NULL; 9612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->FetchTexelf = NULL; 9622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->IsCompressed = 0; 9632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->CompressedSize = 0; 9642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 9652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 9662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 967b4df768d103fab8a7cb260812cde6789d1128878florian/** 9682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Initialize basic fields of the gl_texture_image struct. 9692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 9702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 9712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 9722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param img texture image structure to be initialized. 9732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param width image width. 9742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param height image height. 9752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param depth image depth. 9762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param border image border. 9772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat internal format. 9782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 9792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Fills in the fields of \p img with the given information. 9802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Note: width, height and depth include the border. 9812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 9822019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid 9832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_init_teximage_fields(GLcontext *ctx, GLenum target, 9842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *img, 9852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height, GLsizei depth, 9862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint border, GLenum internalFormat) 9872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 9882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(img); 9892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Format = _mesa_base_tex_format( ctx, internalFormat ); 9902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(img->Format > 0); 9912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->IntFormat = internalFormat; 9922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Border = border; 9932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Width = width; 9942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Height = height; 9952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Depth = depth; 9962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->RowStride = width; 9972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->WidthLog2 = logbase2(width - 2 * border); 9982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (height == 1) /* 1-D texture */ 9992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->HeightLog2 = 0; 10002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 10012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->HeightLog2 = logbase2(height - 2 * border); 10022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (depth == 1) /* 2-D texture */ 10032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->DepthLog2 = 0; 10042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 10052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->DepthLog2 = logbase2(depth - 2 * border); 10062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Width2 = width - 2 * border; /*1 << img->WidthLog2;*/ 10072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Height2 = height - 2 * border; /*1 << img->HeightLog2;*/ 10082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->Depth2 = depth - 2 * border; /*1 << img->DepthLog2;*/ 10092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 10102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->IsCompressed = is_compressed_format(ctx, internalFormat); 10112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (img->IsCompressed) 10122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->CompressedSize = ctx->Driver.CompressedTextureSize(ctx, width, 10132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj height, depth, internalFormat); 10142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 10152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->CompressedSize = 0; 10162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((width == 1 || _mesa_bitcount(width - 2 * border) == 1) && 10182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (height == 1 || _mesa_bitcount(height - 2 * border) == 1) && 10192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (depth == 1 || _mesa_bitcount(depth - 2 * border) == 1)) 10202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->_IsPowerOfTwo = GL_TRUE; 10212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else 10222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->_IsPowerOfTwo = GL_FALSE; 10232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Compute Width/Height/DepthScale for mipmap lod computation */ 10252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_RECTANGLE_NV) { 10262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* scale = 1.0 since texture coords directly map to texels */ 10272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->WidthScale = 1.0; 10282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->HeightScale = 1.0; 10292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->DepthScale = 1.0; 10302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 10312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 10322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->WidthScale = (GLfloat) img->Width; 10332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->HeightScale = (GLfloat) img->Height; 10342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj img->DepthScale = (GLfloat) img->Depth; 10352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 10362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 10372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 10402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * This is the fallback for Driver.TestProxyTexImage(). Test the texture 10412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * level, width, height and depth against the ctx->Const limits for textures. 10422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 10432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * A hardware driver might override this function if, for example, the 10442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * max 3D texture size is 512x512x64 (i.e. not a cube). 10452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 10462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 10472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 10482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 10492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level as passed to glTexImage 10502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat as passed to glTexImage 10512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param format as passed to glTexImage 10522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param type as passed to glTexImage 10532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param width as passed to glTexImage 10542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param height as passed to glTexImage 10552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param depth as passed to glTexImage 10562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param border as passed to glTexImage 10572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 10582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 10592019a976f07ff418dde2dfc7cc74667ef66d7764sewardjGLboolean 10602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, 10612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint internalFormat, GLenum format, GLenum type, 10622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint width, GLint height, GLint depth, GLint border) 10632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 10642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint maxSize; 10652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (void) internalFormat; 10672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (void) format; 10682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (void) type; 10692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 10702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj switch (target) { 10712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_1D: 10722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 10732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 2 * border || width > 2 + maxSize || 10742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 10752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(width - 2 * border) != 1) || 10762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level >= ctx->Const.MaxTextureLevels) { 10772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* bad width or level */ 10782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 10792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 10802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 10812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_2D: 10822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 10832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 2 * border || width > 2 + maxSize || 10842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 10852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(width - 2 * border) != 1) || 10862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj height < 2 * border || height > 2 + maxSize || 10872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 10882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(height - 2 * border) != 1) || 10892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level >= ctx->Const.MaxTextureLevels) { 10902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* bad width or height or level */ 10912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 10922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 10932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 10942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_3D: 10952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 10962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 2 * border || width > 2 + maxSize || 10972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 10982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(width - 2 * border) != 1) || 10992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj height < 2 * border || height > 2 + maxSize || 11002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 11012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(height - 2 * border) != 1) || 11022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj depth < 2 * border || depth > 2 + maxSize || 11032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 11042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(depth - 2 * border) != 1) || 11052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level >= ctx->Const.Max3DTextureLevels) { 11062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* bad width or height or depth or level */ 11072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 11082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 11102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_RECTANGLE_NV: 11112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 1 || width > ctx->Const.MaxTextureRectSize || 11122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj height < 1 || height > ctx->Const.MaxTextureRectSize || 11132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level != 0) { 11142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* bad width or height or level */ 11152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 11162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 11182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 11192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 11202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 2 * border || width > 2 + maxSize || 11212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 11222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(width - 2 * border) != 1) || 11232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj height < 2 * border || height > 2 + maxSize || 11242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && 11252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_bitcount(height - 2 * border) != 1) || 11262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level >= ctx->Const.MaxCubeTextureLevels) { 11272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* bad width or height */ 11282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 11292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 11312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj default: 11322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 11332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 11342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 11362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 11372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 11382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 11392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test the glTexImage[123]D() parameters for errors. 11402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 11412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 11422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target given by the user. 11432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level given by the user. 11442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param internalFormat internal format given by the user. 11452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param format pixel data format given by the user. 11462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param type pixel data type given by the user. 11472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param dimensions texture image dimensions (must be 1, 2 or 3). 11482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param width image width given by the user. 11492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param height image height given by the user. 11502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param depth image depth given by the user. 11512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param border image border given by the user. 11522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 11532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 1154ad43b3aab3af108802ea091bc58d12903ec002a8florian * 1155ad43b3aab3af108802ea091bc58d12903ec002a8florian * Verifies each of the parameters against the constants specified in 1156ad43b3aab3af108802ea091bc58d12903ec002a8florian * __GLcontextRec::Const and the supported extensions, and according to the 1157ad43b3aab3af108802ea091bc58d12903ec002a8florian * OpenGL specification. 1158ad43b3aab3af108802ea091bc58d12903ec002a8florian */ 1159ad43b3aab3af108802ea091bc58d12903ec002a8florianstatic GLboolean 1160ad43b3aab3af108802ea091bc58d12903ec002a8floriantexture_error_check( GLcontext *ctx, GLenum target, 1161ad43b3aab3af108802ea091bc58d12903ec002a8florian GLint level, GLint internalFormat, 1162ad43b3aab3af108802ea091bc58d12903ec002a8florian GLenum format, GLenum type, 1163ad43b3aab3af108802ea091bc58d12903ec002a8florian GLuint dimensions, 1164ad43b3aab3af108802ea091bc58d12903ec002a8florian GLint width, GLint height, 1165ad43b3aab3af108802ea091bc58d12903ec002a8florian GLint depth, GLint border ) 1166ad43b3aab3af108802ea091bc58d12903ec002a8florian{ 1167ad43b3aab3af108802ea091bc58d12903ec002a8florian const GLboolean isProxy = is_proxy_target(target); 1168ad43b3aab3af108802ea091bc58d12903ec002a8florian GLboolean sizeOK; 1169ad43b3aab3af108802ea091bc58d12903ec002a8florian 1170ad43b3aab3af108802ea091bc58d12903ec002a8florian /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1171ad43b3aab3af108802ea091bc58d12903ec002a8florian if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1172ad43b3aab3af108802ea091bc58d12903ec002a8florian if (!isProxy) { 1173ad43b3aab3af108802ea091bc58d12903ec002a8florian _mesa_error(ctx, GL_INVALID_VALUE, 1174ad43b3aab3af108802ea091bc58d12903ec002a8florian "glTexImage%dD(level=%d)", dimensions, level); 1175ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1176ad43b3aab3af108802ea091bc58d12903ec002a8florian return GL_TRUE; 1177ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1178ad43b3aab3af108802ea091bc58d12903ec002a8florian 1179ad43b3aab3af108802ea091bc58d12903ec002a8florian /* Check border */ 1180ad43b3aab3af108802ea091bc58d12903ec002a8florian if (border < 0 || border > 1 || 1181ad43b3aab3af108802ea091bc58d12903ec002a8florian ((target == GL_TEXTURE_RECTANGLE_NV || 1182ad43b3aab3af108802ea091bc58d12903ec002a8florian target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 11832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 11842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 11852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%dD(border=%d)", dimensions, border); 11862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11879d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 11882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 11907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (width < 0 || height < 0 || depth < 0) { 11912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 11922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 11932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%dD(width, height or depth < 0)", dimensions); 11942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 11962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 11979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 11982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check target and call ctx->Driver.TestProxyTexImage() to check the 11992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * level, width, height and depth. 12007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj */ 12012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 12022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { 12032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 12042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 12052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 12062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, 1, 1, border); 12079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 12082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 12092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 12107ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 12112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 2) { 12142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) { 12152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 12162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 12179d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj format, type, 12182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 12192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1220652b56aecd7af6012e82801557b3833f74b19b59sewardj else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 1221652b56aecd7af6012e82801557b3833f74b19b59sewardj (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 12227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 12232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.ARB_texture_cube_map) { 12242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 12252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = (width == height) && 12282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 12299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj level, internalFormat, format, type, 12302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 12312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1232652b56aecd7af6012e82801557b3833f74b19b59sewardj else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV || 1233652b56aecd7af6012e82801557b3833f74b19b59sewardj target == GL_TEXTURE_RECTANGLE_NV) { 12347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!ctx->Extensions.NV_texture_rectangle) { 12352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 12362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, 12392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GL_PROXY_TEXTURE_RECTANGLE_NV, 12402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 12419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj format, type, 12422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 12432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1244652b56aecd7af6012e82801557b3833f74b19b59sewardj else { 1245652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 12467ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 12472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 3) { 12502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) { 12512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_3D, 12522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 12539d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj format, type, 12542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, depth, border); 12552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1256652b56aecd7af6012e82801557b3833f74b19b59sewardj else { 1257652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 12587ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 12592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 12622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem( ctx, "bad dims in texture_error_check" ); 12632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12659d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 12662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!sizeOK) { 12672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 12687ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, 12692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 12702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions, level, width, height, depth); 12712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 12759d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Check internalFormat */ 12762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 12772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 1278652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_INVALID_VALUE, 1279652b56aecd7af6012e82801557b3833f74b19b59sewardj "glTexImage%dD(internalFormat=0x%x)", 12807ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj dimensions, internalFormat); 12812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 12852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check incoming image format and type */ 12862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 12879d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 12882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. 12892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 12907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!isProxy) { 12912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 12922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%dD(format or type)", dimensions); 12932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 12952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 12962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 12979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (format == GL_YCBCR_MESA || internalFormat == GL_YCBCR_MESA) { 12982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Extensions.MESA_ycbcr_texture); 12992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (format != GL_YCBCR_MESA || 13007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj internalFormat != GL_YCBCR_MESA || 13012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (type != GL_UNSIGNED_SHORT_8_8_MESA && 13022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj type != GL_UNSIGNED_SHORT_8_8_REV_MESA)) { 13032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj char message[100]; 13042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_sprintf(message, 13052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%d(format/type/internalFormat YCBCR mismatch", 13062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions); 13079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_ENUM, message); 1308ad43b3aab3af108802ea091bc58d12903ec002a8florian return GL_TRUE; /* error */ 1309ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1310ad43b3aab3af108802ea091bc58d12903ec002a8florian if (target != GL_TEXTURE_2D && 1311ad43b3aab3af108802ea091bc58d12903ec002a8florian target != GL_PROXY_TEXTURE_2D && 1312ad43b3aab3af108802ea091bc58d12903ec002a8florian target != GL_TEXTURE_RECTANGLE_NV && 1313ad43b3aab3af108802ea091bc58d12903ec002a8florian target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1314ad43b3aab3af108802ea091bc58d12903ec002a8florian if (!isProxy) 1315ad43b3aab3af108802ea091bc58d12903ec002a8florian _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1316ad43b3aab3af108802ea091bc58d12903ec002a8florian return GL_TRUE; 1317ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1318ad43b3aab3af108802ea091bc58d12903ec002a8florian if (border != 0) { 1319ad43b3aab3af108802ea091bc58d12903ec002a8florian if (!isProxy) { 13202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj char message[100]; 13212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_sprintf(message, 13227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj "glTexImage%d(format=GL_YCBCR_MESA and border=%d)", 13232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions, border); 13242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, message); 13252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 13272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 13302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_compressed_format(ctx, internalFormat)) { 13312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D) { 13327ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* OK */ 13332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (ctx->Extensions.ARB_texture_cube_map && 13352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target == GL_PROXY_TEXTURE_CUBE_MAP || 13362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && 13372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { 13382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* OK */ 13399d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 13402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 13412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 13427ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_ENUM, 13432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%d(target)", dimensions); 13442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 13452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (border != 0) { 13482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!isProxy) { 13499d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 13502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexImage%D(border!=0)", dimensions); 13512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1352652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_TRUE; 1353652b56aecd7af6012e82801557b3833f74b19b59sewardj } 13547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 13552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 13562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* if we get here, the parameters are OK */ 13572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 13582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 13592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 13602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 13619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj/** 13622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test glTexSubImage[123]D() parameters for errors. 13632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 1364652b56aecd7af6012e82801557b3833f74b19b59sewardj * \param ctx GL context. 1365652b56aecd7af6012e82801557b3833f74b19b59sewardj * \param dimensions texture image dimensions (must be 1, 2 or 3). 13667ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * \param target texture target given by the user. 13672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level given by the user. 13682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param xoffset sub-image x offset given by the user. 13692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param yoffset sub-image y offset given by the user. 13702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param zoffset sub-image z offset given by the user. 13712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param format pixel data format given by the user. 13722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param type pixel data type given by the user. 13739d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj * \param width image width given by the user. 13742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param height image height given by the user. 13752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param depth image depth given by the user. 1376652b56aecd7af6012e82801557b3833f74b19b59sewardj * 1377652b56aecd7af6012e82801557b3833f74b19b59sewardj * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 13787ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * 13792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Verifies each of the parameters against the constants specified in 13802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * __GLcontextRec::Const and the supported extensions, and according to the 13812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * OpenGL specification. 13822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 13832019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 13842019a976f07ff418dde2dfc7cc74667ef66d7764sewardjsubtexture_error_check( GLcontext *ctx, GLuint dimensions, 13859d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLenum target, GLint level, 13862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLint yoffset, GLint zoffset, 13872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint width, GLint height, GLint depth, 1388652b56aecd7af6012e82801557b3833f74b19b59sewardj GLenum format, GLenum type ) 1389652b56aecd7af6012e82801557b3833f74b19b59sewardj{ 13907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 13912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *destTex; 13922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 13932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check target */ 13942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 13952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_1D) { 13962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 13979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 13982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 13992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else if (dimensions == 2) { 14012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 14022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 14032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.ARB_texture_cube_map) { 14042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 14052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 14082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (ctx->Extensions.NV_texture_rectangle && 14092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_TEXTURE_RECTANGLE_NV) { 14107ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!ctx->Extensions.NV_texture_rectangle) { 14112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 14122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target != GL_TEXTURE_2D) { 14162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 14179d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 14182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14207ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else if (dimensions == 3) { 14212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_3D) { 14222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 14232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 14279d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_problem( ctx, "invalid dims in texture_error_check" ); 14282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14307ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 14312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Basic level check */ 14322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 14332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 14342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 14379d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (width < 0) { 14388844a6329d275814456e3a2a5a7bffac75da0957florian _mesa_error(ctx, GL_INVALID_VALUE, 14398844a6329d275814456e3a2a5a7bffac75da0957florian "glTexSubImage%dD(width=%d)", dimensions, width); 14408844a6329d275814456e3a2a5a7bffac75da0957florian return GL_TRUE; 14418844a6329d275814456e3a2a5a7bffac75da0957florian } 14428844a6329d275814456e3a2a5a7bffac75da0957florian if (height < 0 && dimensions > 1) { 14438844a6329d275814456e3a2a5a7bffac75da0957florian _mesa_error(ctx, GL_INVALID_VALUE, 14448844a6329d275814456e3a2a5a7bffac75da0957florian "glTexSubImage%dD(height=%d)", dimensions, height); 14458844a6329d275814456e3a2a5a7bffac75da0957florian return GL_TRUE; 14468844a6329d275814456e3a2a5a7bffac75da0957florian } 14478844a6329d275814456e3a2a5a7bffac75da0957florian if (depth < 0 && dimensions > 2) { 14482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 14492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexSubImage%dD(depth=%d)", dimensions, depth); 14507ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 14512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 14532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj destTex = _mesa_select_tex_image(ctx, texUnit, target, level); 14542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 14552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!destTex) { 14562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* undefined image level */ 14579d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 14582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14607ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 14612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (xoffset < -((GLint)destTex->Border)) { 14622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 14632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions); 14642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 14679d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 14682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions); 14692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 14712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions > 1) { 14722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (yoffset < -((GLint)destTex->Border)) { 14732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 14742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions); 14752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 14782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 14792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj dimensions); 1480652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_TRUE; 1481652b56aecd7af6012e82801557b3833f74b19b59sewardj } 14827ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 14832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions > 2) { 14842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (zoffset < -((GLint)destTex->Border)) { 14852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 14862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 14899d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 14902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1492652b56aecd7af6012e82801557b3833f74b19b59sewardj } 1493652b56aecd7af6012e82801557b3833f74b19b59sewardj 14947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 14952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, 14962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexSubImage%dD(format or type)", dimensions); 14972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 14982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 14992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (destTex->IsCompressed) { 15019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj const struct gl_texture_unit *texUnit; 15022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const struct gl_texture_image *texImage; 15032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1504652b56aecd7af6012e82801557b3833f74b19b59sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 1505652b56aecd7af6012e82801557b3833f74b19b59sewardj 15067ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D) { 15072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* OK */ 15082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (ctx->Extensions.ARB_texture_cube_map && 15102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target == GL_PROXY_TEXTURE_CUBE_MAP || 15112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && 15122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { 15139d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* OK */ 15142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 15167ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_ENUM, 15172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexSubImage%D(target)", dimensions); 15182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 15192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* offset must be multiple of 4 */ 15212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((xoffset & 3) || (yoffset & 3)) { 15222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 15239d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj "glTexSubImage%D(xoffset or yoffset)", dimensions); 15242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 15252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1526652b56aecd7af6012e82801557b3833f74b19b59sewardj /* size must be multiple of 4 or equal to whole texture size */ 1527652b56aecd7af6012e82801557b3833f74b19b59sewardj if ((width & 3) && (GLuint) width != texImage->Width) { 15287ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_OPERATION, 15292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexSubImage%D(width)", dimensions); 15302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 15312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((height & 3) && (GLuint) height != texImage->Height) { 15332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 15342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glTexSubImage%D(width)", dimensions); 15359d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 15362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1538652b56aecd7af6012e82801557b3833f74b19b59sewardj 1539652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_FALSE; 15407ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj} 15412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 15442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test glCopyTexImage[12]D() parameters for errors. 15452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 15462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 15479d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj * \param dimensions texture image dimensions (must be 1, 2 or 3). 15482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target given by the user. 15492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level given by the user. 15507ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * \param internalFormat internal format given by the user. 15512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param width image width given by the user. 15522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param height image height given by the user. 15532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param depth image depth given by the user. 15542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param border texture border. 15552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 15562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15579d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj * 15582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Verifies each of the parameters against the constants specified in 15592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * __GLcontextRec::Const and the supported extensions, and according to the 15607ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * OpenGL specification. 15612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 15622019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 15632019a976f07ff418dde2dfc7cc74667ef66d7764sewardjcopytexture_error_check( GLcontext *ctx, GLuint dimensions, 15642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum target, GLint level, GLint internalFormat, 15652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint width, GLint height, GLint border ) 15662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 15679d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLenum format, type; 15682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLboolean sizeOK; 15692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 15712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 15722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 15732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage%dD(level=%d)", dimensions, level); 15742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 15752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 15762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Check border */ 15782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (border < 0 || border > 1 || 15792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ((target == GL_TEXTURE_RECTANGLE_NV || 1580652b56aecd7af6012e82801557b3833f74b19b59sewardj target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1581652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_TRUE; 15827ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 15832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 15842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* The format and type aren't really significant here, but we need to pass 15852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * something to TestProxyTexImage(). 15862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 15872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format = _mesa_base_tex_format(ctx, internalFormat); 15882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj type = GL_FLOAT; 15899d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 15902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check target and call ctx->Driver.TestProxyTexImage() to check the 15912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * level, width, height and depth. 1592652b56aecd7af6012e82801557b3833f74b19b59sewardj */ 1593652b56aecd7af6012e82801557b3833f74b19b59sewardj if (dimensions == 1) { 15947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_TEXTURE_1D) { 15952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 15962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 15972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 15982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, 1, 1, border); 15992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 16019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 16022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 16032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1604652b56aecd7af6012e82801557b3833f74b19b59sewardj } 1605652b56aecd7af6012e82801557b3833f74b19b59sewardj else if (dimensions == 2) { 16067ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_TEXTURE_2D) { 16072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 16082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 16092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 16102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 16112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 16139d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 16142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.ARB_texture_cube_map) { 16152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 16167ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 16172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = (width == height) && 16192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 16202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, format, type, 16212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 16222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16239d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj else if (target == GL_TEXTURE_RECTANGLE_NV) { 16242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.NV_texture_rectangle) { 16252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 16267ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 16272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj sizeOK = ctx->Driver.TestProxyTexImage(ctx, 16292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GL_PROXY_TEXTURE_RECTANGLE_NV, 16302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj level, internalFormat, 16312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 16322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 16339d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 16342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 16352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 16367ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 16372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 16402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(ctx, "invalid dimensions in copytexture_error_check"); 16412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 16422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16439d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 16442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!sizeOK) { 16452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 16467ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, 16472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage1D(width=%d)", width); 16482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 16502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(dimensions == 2); 16512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 16522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage2D(width=%d, height=%d)", width, height); 16539d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 16542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 16552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1656652b56aecd7af6012e82801557b3833f74b19b59sewardj 1657652b56aecd7af6012e82801557b3833f74b19b59sewardj if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 16587ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, 16592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage%dD(internalFormat)", dimensions); 16602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 16612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 16632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_compressed_format(ctx, internalFormat)) { 16642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_2D) { 16659d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_error(ctx, GL_INVALID_ENUM, 16662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage%d(target)", dimensions); 16672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 1668652b56aecd7af6012e82801557b3833f74b19b59sewardj } 1669652b56aecd7af6012e82801557b3833f74b19b59sewardj if (border != 0) { 16707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_OPERATION, 16712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexImage%D(border!=0)", dimensions); 16722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 16732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 16752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 16762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* if we get here, the parameters are OK */ 16779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_FALSE; 16782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 16792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 16807ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 16812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 16822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Test glCopyTexImage[12]D() parameters for errors. 16832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 16842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param ctx GL context. 16852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param dimensions texture image dimensions (must be 1, 2 or 3). 16862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target given by the user. 16879d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj * \param level image level given by the user. 16882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param xoffset sub-image x offset given by the user. 16892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param yoffset sub-image y offset given by the user. 1690652b56aecd7af6012e82801557b3833f74b19b59sewardj * \param zoffset sub-image z offset given by the user. 1691652b56aecd7af6012e82801557b3833f74b19b59sewardj * \param width image width given by the user. 16927ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * \param height image height given by the user. 16932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 16942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 16952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * 16962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Verifies each of the parameters against the constants specified in 16972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * __GLcontextRec::Const and the supported extensions, and according to the 16982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * OpenGL specification. 16999d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj */ 17002019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLboolean 17012019a976f07ff418dde2dfc7cc74667ef66d7764sewardjcopytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 17027ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLenum target, GLint level, 17032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLint yoffset, GLint zoffset, 17042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height ) 17052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 17062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 17072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *teximage; 17082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 17099d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Check target */ 17102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 17112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_1D) { 17127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 17132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 2) { 17172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 17182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 17199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!ctx->Extensions.ARB_texture_cube_map) { 17202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 17212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 17232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_TEXTURE_RECTANGLE_NV) { 17252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.NV_texture_rectangle) { 17262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 17272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 17302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target != GL_TEXTURE_2D) { 17312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1732652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_TRUE; 1733652b56aecd7af6012e82801557b3833f74b19b59sewardj } 17347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 17352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 3) { 17362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_3D) { 17372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 17382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 17422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check level */ 17432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1744652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_INVALID_VALUE, 1745652b56aecd7af6012e82801557b3833f74b19b59sewardj "glCopyTexSubImage%dD(level=%d)", dimensions, level); 17467ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 17472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 17492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Check size */ 17502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 0) { 17512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 17522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(width=%d)", dimensions, width); 17539d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 17542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions > 1 && height < 0) { 1756652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_INVALID_VALUE, 1757652b56aecd7af6012e82801557b3833f74b19b59sewardj "glCopyTexSubImage%dD(height=%d)", dimensions, height); 17587ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 17592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 17612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj teximage = _mesa_select_tex_image(ctx, texUnit, target, level); 17622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!teximage) { 17632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 17642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(undefined texture level: %d)", 17659d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj dimensions, level); 17662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1768652b56aecd7af6012e82801557b3833f74b19b59sewardj 1769652b56aecd7af6012e82801557b3833f74b19b59sewardj if (xoffset < -((GLint)teximage->Border)) { 17707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, 17712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 17722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 17752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 17762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(xoffset+width)", dimensions); 17779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 1778ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1779ad43b3aab3af108802ea091bc58d12903ec002a8florian if (dimensions > 1) { 1780ad43b3aab3af108802ea091bc58d12903ec002a8florian if (yoffset < -((GLint)teximage->Border)) { 1781ad43b3aab3af108802ea091bc58d12903ec002a8florian _mesa_error(ctx, GL_INVALID_VALUE, 1782ad43b3aab3af108802ea091bc58d12903ec002a8florian "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 1783ad43b3aab3af108802ea091bc58d12903ec002a8florian return GL_TRUE; 1784ad43b3aab3af108802ea091bc58d12903ec002a8florian } 1785ad43b3aab3af108802ea091bc58d12903ec002a8florian /* NOTE: we're adding the border here, not subtracting! */ 1786ad43b3aab3af108802ea091bc58d12903ec002a8florian if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 1787ad43b3aab3af108802ea091bc58d12903ec002a8florian _mesa_error(ctx, GL_INVALID_VALUE, 17882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(yoffset+height)", dimensions); 17892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 1790652b56aecd7af6012e82801557b3833f74b19b59sewardj } 1791652b56aecd7af6012e82801557b3833f74b19b59sewardj } 17927ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 17932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions > 2) { 17942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (zoffset < -((GLint)teximage->Border)) { 17952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 17962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(zoffset)", dimensions); 17972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 17982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 17999d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 18002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 18012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 18027ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_TRUE; 18032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (teximage->IsCompressed) { 18072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target != GL_TEXTURE_2D) { 18082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, 18099d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj "glCopyTexSubImage%d(target)", dimensions); 18102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 18112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1812652b56aecd7af6012e82801557b3833f74b19b59sewardj /* offset must be multiple of 4 */ 1813652b56aecd7af6012e82801557b3833f74b19b59sewardj if ((xoffset & 3) || (yoffset & 3)) { 18147ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, 18152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCopyTexSubImage%D(xoffset or yoffset)", dimensions); 18162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 18172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* size must be multiple of 4 */ 18192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 18202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, 18219d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj "glCopyTexSubImage%D(width)", dimensions); 18222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 18232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 1824652b56aecd7af6012e82801557b3833f74b19b59sewardj if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 1825652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_INVALID_VALUE, 18267ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj "glCopyTexSubImage%D(height)", dimensions); 18272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_TRUE; 18282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (teximage->IntFormat == GL_YCBCR_MESA) { 18322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 18339d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_TRUE; 18342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18367ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* if we get here, the parameters are OK */ 18372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_FALSE; 18382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 18392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 18422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Get texture image. Called by glGetTexImage. 18439d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj * 18442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param target texture target. 18452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param level image level. 18467ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * \param format pixel data format for returned image. 18472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param type pixel data type for returned image. 18482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \param pixels returned pixel data. 18492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 18502019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 18512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_GetTexImage( GLenum target, GLint level, GLenum format, 18522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum type, GLvoid *pixels ) 18539d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj{ 18542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const struct gl_texture_unit *texUnit; 18552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const struct gl_texture_object *texObj; 1856652b56aecd7af6012e82801557b3833f74b19b59sewardj const struct gl_texture_image *texImage; 1857652b56aecd7af6012e82801557b3833f74b19b59sewardj GLint maxLevels = 0; 18587ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GET_CURRENT_CONTEXT(ctx); 18592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 18602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); 18622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 18632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texObj || is_proxy_target(target)) { 18642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); 18659d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 18662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18687ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj maxLevels = _mesa_max_texture_levels(ctx, target); 18692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 18702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= maxLevels) { 18722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); 18732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 18742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18759d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 18762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (_mesa_sizeof_packed_type(type) <= 0) { 18772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 18787ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 18792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (_mesa_components_in_format(format) <= 0 || 18822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format == GL_STENCIL_INDEX) { 18832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 18842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 18859d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 18862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { 18887ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 18892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.SGIX_depth_texture && is_depth_format(format)) { 18922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 18932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 18959d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!ctx->Extensions.MESA_ycbcr_texture && is_ycbcr_format(format)) { 18962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); 18972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 18987ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 18992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!pixels) 19002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 19022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 19032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 19042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* invalid mipmap level, not an error */ 19059d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 19062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 19087ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!texImage->Data) { 19092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* no image data, not an error */ 19102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 19132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Make sure the requested image format is compatible with the 19142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * texture's format. 19159d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj */ 19162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_color_format(format) 19172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && !is_color_format(texImage->TexFormat->BaseFormat)) { 19187ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 19192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (is_index_format(format) 19222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && !is_index_format(texImage->TexFormat->BaseFormat)) { 19232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 19242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19259d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 19262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (is_depth_format(format) 19272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && !is_depth_format(texImage->TexFormat->BaseFormat)) { 19287ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 19292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (is_ycbcr_format(format) 19322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && !is_ycbcr_format(texImage->TexFormat->BaseFormat)) { 19332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)"); 19342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 19359d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 19362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 19372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj { 1938652b56aecd7af6012e82801557b3833f74b19b59sewardj const GLint width = texImage->Width; 1939652b56aecd7af6012e82801557b3833f74b19b59sewardj const GLint height = texImage->Height; 19407ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj const GLint depth = texImage->Depth; 19412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint img, row; 19422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (img = 0; img < depth; img++) { 19432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (row = 0; row < height; row++) { 19442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* compute destination address in client memory */ 19452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLvoid *dest = _mesa_image_address( &ctx->Pack, pixels, 19462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, format, type, 19479d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj img, row, 0); 19482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(dest); 19492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1950652b56aecd7af6012e82801557b3833f74b19b59sewardj if (format == GL_COLOR_INDEX) { 1951652b56aecd7af6012e82801557b3833f74b19b59sewardj GLuint indexRow[MAX_WIDTH]; 19527ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLint col; 19532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Can't use FetchTexel here because that returns RGBA */ 19542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texImage->TexFormat->IndexBits == 8) { 19552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLubyte *src = (const GLubyte *) texImage->Data; 19562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (col = 0; col < width; col++) { 19572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj indexRow[col] = src[texImage->Width * 19582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (img * texImage->Height + row) + col]; 19599d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 19602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->TexFormat->IndexBits == 16) { 1962652b56aecd7af6012e82801557b3833f74b19b59sewardj const GLushort *src = (const GLushort *) texImage->Data; 1963652b56aecd7af6012e82801557b3833f74b19b59sewardj for (col = 0; col < width; col++) { 19647ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj indexRow[col] = src[texImage->Width * 19652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (img * texImage->Height + row) + col]; 19662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 19692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_problem(ctx, 19702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "Color index problem in _mesa_GetTexImage"); 19719d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 19722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 19732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_pack_index_span(ctx, width, type, dest, 1974652b56aecd7af6012e82801557b3833f74b19b59sewardj indexRow, &ctx->Pack, 1975652b56aecd7af6012e82801557b3833f74b19b59sewardj 0 /* no image transfer */); 19767ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 19772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (format == GL_DEPTH_COMPONENT) { 19782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLfloat depthRow[MAX_WIDTH]; 19792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint col; 19802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (col = 0; col < width; col++) { 19812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*texImage->FetchTexelf)(texImage, col, row, img, 19822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj depthRow + col); 19839d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 19842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_pack_depth_span(ctx, width, dest, type, 19852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj depthRow, &ctx->Pack); 19867ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 19872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (format == GL_YCBCR_MESA) { 19882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* No pixel transfer */ 19892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLint rowstride = texImage->RowStride; 19902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MEMCPY(dest, 19912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (const GLushort *) texImage->Data + row * rowstride, 19922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width * sizeof(GLushort)); 19939d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* check for byte swapping */ 19942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR 19952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) || 19967ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj (texImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV 19972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && type == GL_UNSIGNED_SHORT_8_8_MESA)) { 19982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Pack.SwapBytes) 19992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_swap2((GLushort *) dest, width); 20002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (ctx->Pack.SwapBytes) { 20022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_swap2((GLushort *) dest, width); 20039d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 20042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 2006652b56aecd7af6012e82801557b3833f74b19b59sewardj /* general case: convert row to RGBA format */ 2007652b56aecd7af6012e82801557b3833f74b19b59sewardj GLfloat rgba[MAX_WIDTH][4]; 20087ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLint col; 20092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj for (col = 0; col < width; col++) { 20102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*texImage->FetchTexelf)(texImage, col, row, img, rgba[col]); 20112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_pack_rgba_span_float(ctx, width, 20132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (const GLfloat (*)[4]) rgba, 20142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, dest, &ctx->Pack, 20159d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 0 /* no image transfer */); 20162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } /* format */ 20172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } /* row */ 2018652b56aecd7af6012e82801557b3833f74b19b59sewardj } /* img */ 2019652b56aecd7af6012e82801557b3833f74b19b59sewardj } 20207ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj} 20212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/* 20252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Called from the API. Note that width includes the border. 20262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 20279d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 20282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 20292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLint border, GLenum format, 2030652b56aecd7af6012e82801557b3833f74b19b59sewardj GLenum type, const GLvoid *pixels ) 2031652b56aecd7af6012e82801557b3833f74b19b59sewardj{ 20327ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei postConvWidth = width; 20332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 20342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 20352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_color_format(internalFormat)) { 20372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 20382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20399d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 20402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_1D) { 20412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 2042652b56aecd7af6012e82801557b3833f74b19b59sewardj struct gl_texture_object *texObj; 2043652b56aecd7af6012e82801557b3833f74b19b59sewardj struct gl_texture_image *texImage; 20447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 20452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texture_error_check(ctx, target, level, internalFormat, 20462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 1, postConvWidth, 1, 1, border)) { 20472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* error was recorded */ 20482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 20519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 20522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 20532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2054652b56aecd7af6012e82801557b3833f74b19b59sewardj if (!texImage) { 2055652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 20567ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 20572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 20592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* free the old texture data */ 20602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 20612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->Data = NULL; 20639d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj clear_teximage_fields(texImage); /* not really needed, but helpful */ 20642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, 20652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, 1, 1, 2066652b56aecd7af6012e82801557b3833f74b19b59sewardj border, internalFormat); 2067652b56aecd7af6012e82801557b3833f74b19b59sewardj 20687ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 20692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 20702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TexImage1D); 20722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Give the texture to the driver! <pixels> may be null! */ 20742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, 20759d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj width, border, format, type, pixels, 20762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj &ctx->Unpack, texObj, texImage); 20772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20787ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj ASSERT(texImage->TexFormat); 20792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If driver didn't explicitly set this, use the defaults */ 20812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelc) 20822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D; 20832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelf) 20842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df; 20859d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT(texImage->FetchTexelc); 20862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->FetchTexelf); 20872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 20887ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* state update */ 20892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj->Complete = GL_FALSE; 20902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 20912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 20922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_1D) { 20932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 20942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 20959d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 20962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texture_error_check(ctx, target, level, internalFormat, 20972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 1, postConvWidth, 1, 1, border)) { 2098652b56aecd7af6012e82801557b3833f74b19b59sewardj /* when error, clear all proxy texture image parameters */ 2099652b56aecd7af6012e82801557b3833f74b19b59sewardj if (texImage) 21007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj clear_teximage_fields(texImage); 21012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 21032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* no error, set the tex image parameters */ 21042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage); 21052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, 21062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, 1, 1, 21079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj border, internalFormat); 21082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 21092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, format, type); 2110652b56aecd7af6012e82801557b3833f74b19b59sewardj } 2111652b56aecd7af6012e82801557b3833f74b19b59sewardj } 21127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 21132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 21142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 21152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 21172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 21202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 21212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height, GLint border, 21227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLenum format, GLenum type, 21232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *pixels ) 21242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 21252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width, postConvHeight = height; 21262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 21272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 21282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (is_color_format(internalFormat)) { 21302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 21312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj &postConvHeight); 2132652b56aecd7af6012e82801557b3833f74b19b59sewardj } 2133652b56aecd7af6012e82801557b3833f74b19b59sewardj 21347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_TEXTURE_2D || 21352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (ctx->Extensions.ARB_texture_cube_map && 21362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 21372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 21382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (ctx->Extensions.NV_texture_rectangle && 21392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target == GL_TEXTURE_RECTANGLE_NV)) { 21402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* non-proxy target */ 21419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj struct gl_texture_unit *texUnit; 21422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 21432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 2144652b56aecd7af6012e82801557b3833f74b19b59sewardj 2145652b56aecd7af6012e82801557b3833f74b19b59sewardj if (texture_error_check(ctx, target, level, internalFormat, 21467ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj format, type, 2, postConvWidth, postConvHeight, 21472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1, border)) { 21482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* error was recorded */ 21492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 21522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 21539d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 21542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 21552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 21567ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 21572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 21592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* free the old texture data */ 21602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 21612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->Data = NULL; 21639d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj clear_teximage_fields(texImage); /* not really needed, but helpful */ 21642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, 21652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, postConvHeight, 1, 21667ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj border, internalFormat); 21672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 21692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 21702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TexImage2D); 21722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21739d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Give the texture to the driver! <pixels> may be null! */ 21742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, 21752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, border, format, type, pixels, 21767ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj &ctx->Unpack, texObj, texImage); 21772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->TexFormat); 21792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 21802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If driver didn't explicitly set these, use the defaults */ 21812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelc) 21822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; 21839d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!texImage->FetchTexelf) 21842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; 21852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->FetchTexelc); 2186652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(texImage->FetchTexelf); 2187652b56aecd7af6012e82801557b3833f74b19b59sewardj 21887ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* state update */ 21892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj->Complete = GL_FALSE; 21902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 21912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 21922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_2D || 21932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 21942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Extensions.ARB_texture_cube_map) || 21959d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj (target == GL_PROXY_TEXTURE_RECTANGLE_NV && 21962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Extensions.NV_texture_rectangle)) { 21972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 2198652b56aecd7af6012e82801557b3833f74b19b59sewardj struct gl_texture_image *texImage; 2199652b56aecd7af6012e82801557b3833f74b19b59sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 22007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (texture_error_check(ctx, target, level, internalFormat, 22012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 2, postConvWidth, postConvHeight, 22022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 1, border)) { 22032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* when error, clear all proxy texture image parameters */ 22042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texImage) 22052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(ctx->Texture.Proxy2D->Image[0][level]); 22062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj else { 22082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* no error, set the tex image parameters */ 22092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, 2210652b56aecd7af6012e82801557b3833f74b19b59sewardj postConvWidth, postConvHeight, 1, 2211652b56aecd7af6012e82801557b3833f74b19b59sewardj border, internalFormat); 22127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 22132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, format, type); 22142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 22172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 22182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 22199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 22202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 22212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2222652b56aecd7af6012e82801557b3833f74b19b59sewardj 2223652b56aecd7af6012e82801557b3833f74b19b59sewardj/* 22247ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj * Called by the API or display list executor. 22252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Note that width and height include the border. 22262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 22272019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 22282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 22292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height, GLsizei depth, 22302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint border, GLenum format, GLenum type, 22319d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj const GLvoid *pixels ) 22322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 22332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 2234652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2235652b56aecd7af6012e82801557b3833f74b19b59sewardj 22367ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_TEXTURE_3D) { 22372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 22382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 22392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 22402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 22412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texture_error_check(ctx, target, level, (GLint) internalFormat, 22422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, 3, width, height, depth, border)) { 22439d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; /* error was recorded */ 22442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2246652b56aecd7af6012e82801557b3833f74b19b59sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 2247652b56aecd7af6012e82801557b3833f74b19b59sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 22487ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 22492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 22502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 22512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 22522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 22542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 22559d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 22562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->Data = NULL; 22572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); /* not really needed, but helpful */ 2258652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_init_teximage_fields(ctx, target, texImage, 2259652b56aecd7af6012e82801557b3833f74b19b59sewardj width, height, depth, 22607ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj border, internalFormat); 22612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 22622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 22632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 22642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 22652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TexImage3D); 22662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 22679d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* Give the texture to the driver! <pixels> may be null! */ 22682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, 22692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, depth, border, format, type, 2270652b56aecd7af6012e82801557b3833f74b19b59sewardj pixels, &ctx->Unpack, texObj, texImage); 2271652b56aecd7af6012e82801557b3833f74b19b59sewardj 22727ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj ASSERT(texImage->TexFormat); 22732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 22742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If driver didn't explicitly set these, use the defaults */ 22752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelc) 22762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelc = texImage->TexFormat->FetchTexel3D; 22772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelf) 22782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelf = texImage->TexFormat->FetchTexel3Df; 22799d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT(texImage->FetchTexelc); 22802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->FetchTexelf); 22812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2282652b56aecd7af6012e82801557b3833f74b19b59sewardj /* state update */ 2283652b56aecd7af6012e82801557b3833f74b19b59sewardj texObj->Complete = GL_FALSE; 22847ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj ctx->NewState |= _NEW_TEXTURE; 22852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 22862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_3D) { 22872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 22882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 22892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 22902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texture_error_check(ctx, target, level, internalFormat, 22919d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj format, type, 3, width, height, depth, border)) { 22922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* when error, clear all proxy texture image parameters */ 22932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (texImage) 2294652b56aecd7af6012e82801557b3833f74b19b59sewardj clear_teximage_fields(texImage); 2295652b56aecd7af6012e82801557b3833f74b19b59sewardj } 22967ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 22972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* no error, set the tex image parameters */ 22982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 22992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, internalFormat); 23002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, 23012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, format, type); 23022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 23039d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 23042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 23052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 23067ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 23072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 23082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 23092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23112019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 23122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 23139d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLsizei width, GLsizei height, GLsizei depth, 23142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint border, GLenum format, GLenum type, 23152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *pixels ) 23167ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj{ 23172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 23182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj depth, border, format, type, pixels); 23192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 23202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23239d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 23242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexSubImage1D( GLenum target, GLint level, 23252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLsizei width, 23267ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLenum format, GLenum type, 23272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *pixels ) 23282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 23292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width; 23302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 23312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 23322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 23339d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GET_CURRENT_CONTEXT(ctx); 23342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 23352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23367ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 23372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 23382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* XXX should test internal format */ 23402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_color_format(format)) { 23412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 23422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 23439d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 23442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 23452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, 1, 1, format, type)) { 2346652b56aecd7af6012e82801557b3833f74b19b59sewardj return; /* error was detected */ 2347652b56aecd7af6012e82801557b3833f74b19b59sewardj } 23487ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 23492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 23512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 23522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(texImage); 23532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || !pixels) 23559d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; /* no-op, not an error */ 23562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 23587ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj xoffset += texImage->Border; 23592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TexSubImage1D); 23612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, 23622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, pixels, &ctx->Unpack, 23632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj, texImage); 23642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 23659d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj} 23662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2368652b56aecd7af6012e82801557b3833f74b19b59sewardjvoid GLAPIENTRY 2369652b56aecd7af6012e82801557b3833f74b19b59sewardj_mesa_TexSubImage2D( GLenum target, GLint level, 23707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLint xoffset, GLint yoffset, 23712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height, 23722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum format, GLenum type, 23732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *pixels ) 23742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 23752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width, postConvHeight = height; 23762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 23779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj struct gl_texture_object *texObj; 23782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 23792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 23807ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 23812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 23832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 23842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* XXX should test internal format */ 23862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_color_format(format)) { 23879d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 23882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj &postConvHeight); 23892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 23907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 23912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 23922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, postConvHeight, 1, format, type)) { 23932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* error was detected */ 23942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 23952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 23962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 23979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 23982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 23992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(texImage); 24007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 24012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || height == 0 || !pixels) 24022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* no-op, not an error */ 24032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 24052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset += texImage->Border; 24062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj yoffset += texImage->Border; 24079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 24082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TexSubImage2D); 24092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, 2410652b56aecd7af6012e82801557b3833f74b19b59sewardj width, height, format, type, pixels, 2411652b56aecd7af6012e82801557b3833f74b19b59sewardj &ctx->Unpack, texObj, texImage); 24127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj ctx->NewState |= _NEW_TEXTURE; 24132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 24142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24172019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 24182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_TexSubImage3D( GLenum target, GLint level, 24199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLint xoffset, GLint yoffset, GLint zoffset, 24202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLsizei height, GLsizei depth, 24212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum format, GLenum type, 2422652b56aecd7af6012e82801557b3833f74b19b59sewardj const GLvoid *pixels ) 2423652b56aecd7af6012e82801557b3833f74b19b59sewardj{ 24247ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj struct gl_texture_unit *texUnit; 24252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 24262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 24272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 24282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 24292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 24319d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_update_state(ctx); 24322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 24347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj width, height, depth, format, type)) { 24352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* error was detected */ 24362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 24372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 24392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 24402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 24419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj assert(texImage); 24422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || height == 0 || height == 0 || !pixels) 24447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; /* no-op, not an error */ 24452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 24472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset += texImage->Border; 24482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj yoffset += texImage->Border; 24492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj zoffset += texImage->Border; 24502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT(ctx->Driver.TexSubImage3D); 24522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.TexSubImage3D)(ctx, target, level, 24532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, zoffset, 24547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj width, height, depth, 24552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, type, pixels, 24562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj &ctx->Unpack, texObj, texImage ); 24572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 24582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 24592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 24622019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 24632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CopyTexImage1D( GLenum target, GLint level, 2464652b56aecd7af6012e82801557b3833f74b19b59sewardj GLenum internalFormat, 2465652b56aecd7af6012e82801557b3833f74b19b59sewardj GLint x, GLint y, 24667ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei width, GLint border ) 24672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 24682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 24692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 24702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 24712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width; 24722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 24739d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 24742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 2476652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_update_state(ctx); 2477652b56aecd7af6012e82801557b3833f74b19b59sewardj 24787ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (is_color_format(internalFormat)) { 24792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 24802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 24812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (copytexture_error_check(ctx, 1, target, level, internalFormat, 24832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, 1, border)) 24842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 24859d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 24862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 24872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 2488652b56aecd7af6012e82801557b3833f74b19b59sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 2489652b56aecd7af6012e82801557b3833f74b19b59sewardj if (!texImage) { 24907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 24912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 24922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 24932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 24942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* free the old texture data */ 24952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 24962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 24979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage->Data = NULL; 24982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 24992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); /* not really needed, but helpful */ 2500652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1, 2501652b56aecd7af6012e82801557b3833f74b19b59sewardj border, internalFormat); 25027ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 25032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.CopyTexImage1D); 25052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, 25062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj x, y, width, border); 25072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->TexFormat); 25099d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 25102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If driver didn't explicitly set these, use the defaults */ 25112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelc) 25127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D; 25132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelf) 25142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df; 25152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->FetchTexelc); 25162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->FetchTexelf); 25172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* state update */ 25199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj->Complete = GL_FALSE; 25202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 25212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 25227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 25232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25252019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 25262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 25272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint x, GLint y, GLsizei width, GLsizei height, 25282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint border ) 25299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj{ 25302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 25312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 25327ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj struct gl_texture_image *texImage; 25332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width, postConvHeight = height; 25342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 25352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 25362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 25382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 25399d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 25402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_color_format(internalFormat)) { 25412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, 2542652b56aecd7af6012e82801557b3833f74b19b59sewardj &postConvHeight); 2543652b56aecd7af6012e82801557b3833f74b19b59sewardj } 25447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 25452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (copytexture_error_check(ctx, 2, target, level, internalFormat, 25462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, postConvHeight, border)) 25472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 25482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 25502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 25519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 25522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 25532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 2554652b56aecd7af6012e82801557b3833f74b19b59sewardj return; 2555652b56aecd7af6012e82801557b3833f74b19b59sewardj } 25567ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else if (texImage->Data && !texImage->IsClientData) { 25572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* free the old texture data */ 25582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 25592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 25602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->Data = NULL; 25612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); /* not really needed, but helpful */ 25639d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj _mesa_init_teximage_fields(ctx, target, texImage, 25642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, postConvHeight, 1, 25652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, internalFormat); 2566652b56aecd7af6012e82801557b3833f74b19b59sewardj 2567652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(ctx->Driver.CopyTexImage2D); 25687ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, 25692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj x, y, width, height, border); 25702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage->TexFormat); 25722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If driver didn't explicitly set these, use the defaults */ 25742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelc) 25759d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; 25762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->FetchTexelf) 25772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; 2578652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(texImage->FetchTexelc); 2579652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(texImage->FetchTexelf); 25807ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 25812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* state update */ 25822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj->Complete = GL_FALSE; 25832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 25842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 25852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 25879d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 25882019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 25892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CopyTexSubImage1D( GLenum target, GLint level, 25907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLint xoffset, GLint x, GLint y, GLsizei width ) 25912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 25922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 25932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 25942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei postConvWidth = width; 25952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 25962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 25979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 25983c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 25992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 26007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 26012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* XXX should test internal format */ 26022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); 26033c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj 26042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (copytexsubimage_error_check(ctx, 1, target, level, 26052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, 0, 0, postConvWidth, 1)) 26062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 26079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 26082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 2610652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(texImage); 2611652b56aecd7af6012e82801557b3833f74b19b59sewardj 26127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 26132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset += texImage->Border; 26142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.CopyTexSubImage1D); 26162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width); 26172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 26182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 26199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 26203c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj 26212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardjvoid GLAPIENTRY 26232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CopyTexSubImage2D( GLenum target, GLint level, 26242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLint yoffset, 26253c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj GLint x, GLint y, GLsizei width, GLsizei height ) 26262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 26272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 26282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 26299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLsizei postConvWidth = width, postConvHeight = height; 26302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 26312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2632652b56aecd7af6012e82801557b3833f74b19b59sewardj 2633652b56aecd7af6012e82801557b3833f74b19b59sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 26347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_update_state(ctx); 26352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* XXX should test internal format */ 26372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 26382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 26402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj postConvWidth, postConvHeight)) 26419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 26423c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj 26432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 26452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage); 26462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26473c49aaa6df5f162cdcd260e55d1990c2e196df37sewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 26482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset += texImage->Border; 26492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj yoffset += texImage->Border; 26502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT(ctx->Driver.CopyTexSubImage2D); 26522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 26532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, x, y, width, height); 2654652b56aecd7af6012e82801557b3833f74b19b59sewardj ctx->NewState |= _NEW_TEXTURE; 2655652b56aecd7af6012e82801557b3833f74b19b59sewardj} 26567ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 26572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26592019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 26602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CopyTexSubImage3D( GLenum target, GLint level, 26612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLint yoffset, GLint zoffset, 26622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint x, GLint y, GLsizei width, GLsizei height ) 26639d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj{ 26642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 26652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 26667ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei postConvWidth = width, postConvHeight = height; 26672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 26682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 26692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE) 26712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_update_state(ctx); 26722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26739d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj /* XXX should test internal format */ 26742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); 26752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2676652b56aecd7af6012e82801557b3833f74b19b59sewardj if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, 2677652b56aecd7af6012e82801557b3833f74b19b59sewardj zoffset, postConvWidth, postConvHeight)) 26787ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 26792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 26812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 26822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(texImage); 26832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* If we have a border, xoffset=-1 is legal. Bias by border width */ 26859d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj xoffset += texImage->Border; 26862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj yoffset += texImage->Border; 26872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj zoffset += texImage->Border; 2688652b56aecd7af6012e82801557b3833f74b19b59sewardj 2689652b56aecd7af6012e82801557b3833f74b19b59sewardj ASSERT(ctx->Driver.CopyTexSubImage3D); 26907ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 26912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, zoffset, 26922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj x, y, width, height); 26932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 26942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 26952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26979d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 26982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 26992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/**********************************************************************/ 27007ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj/****** Compressed Textures ******/ 27012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/**********************************************************************/ 27022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 27052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Error checking for glCompressedTexImage[123]D(). 27062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return error code or GL_NO_ERROR. 27079d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj */ 27082019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLenum 27092019a976f07ff418dde2dfc7cc74667ef66d7764sewardjcompressed_texture_error_check(GLcontext *ctx, GLint dimensions, 2710652b56aecd7af6012e82801557b3833f74b19b59sewardj GLenum target, GLint level, 2711652b56aecd7af6012e82801557b3833f74b19b59sewardj GLenum internalFormat, GLsizei width, 27127ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei height, GLsizei depth, GLint border, 27132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei imageSize) 27142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 27152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint expectedSize, maxLevels = 0, maxTextureSize; 27162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 27182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* 1D compressed textures not allowed */ 27199d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_INVALID_ENUM; 27202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 2) { 27227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (target == GL_PROXY_TEXTURE_2D) { 27232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxTextureLevels; 27242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_TEXTURE_2D) { 27262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxTextureLevels; 27272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 27299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!ctx->Extensions.ARB_texture_cube_map) 27302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; /*target*/ 27312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxCubeTextureLevels; 2732652b56aecd7af6012e82801557b3833f74b19b59sewardj } 2733652b56aecd7af6012e82801557b3833f74b19b59sewardj else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 27347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 27352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.ARB_texture_cube_map) 27362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; /*target*/ 27372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxCubeTextureLevels; 27382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 27402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; /*target*/ 27419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj } 27422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 3) { 27447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* 3D compressed textures not allowed */ 27452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; 27462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 27472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxTextureSize = 1 << (maxLevels - 1); 27492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!is_compressed_format(ctx, internalFormat)) 27519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_INVALID_ENUM; 27522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (border != 0) 27547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_INVALID_VALUE; 27552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* 27572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * XXX We should probably use the proxy texture error check function here. 27582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 27592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width < 1 || width > maxTextureSize || 27602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && logbase2(width) < 0)) 27619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_INVALID_VALUE; 27622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((height < 1 || height > maxTextureSize || 27647ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj (!ctx->Extensions.ARB_texture_non_power_of_two && logbase2(height) < 0)) 27652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && dimensions > 1) 27662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 27672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((depth < 1 || depth > maxTextureSize || 27692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (!ctx->Extensions.ARB_texture_non_power_of_two && logbase2(depth) < 0)) 27702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && dimensions > 2) 27719d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_INVALID_VALUE; 27722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* For cube map, width must equal height */ 2774652b56aecd7af6012e82801557b3833f74b19b59sewardj if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 2775652b56aecd7af6012e82801557b3833f74b19b59sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 27767ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_INVALID_VALUE; 27772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= maxLevels) 27792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 27802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27812019a976f07ff418dde2dfc7cc74667ef66d7764sewardj expectedSize = ctx->Driver.CompressedTextureSize(ctx, width, height, depth, 27822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat); 27839d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (expectedSize != imageSize) 27842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 27852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 2786652b56aecd7af6012e82801557b3833f74b19b59sewardj return GL_NO_ERROR; 2787652b56aecd7af6012e82801557b3833f74b19b59sewardj} 27887ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 27892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 27902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj/** 27912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * Error checking for glCompressedTexSubImage[123]D(). 27922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj * \return error code or GL_NO_ERROR. 27932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj */ 27942019a976f07ff418dde2dfc7cc74667ef66d7764sewardjstatic GLenum 27959d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjcompressed_subtexture_error_check(GLcontext *ctx, GLint dimensions, 27962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum target, GLint level, 27972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint xoffset, GLint yoffset, GLint zoffset, 27987ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei width, GLsizei height, GLsizei depth, 27992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum format, GLsizei imageSize) 28002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 28012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint expectedSize, maxLevels = 0, maxTextureSize; 28022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (dimensions == 1) { 28042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* 1D compressed textures not allowed */ 28059d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return GL_INVALID_ENUM; 28062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (dimensions == 2) { 2808652b56aecd7af6012e82801557b3833f74b19b59sewardj if (target == GL_PROXY_TEXTURE_2D) { 2809652b56aecd7af6012e82801557b3833f74b19b59sewardj maxLevels = ctx->Const.MaxTextureLevels; 28107ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 28112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_TEXTURE_2D) { 28122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxTextureLevels; 28132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 28152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!ctx->Extensions.ARB_texture_cube_map) 28162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; /*target*/ 28179d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj maxLevels = ctx->Const.MaxCubeTextureLevels; 28182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 2820652b56aecd7af6012e82801557b3833f74b19b59sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 2821652b56aecd7af6012e82801557b3833f74b19b59sewardj if (!ctx->Extensions.ARB_texture_cube_map) 28227ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return GL_INVALID_ENUM; /*target*/ 28232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = ctx->Const.MaxCubeTextureLevels; 28242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else { 28262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_ENUM; /*target*/ 28272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28299d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj else if (dimensions == 3) { 2830b13a92a1978b8c1446a2879249dbdd083a274477sewardj /* 3D compressed textures not allowed */ 2831b13a92a1978b8c1446a2879249dbdd083a274477sewardj return GL_INVALID_ENUM; 28327ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 2833b13a92a1978b8c1446a2879249dbdd083a274477sewardj 2834b13a92a1978b8c1446a2879249dbdd083a274477sewardj maxTextureSize = 1 << (maxLevels - 1); 2835b13a92a1978b8c1446a2879249dbdd083a274477sewardj 2836b13a92a1978b8c1446a2879249dbdd083a274477sewardj if (!is_compressed_format(ctx, format)) 2837b13a92a1978b8c1446a2879249dbdd083a274477sewardj return GL_INVALID_ENUM; 2838b13a92a1978b8c1446a2879249dbdd083a274477sewardj 2839b13a92a1978b8c1446a2879249dbdd083a274477sewardj if (width < 1 || width > maxTextureSize) 28402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28427ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if ((height < 1 || height > maxTextureSize) 28432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj && dimensions > 1) 28442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= maxLevels) 28472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28499d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if ((xoffset & 3) != 0 || (yoffset & 3) != 0) 28502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28527ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if ((width & 3) != 0 && width != 2 && width != 1) 28532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((height & 3) != 0 && height != 2 && height != 1) 28562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj expectedSize = ctx->Driver.CompressedTextureSize(ctx, width, height, depth, 28599d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj format); 28602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (expectedSize != imageSize) 28612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_INVALID_VALUE; 28627ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 28632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return GL_NO_ERROR; 28642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 28652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28682019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 28699d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 28702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum internalFormat, GLsizei width, 28712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint border, GLsizei imageSize, 2872652b56aecd7af6012e82801557b3833f74b19b59sewardj const GLvoid *data) 2873652b56aecd7af6012e82801557b3833f74b19b59sewardj{ 28747ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GET_CURRENT_CONTEXT(ctx); 28752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 28762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_1D) { 28782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 28792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 28802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 28819d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLenum error = compressed_texture_error_check(ctx, 1, target, level, 28822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, 1, 1, border, imageSize); 28832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 2884652b56aecd7af6012e82801557b3833f74b19b59sewardj _mesa_error(ctx, error, "glCompressedTexImage1D"); 2885652b56aecd7af6012e82801557b3833f74b19b59sewardj return; 28867ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 28872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 28882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 28892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 28902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 28912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 28922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D"); 28939d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 28942019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 28967ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj MESA_PBUFFER_FREE(texImage->Data); 28972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 28982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage->Data = NULL; 28992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 29012019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, internalFormat); 29022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29039d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT(ctx->Driver.CompressedTexImage1D); 29042019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 29052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, border, 2906d07b8566ab17faf70748cfce1304699f1d15c34esewardj imageSize, data, 2907d07b8566ab17faf70748cfce1304699f1d15c34esewardj texObj, texImage); 29087ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 29092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* state update */ 29102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj->Complete = GL_FALSE; 29112019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 29122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_1D) { 29142019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 29159d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLenum error = compressed_texture_error_check(ctx, 1, target, level, 29162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, 1, 1, border, imageSize); 29172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!error) { 2918d07b8566ab17faf70748cfce1304699f1d15c34esewardj ASSERT(ctx->Driver.TestProxyTexImage); 2919d07b8566ab17faf70748cfce1304699f1d15c34esewardj error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 29207ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj internalFormat, GL_NONE, GL_NONE, 29212019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, 1, 1, border); 29222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 29242019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* if error, clear all proxy texture image parameters */ 29252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 29262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 29279d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (texImage) 29282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); 29292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29307ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 29312019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* store the teximage parameters */ 29322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 29332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 29342019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 29352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 29362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 29379d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj border, internalFormat); 29382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29407ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 29412019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1D(target)"); 29422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 29432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29442019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 29452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29479d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 29482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 29492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum internalFormat, GLsizei width, 29507ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei height, GLint border, GLsizei imageSize, 29512019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *data) 29522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 29532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 29542019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 29552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_2D || 29579d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj (ctx->Extensions.ARB_texture_cube_map && 29582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 29592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 29607ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj struct gl_texture_unit *texUnit; 29612019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 29622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 29632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error = compressed_texture_error_check(ctx, 2, target, level, 29642019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, height, 1, border, imageSize); 29652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 29662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, error, "glCompressedTexImage2D"); 29679d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 29682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29707ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 29712019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 29722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 29732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 29742019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); 29752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 29762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 29779d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj else if (texImage->Data && !texImage->IsClientData) { 29782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 29792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 2980652b56aecd7af6012e82801557b3833f74b19b59sewardj texImage->Data = NULL; 2981652b56aecd7af6012e82801557b3833f74b19b59sewardj 29827ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 29832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, internalFormat); 29842019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.CompressedTexImage2D); 29862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, 29872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, height, 29882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, imageSize, data, 29899d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj, texImage); 29902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 29912019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* state update */ 2992652b56aecd7af6012e82801557b3833f74b19b59sewardj texObj->Complete = GL_FALSE; 2993652b56aecd7af6012e82801557b3833f74b19b59sewardj ctx->NewState |= _NEW_TEXTURE; 29947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 29952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_2D || 29962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 29972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->Extensions.ARB_texture_cube_map)) { 29982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 29992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error = compressed_texture_error_check(ctx, 2, target, level, 30002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, height, 1, border, imageSize); 30019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!error) { 30022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TestProxyTexImage); 30032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 30047ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj internalFormat, GL_NONE, GL_NONE, 30052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, 1, border); 30062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 30082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* if error, clear all proxy texture image parameters */ 30092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 30102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 30119d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (texImage) 30122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); 30132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30147ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 30152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* store the teximage parameters */ 30162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 30172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 30182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 30202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 30219d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj border, internalFormat); 30222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30247ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 30252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(target)"); 30262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 30272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 30292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30319d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 30322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 30332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum internalFormat, GLsizei width, 30347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei height, GLsizei depth, GLint border, 30352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei imageSize, const GLvoid *data) 30362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 30372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 30382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 30392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (target == GL_TEXTURE_3D) { 30419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj struct gl_texture_unit *texUnit; 30422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 30432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 30447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLenum error = compressed_texture_error_check(ctx, 3, target, level, 30452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, height, depth, border, imageSize); 30462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 30472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, error, "glCompressedTexImage3D"); 30482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 30492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 30532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_tex_image(ctx, texUnit, target, level); 30547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!texImage) { 30552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D"); 30562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 30572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (texImage->Data && !texImage->IsClientData) { 30592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MESA_PBUFFER_FREE(texImage->Data); 30602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texImage->Data = NULL; 30622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, height, depth, 30647ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj border, internalFormat); 30652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.CompressedTexImage3D); 30672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, 30682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, 30692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, depth, 30702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj border, imageSize, data, 30719d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj, texImage); 30722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 30732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* state update */ 30747ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texObj->Complete = GL_FALSE; 30752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 30762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj else if (target == GL_PROXY_TEXTURE_3D) { 30782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* Proxy texture: check for errors and update proxy state */ 30792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error = compressed_texture_error_check(ctx, 3, target, level, 30802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj internalFormat, width, height, depth, border, imageSize); 30819d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (!error) { 30822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(ctx->Driver.TestProxyTexImage); 30832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 30847ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj internalFormat, GL_NONE, GL_NONE, 30852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj width, height, depth, border); 30862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 30882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* if error, clear all proxy texture image parameters */ 30892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 30902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_get_proxy_tex_image(ctx, target, level); 30919d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (texImage) 30922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj clear_teximage_fields(texImage); 30932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 30947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 30952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* store the teximage parameters */ 30962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 30972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 30982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 30992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 31002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_init_teximage_fields(ctx, target, texImage, width, height, 31019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj depth, border, internalFormat); 31022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31047ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj else { 31052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3D(target)"); 31062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 31092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31119d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardjvoid GLAPIENTRY 31122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 31132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei width, GLenum format, 31147ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei imageSize, const GLvoid *data) 31152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 31162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 31172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 31182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 31192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error; 31202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 31219d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 31222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj error = compressed_subtexture_error_check(ctx, 1, target, level, 31247ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj xoffset, 0, 0, width, 1, 1, format, imageSize); 31252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 31262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, error, "glCompressedTexSubImage1D"); 31272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 31319d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 31322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 31332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(texImage); 31347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 31352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((GLint) format != texImage->IntFormat) { 31362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 31372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCompressedTexSubImage1D(format)"); 31382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if ((width == 1 || width == 2) && (GLuint) width != texImage->Width) { 31422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage1D(width)"); 31432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 31452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || !data) 31472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* no-op, not an error */ 31482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Driver.CompressedTexSubImage1D) { 31502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, 31519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj xoffset, width, 31522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, imageSize, data, 31532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj, texImage); 31547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj } 31552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 31562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 31572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31592019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 31602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 31619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj GLint yoffset, GLsizei width, GLsizei height, 31622019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum format, GLsizei imageSize, 31632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const GLvoid *data) 31647ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj{ 31652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 31662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 31672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 31682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error; 31692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 31702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 31719d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 31722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj error = compressed_subtexture_error_check(ctx, 2, target, level, 31732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, 0, width, height, 1, format, imageSize); 31747ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (error) { 31752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* XXX proxy target? */ 31762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, error, "glCompressedTexSubImage2D"); 31772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 31819d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 31822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 31832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(texImage); 31847ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 31852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((GLint) format != texImage->IntFormat) { 31862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 31872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCompressedTexSubImage2D(format)"); 31882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 31892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31919d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 31922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ((height == 1 || height == 2) && (GLuint) height != texImage->Height)) { 31932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage2D(size)"); 31947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 31952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 31962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 31972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || height == 0 || !data) 31982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* no-op, not an error */ 31992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (ctx->Driver.CompressedTexSubImage2D) { 32019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, 32022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, width, height, 32032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, imageSize, data, 32047ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj texObj, texImage); 32052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 32072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 32082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32102019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 32119d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 32122019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint yoffset, GLint zoffset, GLsizei width, 32132019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLsizei height, GLsizei depth, GLenum format, 32147ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj GLsizei imageSize, const GLvoid *data) 32152019a976f07ff418dde2dfc7cc74667ef66d7764sewardj{ 32162019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_unit *texUnit; 32172019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_object *texObj; 32182019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 32192019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLenum error; 32202019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 32219d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 32222019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32232019a976f07ff418dde2dfc7cc74667ef66d7764sewardj error = compressed_subtexture_error_check(ctx, 3, target, level, 32247ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj xoffset, yoffset, zoffset, width, height, depth, format, imageSize); 32252019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (error) { 32262019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, error, "glCompressedTexSubImage2D"); 32272019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32282019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32292019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32302019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 32319d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 32322019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 32332019a976f07ff418dde2dfc7cc74667ef66d7764sewardj assert(texImage); 32347ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj 32352019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if ((GLint) format != texImage->IntFormat) { 32362019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, 32372019a976f07ff418dde2dfc7cc74667ef66d7764sewardj "glCompressedTexSubImage3D(format)"); 32382019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32392019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32402019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32419d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (((width == 1 || width == 2) && (GLuint) width != texImage->Width) || 32422019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ((height == 1 || height == 2) && (GLuint) height != texImage->Height) || 32432019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ((depth == 1 || depth == 2) && (GLuint) depth != texImage->Depth)) { 32447ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage3D(size)"); 32452019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32462019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32472019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32482019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (width == 0 || height == 0 || depth == 0 || !data) 32492019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; /* no-op, not an error */ 32502019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32519d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj if (ctx->Driver.CompressedTexSubImage3D) { 32522019a976f07ff418dde2dfc7cc74667ef66d7764sewardj (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, 32532019a976f07ff418dde2dfc7cc74667ef66d7764sewardj xoffset, yoffset, zoffset, 32547ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj width, height, depth, 32552019a976f07ff418dde2dfc7cc74667ef66d7764sewardj format, imageSize, data, 32562019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj, texImage); 32572019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32582019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ctx->NewState |= _NEW_TEXTURE; 32592019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 32602019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32619d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 32622019a976f07ff418dde2dfc7cc74667ef66d7764sewardjvoid GLAPIENTRY 32632019a976f07ff418dde2dfc7cc74667ef66d7764sewardj_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) 32647ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj{ 32652019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const struct gl_texture_unit *texUnit; 32662019a976f07ff418dde2dfc7cc74667ef66d7764sewardj const struct gl_texture_object *texObj; 32672019a976f07ff418dde2dfc7cc74667ef66d7764sewardj struct gl_texture_image *texImage; 32682019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GLint maxLevels; 32692019a976f07ff418dde2dfc7cc74667ef66d7764sewardj GET_CURRENT_CONTEXT(ctx); 32702019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 32719d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 32722019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 32732019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texObj = _mesa_select_tex_object(ctx, texUnit, target); 32747ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!texObj) { 32752019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB"); 32762019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32772019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32782019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32792019a976f07ff418dde2dfc7cc74667ef66d7764sewardj maxLevels = _mesa_max_texture_levels(ctx, target); 32802019a976f07ff418dde2dfc7cc74667ef66d7764sewardj ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */ 32819d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 32822019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (level < 0 || level >= maxLevels) { 32832019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 32847ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj return; 32852019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32862019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32872019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (is_proxy_target(target)) { 32882019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); 32892019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32902019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32919d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj 32922019a976f07ff418dde2dfc7cc74667ef66d7764sewardj texImage = _mesa_select_tex_image(ctx, texUnit, target, level); 32932019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage) { 32947ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj /* probably invalid mipmap level */ 32952019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); 32962019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 32972019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 32982019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 32992019a976f07ff418dde2dfc7cc74667ef66d7764sewardj if (!texImage->IsCompressed) { 33002019a976f07ff418dde2dfc7cc74667ef66d7764sewardj _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); 33019d31dfd1f65077789d8fcafdce2d1cefaf291d35sewardj return; 33022019a976f07ff418dde2dfc7cc74667ef66d7764sewardj } 33032019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 33047ee9752b2f79d54cbf2f8b1f36d239380b0799cdsewardj if (!img) 33052019a976f07ff418dde2dfc7cc74667ef66d7764sewardj return; 33062019a976f07ff418dde2dfc7cc74667ef66d7764sewardj 33072019a976f07ff418dde2dfc7cc74667ef66d7764sewardj /* just memcpy, no pixelstore or pixel transfer */ 33082019a976f07ff418dde2dfc7cc74667ef66d7764sewardj MEMCPY(img, texImage->Data, texImage->CompressedSize); 33092019a976f07ff418dde2dfc7cc74667ef66d7764sewardj} 33102019a976f07ff418dde2dfc7cc74667ef66d7764sewardj