teximage.c revision f1452844fe2522387bbc6633f22aec09b8a06204
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian * mesa 3-D graphics library 325be043940b25a5fe6eb8058070b3e8f12e92039Brian Paul * Version: 7.6 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 59f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 33fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 34b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 36d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h" 3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 3834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 413c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 42ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 43db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 44fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 461a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 497179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 505e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 534cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 5863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul#define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \ 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul _NEW_BUFFERS | \ 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul _NEW_PIXEL) 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 824cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 834cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 844cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 85f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 86887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)). 87973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1. 88afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 89fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 90fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 93afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 94afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 95973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n < 0) 96afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 97973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul 98973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n == 0) 99973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul return 0; 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 106887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul return log2 - 1; 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1161749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 1171749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1201749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 12489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 12589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 12689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 12773b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 12873b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 130b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 131f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1331749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 181afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 182f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 183f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 184f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 186f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke if (ctx->Extensions.EXT_texture_format_BGRA8888) { 187f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 188f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke case GL_BGRA_EXT: 189f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 190f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 191f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 192f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 193f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 194f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 199f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 200f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 202f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 203f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 204e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 2104741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 211f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 212f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 2134741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 2144741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 2154741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 216f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 217f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 219f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 220f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 22189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 22233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 22333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 22433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 22533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 22633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 22733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 22833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 22933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 23033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 23133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 23233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 23333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 23433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 23533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 23633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 24289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 24489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2528f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2538f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 25740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 260f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 265f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 267663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 269f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 270663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 271f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 27589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 278f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2801749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 282f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 288f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 289f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 290f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 291f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 292f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 293f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 294f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 295f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 296f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 297f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 298f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 299f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 300f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 301f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 3028f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 303f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 304afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 305f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 306114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 307114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 308114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 309114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 310114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 311114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 312114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 313114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 314114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 315114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 316c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger if (ctx->Extensions.MESA_texture_signed_rgba) { 317c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 318c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 319c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 320c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 321c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 322c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 323c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 324c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 325114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3261ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3271ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3281ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3291ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3301ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3311ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3321ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3331ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3341ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3351ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3500a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3530a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3540a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3550a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3560a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3573488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3580a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3590a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 360abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3610a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3620a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3630a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3640a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 402abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 403abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 404abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 405abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 406abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 407abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 408abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 409abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 410abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 411abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4136988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4146988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 4156988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4166988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4173ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4183ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4193ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4203ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4226988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4243ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4253ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4266988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4276988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4286988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4296988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4306988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4316988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4373ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4383ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4393ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4416988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4423ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4433ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4443ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4453ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4463ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4476988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4483ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4493ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4503ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4536988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4556988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4566988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4573ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4583ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4593ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4603ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4613ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4623ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4633ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4896988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4916988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4926988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4946988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4956988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4966988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4976988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4986988f65e43297ae63bbce30bf882f870b370096cBrian Paul 499e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 5006988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 501e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 502e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 5036988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 504e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 505e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 5066988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 5076988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 5086988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 5096988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 510abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 511abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 512f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 514afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 517e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 518e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 519e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 520e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 521e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 522519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 523519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 524519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 525519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 526519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 527519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 528519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 529519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 530519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 531519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 5406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 547fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5489c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5499c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 550fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 551fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5529c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5539c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5549c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5559c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 556a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 557a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 558fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 559fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 560fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 561a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 564a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 565a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 56977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 57077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 571f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 57277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 573a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 57477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 57577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 57677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 57777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 578a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5793e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 5804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 5813e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 5821eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 5833e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 5843e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 5853e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 5863e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 587f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx, 5884cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 5893e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 590c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 591c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 5923e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 5933e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 5944cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 5953e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 5963e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 5973e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 5983e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 5993e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6003e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6013e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 6026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 6036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6041eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6063e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 607a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 60877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6093c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6103c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 61177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.FreeTexImageData); 6165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 6175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 6183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 619b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 62032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage->ImageOffsets); 62132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage); 62277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 62377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 62477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 631aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 63277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 63377ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 634aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 6352465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below */ 6362465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul assert(NUM_TEXTURE_TARGETS == 7); 6372465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 64127f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 642bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 643bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 644bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 645aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 646aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 647aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 64935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target 65035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 65135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum 65235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target) 65335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{ 65435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul switch (target) { 65535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D: 65635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D: 65735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D; 65835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D: 65935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D: 66035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D; 66135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_3D: 66235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_3D: 66335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_3D; 66435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 66535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 66635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 66735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 66835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 66935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 67035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 67135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 67235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_CUBE_MAP_ARB; 67335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_RECTANGLE_NV: 67435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 67535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_RECTANGLE_NV; 67635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 67735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 67835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D_ARRAY_EXT; 67935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 68035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 68135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D_ARRAY_EXT; 68235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul default: 68335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul _mesa_problem(NULL, "unexpected target in get_proxy_target()"); 68435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return 0; 68535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul } 68635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul} 68735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 68835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 68935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/** 6903c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 6913c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * texture unit. 6926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 6946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 6956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 6986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 70035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 70135d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 7023c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 7033c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 70435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 70535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 70635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 70735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7089818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 70935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 710fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 71135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7129818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 71335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 714fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 71535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 7169818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 71735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 718fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 71935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 72035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 72135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 72235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 72335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 72435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7255ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 726a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7279818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 72835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 729a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 730fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7318afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7328afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7339818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7348afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7358afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 736fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 737bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 738bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 7399818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 740bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 741bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 742fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 743bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 744bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 7459818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 746bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 747bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 748fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 74935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 75008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 75135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 75235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 75335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 75435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 75535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 757b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 758b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 759b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 760f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 761b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 762b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 763b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 764b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 765b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 766b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 767b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 768c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 769c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 770c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7731eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 777c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 778fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 779fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 7803c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 7813c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 7825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 783fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 784c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 7855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 786c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 787c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 788c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 789bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 790c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 791fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 792fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 793fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 794a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 795a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 796a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 797a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 798a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 799a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 800f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 801a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 802a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 803a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 8045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 8065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 810a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 811a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 812a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 813a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 819a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 820a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 827a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 828a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 829a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 830f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 83380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 838a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 84280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 84380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 84780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 84880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 849a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 85280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 85380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 855a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 856a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 85780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 85880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 859a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 860a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 861a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 86380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 864bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 865bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 866bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 86780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 86880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 869bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 870bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 871bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 87280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 87380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 874a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 875a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 876a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 87780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 87880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 87980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 88080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 88180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 88280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 88380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 88480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 88580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 88680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 88780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 88880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 88980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 890a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 891a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 892a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 8936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 8946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 8956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 8976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 8986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 903ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 904ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 905f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 906ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 907ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 908ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 909ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 910ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 911ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 912ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 913ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 914ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 915ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 916ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 917ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 918ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 919ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 920ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 921ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 922add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 923ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 924fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 925fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 928fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 929fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 930fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 931fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 932fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 933fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.MESA_texture_array 934fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 935ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 936ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 937ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 938ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 94183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9425e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 94383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 944a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 945a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 94683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 94783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 94883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 94983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 95083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 95183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 95283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 95383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 95483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 95583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 95683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 95783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 95883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 95983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 96083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 96183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 96283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9635e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9645e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 96583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 96683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 96783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9685e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9695e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 97083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 97183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 97283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 97383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 97483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 97583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 97683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 97783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 97883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 97983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 980fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 98162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 982f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 984afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 9858e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9878e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 9888e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 9908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 9918e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 9928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 993afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 994a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 995afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 996afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 997afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 100165d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1002afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1003afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1004afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1005afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1007afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1008afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1009afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1010afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1011afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1027a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 103162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1032afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1034afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1035738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1036f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10409c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10419c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1042f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1043f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1044f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10459c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10469c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1047f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10489c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10499c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1050a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1051a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10529c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10539c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10549c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10559c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1056681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1057b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 105832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 1059b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1060b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 10619c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10629c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10639c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10649c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10659c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10669c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10679c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10681f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10694f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10704f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10719c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10729c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10756628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1078b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 10796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 10806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 10816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 10826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 10836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 10846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 108583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 10866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1088887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 10896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 10903893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1091f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 10923893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 10933893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 109483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 109583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 10966628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 109783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint i, dims; 1098b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 10996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11008bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11018bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11028bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1103b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1104a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1105a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1106a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11076628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11086628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11096628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11106628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1111c813b545ab4726fc5030f123ec6255224d64ad82Brian 11124d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 11134d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->WidthLog2 = logbase2(img->Width2); 1114c813b545ab4726fc5030f123ec6255224d64ad82Brian 1115c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1116c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 11176628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1118c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1119c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1120c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 11214d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->HeightLog2 = logbase2(img->Height2); 1122c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1123c813b545ab4726fc5030f123ec6255224d64ad82Brian 1124c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1125c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 11266628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1127c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1128c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1129c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 11304d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->DepthLog2 = logbase2(img->Depth2); 1131c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1132c813b545ab4726fc5030f123ec6255224d64ad82Brian 11336628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1134c813b545ab4726fc5030f123ec6255224d64ad82Brian 1135be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1136be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1137be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1138887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1139887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1140887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1141887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1142b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1143b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1144b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1145b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1146b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1147b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1148a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer if (img->ImageOffsets) 114932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 115032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); 1151b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1152b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1153b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1154b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11578afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11588afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11608afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11618afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11628afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11648afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11658afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11668afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11671a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul 116883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 116983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1170a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie dims = _mesa_get_texture_dimensions(target); 117183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 117283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_set_fetch_functions(img, dims); 11736628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11746628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11756628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1176738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 117742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 117842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 117942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 118042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 118142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 118242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 118342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 118442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 118542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 11863c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 11873c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 118842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 118942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu ctx->Driver.FreeTexImageData(ctx, texImage); 119042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 119142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 119242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 119342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 119442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1195738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1196738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1197738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1198738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1199738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1200738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1201aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1202aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1203aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1204aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1205738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1206738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1207738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1208738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1209738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1210738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1211738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1212738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1214738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1216738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1217738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1218738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1219f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1220738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1222738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12249c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1229738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1232c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1234c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1235c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1236c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1237c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1238c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1239738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1240738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1241c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1242738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1243738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1244c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1245c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1246c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1247738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1248c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1249c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1250c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1251c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1252c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1253c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1254c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1255738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1256738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1258738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1259738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1260c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1262c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1263738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 2 * border || depth > 2 + maxSize) 1265c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1267c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1268c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1271c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1272c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1274c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1279c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1280c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1281c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1283c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1284c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1285738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1286738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1287c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1288738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1289738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1291c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1292c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1294c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1295738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1296c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1297c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1298c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1299c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1300c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1301738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1302738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1303c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1304bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1305bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1306c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1307bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1308c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1309bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1310c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1311c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1313c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1314c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1315bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1316bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1317c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1318bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1319bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1320c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1321bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1322c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1323c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1324c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1325bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1326c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1327c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1328c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1329c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1330c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1331c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1332c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1333bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1334bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1335c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1336738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1337738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1338738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1339738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1340738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1341738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1342738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1343738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 13444b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 13454b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 13464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 13474b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 13484b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 13494b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 13504b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 13514b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 13524b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 13534b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 13544b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 13554b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 13564b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 13574b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 13584b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13594b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13604b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13614b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 13627404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 13637404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1364064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1365064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13667404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13677404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1368064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13697404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 13707404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1371646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1372646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1373646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 13747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1375646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1376646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1377646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1378646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1379646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1380646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1381646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1382646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1383646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1384646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1385646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.MESA_texture_array; 1386646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1387646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1388646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1389064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1390064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1391064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1392064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1393d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1394d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1395d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1396d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1400d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1401d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1402d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1403d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1404d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1405d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1406d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1407d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1408d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1409d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D: 1412d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1413d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1414d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.NV_texture_rectangle; 1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.MESA_texture_array; 1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_3D: 1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.MESA_texture_array; 1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1447d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 144911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 145009a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 145109a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 145209a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 145311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 145411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 145509a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 145611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 145711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 145811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 145911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return target == GL_TEXTURE_1D; 146011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 146111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 146211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 146311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 146411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 146511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 146611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 146711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 146811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 146911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 147011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 147111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 147211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.NV_texture_rectangle; 147311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 147411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.MESA_texture_array; 147511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 147611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 147711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 147809a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 147909a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 148009a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 148109a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 148209a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 148309a5e028a6d254f619132e302a96c8535018603dBrian Paul return ctx->Extensions.MESA_texture_array; 148409a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 148509a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 148609a5e028a6d254f619132e302a96c8535018603dBrian Paul } 148711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 148809a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 148909a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 149011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 149111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 149211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 149311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 149411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 149511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 14966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 14976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 149985288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 15006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 15016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 15026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 15036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 15046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 15056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 15066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 15076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 15086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 15096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15133c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 15143c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1516c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 151785288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 151885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1519c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1520c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1521c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1522c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1523afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 152435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 152535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1526e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1527714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1528afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1529738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1530738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1531738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1532738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1533738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 15348afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1535738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1536738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1537738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1538738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1539738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1540738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1541738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1542738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1543738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1544738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1545738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1546738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1547738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1548738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1549973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1550f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1551f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1552973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1553f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1554f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1555f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1556f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 155735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 155835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 155935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1561d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 156235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 156335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 156435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 156535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 156635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1567e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1568e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1569e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1570738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1571c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15724e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1573738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1574738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1575c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1577afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1578afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1579738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 158089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1581c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1583a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1584a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1585c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1586afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1587afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1588afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1589738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1590f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1591326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1592326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1593326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1594326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 159538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 159638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1597326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1598326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1599326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 16008a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 16018a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1602c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 160338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1604afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1606601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 160722e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1608ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul indexFormat = _mesa_is_index_format(format); 160922e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1610ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_index_format(internalFormat) && !indexFormat) || 1611ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1612ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1613ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1614ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1615601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1616601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16178a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 16188a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1619601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1620601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1621601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1622601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1623601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1624c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1625601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1626601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1627c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1628fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16292236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1630c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1631c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1632c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1633d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1634d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1635d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1636d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1637d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1638d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1639d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1640d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1641d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1642d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1643d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1644fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16452236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1646fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1647c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1648d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1649d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1650d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1651c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1652c5b995066020191982b2315fc45d05e068eee761Brian Paul 1653601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1654601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 16552b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */ 1656601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1657601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1658601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16592b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 16602b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16612b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1662601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1663601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1664601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1665601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1666601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1667601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1668601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1669601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1670c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 16717404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 16727404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 16737404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 16747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1675064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 167689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 167789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 167889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 167989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16808978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 168189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 168289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 168389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 168489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 168589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1686326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1687326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1688326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1689326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1690326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1691326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1692326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1693326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1694326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1695326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1696326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1697326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1700afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1701afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1704c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 17056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 17076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 17086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 17096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 17106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 17116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 17126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 17136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 17146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 17156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 17166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 17176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 17186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 17206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 17223c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 17233c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1725c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1726f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1727c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1728c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1730c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1731afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1732738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1733738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17344e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1735c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1736c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1737afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 173845124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1739c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 17404e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1742c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1743c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1744c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 17454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17464e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1747c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1748c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1749c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1750738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1751738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1752c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1753c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1754afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1756326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1757326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1758326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1759326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1760326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1761326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 17628a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 17638a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 17645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 17655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 17665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 17675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 17685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1769f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1770d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1771d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1772d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1773d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1774d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 17755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1776f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 17775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 17785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 17795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 17805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 17815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 17825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1783c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1784738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1785738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1787c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1789c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1790738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1791738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1792c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1793afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1794c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1795738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1796738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1797c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1798c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1799c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1800c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1801738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1802738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1803c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1804afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1805c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1806738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1807738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1808c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1809afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1810afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1811c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1812c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 181308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1814c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1815c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 181638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 181708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1818c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1819c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1820afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1822b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1823d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1824d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1825d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1826d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1827d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1828d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1829d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1830e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18318978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1832d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1833e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1834e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1835d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1836d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1837e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18388978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1839e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 184089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1841d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 184289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18438978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 184489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 184589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1846e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1847e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1849c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1853c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 18636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18673c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 18683c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1869afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1870c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1871f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1872c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1873c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1874afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 187511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 187611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 1877738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 18780899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1879afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 188011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 188109a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 188211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 188311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 188411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 188511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 188611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1887738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1888738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 18895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 18905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 18915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 18925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 189434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 189534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 189634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 189734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 189834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 189934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 190034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 190134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 190234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 190334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1904738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1905738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1906738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1907738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1908738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1909738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1910738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1911738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 19120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 19130899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19140899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 19150899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19160899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19170899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 191834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 191934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 192034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 192134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 192234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 192334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 192411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 192511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 192611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 1927738318bb75dea8dac4465f53850987f6062a732dBrian Paul 192811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 192911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul internalFormat, format, 193011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 193111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 1932c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1933738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1934738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1936738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1937c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1938738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1939738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1940738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1941738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1942ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1943c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1944c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1945c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1946c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 19477404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 194889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 19492236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 195089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 195189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 195289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 195389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19548978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 195589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 195689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 195789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1958ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depth_format(internalFormat)) { 19590899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19601a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 19610899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19628978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth)", dimensions); 19630899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19640899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19650899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 1966ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depthstencil_format(internalFormat)) { 19670899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19681a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 19690899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19708978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth/stencil buffer)", dimensions); 19710899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19720899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19730899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 197489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1975c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1976c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1977c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1978c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1979c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 19806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 198134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 19829dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 19839dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 19846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 19866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 19876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 19886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 19896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 19916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 1992c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1993f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 19949dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 1995c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 199634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 199734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 199834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 199934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 200034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 200134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 200234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 200334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 200434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 200534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 20061c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 200709a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 20081c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 20091c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 20101c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 2011c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2012c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2013738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2014738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20154e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2017c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2018c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2019c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 20215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 20225ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 20239dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20249dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 20259dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 20269dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 20279dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 20289dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 20299dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 20309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 20319dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 20325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2033f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 20345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 20355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 20365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 20375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 20385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 20399dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2040c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 20414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2042b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2043b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2044c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2045c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2046c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20479dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 20489dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 20499dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20509dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 20519dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20529dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20539dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 20549dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20559dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 20569dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20579dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20589dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20599dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2060c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 20614e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20624e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2063c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2064c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 206538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 20664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20674e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2068c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2069c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2070c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2071c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 20724e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20734e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2076c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 207738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 20784e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20794e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2080c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2081c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2082c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2083c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20849dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2085c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2086c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 20874e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20884e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2089c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2090c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 209138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 20924e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20934e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2094c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2095c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2096c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2097c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2098b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 209989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 210089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 210189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21028978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2103e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2104e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 210589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2106798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 210789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21088978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2109e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 211089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2111798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 211289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21138978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 211489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 211589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2116e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2117e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2118a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2119d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2120d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2121d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2122d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2123985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2124985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2125803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2126803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2127985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2128985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2129985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2130a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 21311a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 21320899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21338978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth buffer)", 21340899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21350899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21360899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21370899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2138a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 21391a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 21400899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21418978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth/stencil buffer)", 21420899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21430899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21440899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21450899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21460899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2147326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2148326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2149326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2150412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2151326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2152412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2153326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2154326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2155326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2156326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2157326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2158326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2159326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2160c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2161c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2162c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2163c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2164c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21652897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 21662897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 21672897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2168f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 21692897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 21702897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 21712897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 21722897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2174519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 21752897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2176519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2177519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 21782897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2179519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 21802897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 21812897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2182f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 21832897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 21842897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 21852897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21862897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 21872897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2188519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 21892897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2190519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 21912897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2192519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2193519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2194519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2195519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2196519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]); 2197519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2198ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 21992897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 22002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2201519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2202519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2203519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2204519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2205519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2206519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 22072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 22082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 22092897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 22102897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 22112897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 22122897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 22132897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2214f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 22152897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 22162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 22172897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 22182897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 22192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 22202897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 22212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 22222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 22232897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 22242897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 22252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 22262897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 22272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22292914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 22302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 22312914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 22322914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 22332914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 22342914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void 2235f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 22362914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 22372914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 22382914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2239ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2240ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2241ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 22422914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 22432914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 22442914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 22452914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 22462914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22472914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22481826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 22491826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 22501826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 22511826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 22521826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 22531826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 22541826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 22551826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 22561826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 22571826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22581826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 22591826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 22601826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 22611826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 22621826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22631826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 22641826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 22651826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22661826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 22671826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22681826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 22691826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 22701826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22711826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 22721826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22731826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 22741826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 22751826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22761826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 22771826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22781826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 22791826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 22801826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 22811826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22821826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 22831826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 22841826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22851826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 22871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 22891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 22901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2291519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2292bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2293bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2294bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2295bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2296bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2297bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2298bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2299bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 230083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2301f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2302bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2303bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2304bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2305bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 230683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 230783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2308bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2309bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2310bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2311bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2312bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2313bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2314bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2315bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2316bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2317bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2318bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 231983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 232083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2321bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2322bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2323bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2324bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 232583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 232683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 232783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2328bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2329bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2330bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2331d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2332d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2333c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2334d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2335d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2336d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2337d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2338d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2339d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2340c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2341d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 2342d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2343cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2344c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2345d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2346d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2347d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2348d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2349d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2350d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2351d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2352d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2353d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2354d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 235511caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2356d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2357d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2358d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2359d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2360d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2361d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2362ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2363d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2364d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2365d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 23662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2367d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2368d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2369d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2370d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 237162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2372d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2373738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2374a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2375a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2376c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 237789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 237889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2379bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2380bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2381d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2382d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 238383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 238483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2385d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2386d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2387d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 2388d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2389d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 23904b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 23914b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 23924b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 23934b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 239489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2395c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2396c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 23978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 23990293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24000293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2401f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2402d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 24038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2404c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2405c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24061ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 24075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2408fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2409b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2414d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2418ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 241983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 242083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2421ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2422ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2423ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2424ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2425ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 242683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 242783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 242883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 242983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 243411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 24354b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ASSERT(ctx->Driver.TexImage3D); 2437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 2438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 2439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, border, format, 2441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 2445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, border, format, 2447d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 2451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, format, 2453d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 2457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in teximage()", dims); 2458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2459ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24604b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 24612914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 24624b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2463ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24644b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 24654b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 24664b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 24674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2471ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2472ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 24735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2480d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2481d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2484d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2485d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2486d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2487d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2488d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2489d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2490d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2491d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2492d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2493d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2494d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2495d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2496d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2497d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2498d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2499d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2500d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2501afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2502afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2503afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2504afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2507afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2508c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2509b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2510fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2511fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2512fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2514fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2515d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2516d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2517afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2518afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2519afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2520c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 252143911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2522663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2523663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2524663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2525663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 252689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2527663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2528663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2529663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2530663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2531d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2532d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2533d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2534d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2535d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2536d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 253717efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 253817efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2539d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25402002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 25412002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 25422002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 25432002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 25442002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 25452002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2546d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2547d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2548d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2549d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2550d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2551d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2552d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 2553d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2554d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2555d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2556d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2557d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2558d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2559d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2560d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2561d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 2562d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (texImage->Data) 2563d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.FreeTexImageData( ctx, texImage ); 2564d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2565d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ASSERT(texImage->Data == NULL); 2566d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2567d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2568d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2569d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2570d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2571d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2572d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2573d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2574d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2575d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2576d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2577d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2578afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 257945124e043da5a67e1081526d61b99422f4ccde19Brian Paul 258045124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 258145124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 258245124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 258345124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 258445124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 258545124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 258645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 258745124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2588afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 25890293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2590b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 259145124e043da5a67e1081526d61b99422f4ccde19Brian Paul 259275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 259375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2594d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 259545124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 259645124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2597d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 259845124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 259945124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2600d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2601d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 260245124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 260309a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 260445124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 260545124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 260645124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 260745124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 260845124e043da5a67e1081526d61b99422f4ccde19Brian Paul 26091ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 261008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 26112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 261245124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 261345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2614f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2615afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2617b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2618afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2622afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 262345124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 262445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 262545124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 262645124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2627a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 26285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 262945124e043da5a67e1081526d61b99422f4ccde19Brian Paul else if (width > 0 && height > 0 && height > 0) { 263045124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 263145124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 263245124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 263345124e043da5a67e1081526d61b99422f4ccde19Brian Paul zoffset += texImage->Border; 263445124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 263545124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 263645124e043da5a67e1081526d61b99422f4ccde19Brian Paul yoffset += texImage->Border; 263745124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 263845124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 263945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 264045124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2641347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 264245124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 264345124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 264445124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, 264545124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, width, 264645124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 264745124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 264845124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 264945124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 265045124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, 265145124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, width, height, 265245124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 265345124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 265445124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 265545124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 265645124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 265745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 265845124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 265945124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 266045124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 266145124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 266245124e043da5a67e1081526d61b99422f4ccde19Brian Paul default: 266345124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_problem(ctx, "unexpected dims in subteximage()"); 266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 26652914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 26662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 26672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2668ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2669ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 26705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2672afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2673afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2674afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2675c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 267645124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 267745124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 267945124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 268145124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 268245124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 268345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 268445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 268545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 268645124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 268745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 268845124e043da5a67e1081526d61b99422f4ccde19Brian Paul 268945124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2690fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2691fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2692fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2693fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2694fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2695afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26962c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 269745124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 269845124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 269945124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 270045124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2701c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2705c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2706fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2707fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2708fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2709fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2710fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2711afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27122c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 271345124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 271445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 271545124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 271645124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2717afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2718afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2719afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2720afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 272111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 272211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 272311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 272411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 272511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 272611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 272711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 2728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27292aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 27302aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2731e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 273211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2733cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2734afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2735d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 273611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 273711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 2738d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2739d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 274011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2741d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 274263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 274308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2744fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 274511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 274611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 2747ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2748ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2749b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2750a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 27515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 275411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 27555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 275611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2758c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 275983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 276083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2761c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 2762c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2763c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 27647dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 2765c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 27667dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 276783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 276883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 276983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 27702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 277111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 277211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 27734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 277411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 277511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 277611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (dims == 1) 277711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat, 277811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, border); 277911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul else 278011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat, 278111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 27822aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 27834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 27842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 27854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2786519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 27874b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 27884b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 27894b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 27904b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 27914b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 279211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27934b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2794c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 27955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2797afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2798afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2800afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2801c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 280211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 280311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 280411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 280511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 2806afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2807fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 280811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 280911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 2810c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 28112914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2812c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 281311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 281411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 281511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 281611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 281711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 281811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 281911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 282011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2823afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28241c23b860cea93534f726d2a18658444f37f43538Brian Paul 28251c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 28261c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 28271c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 28281c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 28291c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 28301c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 28311c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 2832afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 2834347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 283503bafd1f9fa000abdb794b2ae344a68840c83201Brian 2836cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2837afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2838d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 28391c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 28401c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 2841d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 28421c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 2843d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 284463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 284508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2846fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 28471c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 2848ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2849ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2850b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 28515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 28555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28561c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 28571c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 28581c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 285903bafd1f9fa000abdb794b2ae344a68840c83201Brian } 2860a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 28611c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 28621c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 28631c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 28641c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset += texImage->Border; 28651c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28661c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 28671c23b860cea93534f726d2a18658444f37f43538Brian Paul yoffset += texImage->Border; 28681c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28691c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 28701c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 28711c23b860cea93534f726d2a18658444f37f43538Brian Paul } 287203bafd1f9fa000abdb794b2ae344a68840c83201Brian 2873a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 2874a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 28751c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 28761c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 28771c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 28781c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, x, y, width); 28791c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28801c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 28811c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, 28821c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, 28831c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 28841c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28851c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 28861c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 28871c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, zoffset, 28881c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 28891c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28901c23b860cea93534f726d2a18658444f37f43538Brian Paul default: 28911c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_problem(ctx, "bad dims in copytexsubimage()"); 28921c23b860cea93534f726d2a18658444f37f43538Brian Paul } 28932914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28942914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 28952914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2896a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 2897a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 2898a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 28995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2901afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2902afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29041c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 29051c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 29061c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 29071c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 29081c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 29091c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 29101c23b860cea93534f726d2a18658444f37f43538Brian Paul} 29111c23b860cea93534f726d2a18658444f37f43538Brian Paul 29121c23b860cea93534f726d2a18658444f37f43538Brian Paul 2913afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2914c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2915fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2916fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2917fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2918afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2919fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29201c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 29211c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 2922afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2923afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2924afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2925afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2926c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2927fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2928fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2929fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2930afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2931fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29321c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 29331c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 2934afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 29351207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29371207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 293889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 293989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 294089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 294189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 294289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 294389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 294489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 294554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 294654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 294754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 294854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 294954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 295054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 295154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 295254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 295354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 295454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 295554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 295607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 295707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 295807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 295907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 296007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 296107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 296207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 296307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 296407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 296554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 296654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 296754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 296889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 296989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 297089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 297189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 2972f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 297389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 297489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 297589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 297689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei imageSize) 297789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 29784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 29794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 29804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 298189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 29824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check level */ 29834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (level < 0 || level >= maxLevels) 29844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul return GL_INVALID_VALUE; 298589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 29867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 29877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 29887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 29897404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 2990c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 2991c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, internalFormat)) 299289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 299389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2994c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 2995a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick if (_mesa_base_tex_format(ctx, internalFormat) < 0) 2996a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 2997a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 29984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 299989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) 300089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 300189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 300289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 300389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 300489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 300589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 300689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30077404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 30087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 30097404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 30107404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul ctx->Driver.ChooseTextureFormat(ctx, internalFormat, 30117404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GL_NONE, GL_NONE); 30127404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 30137404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30147404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 30157404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 30167404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 30177404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 30187404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 30197404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 30207404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 30217404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 30227404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30237404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30247404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30257404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 30274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 30284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE, 30294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border)) { 30307404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 30317404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 303389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 303554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, internalFormat); 30367404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 30377404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 30387404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 30397404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 30407404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 304189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 30427404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 304389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 304489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 304589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 304689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 304789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 304889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 304989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 30502371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 30512371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 30522371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 305389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 305489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 305589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3056f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 305789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 305889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 305989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 306089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 306189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 306289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 306307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3064a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 306589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 306689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 306789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 306889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 306989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 307089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 307189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 307289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 307389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 307489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 307589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 307689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 307789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 307889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 307989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 308089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 308189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 308289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 308389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 308489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 308589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 308689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 308789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 308889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 308989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 309089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 309189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 309289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 309389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 309489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 309589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 309689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 309789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 309889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3099c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3100c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 310189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 310289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3103887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 310489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 310589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3106887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 310789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 310889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 310989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 311189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 311289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 311407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 31152371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 311607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 311707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 311807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 311989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 312089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 312289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 312389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 312589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 312689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 312889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 312989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 313089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 313289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 313389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3135f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3136f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3137f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3138f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3139f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3140f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3141f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3142f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3143f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3144f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3145f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3146f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3147f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3148f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3149f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3150f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3151f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3152f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3153ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3154ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3155f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3156f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3157f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3158f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3159f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3160f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3161f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3162ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3163ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3164f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3165f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3166f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3167f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3168f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3169f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3170f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3171f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3172ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3173ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3174f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3175f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3176f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3177f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3178f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3179f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3180f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3181f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3182f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3183f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 31844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 31854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 31864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 31874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 31884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 31894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 31904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 31914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 31924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 31931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 31944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 31954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3196cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3197aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3198d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 31994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 32004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 32014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3202d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3203d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 32044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 32055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 32077404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 32084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 32094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3210aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3211aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 32144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 32154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize); 3216d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 32177179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#if FEATURE_ES 32184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* XXX this is kind of a hack */ 32194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 32204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glTexImage2D"); 32217179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 32227179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 32237179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 32244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (dims == 2) { 32254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 32264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 32274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 32284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 32294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 32304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 32314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 32324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 32334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 32344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 32354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 32364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 32374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 323889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3239aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 32414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3242aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 32434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 32444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 32454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 32462914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 32478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 32484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 32494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 32504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 32514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 32524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 32534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 32544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 32554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3256aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 32594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 32604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 32614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 32634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 32644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 32654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 32664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 32674ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 32684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 32694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 327089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3271aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3272aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 32738c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3274aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3275aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 32764ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 327789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 32784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD", dims); 327989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3280aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3281aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3282b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 32839519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 32845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 32855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 32865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 32875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 32884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 32894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 32905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3291c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 329283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 329383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3294c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3295c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3296c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3297c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3298c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 329983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 330083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 330183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 330283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 33034b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 33044b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 33054b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 33064b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 330711caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 33084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (dims) { 33094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 1: 33104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 33114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 33124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 33144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 2: 33184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 33194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 33204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 33224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 3: 33264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 33274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 33284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, 33304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul default: 33344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_problem(ctx, "bad dims in compressedteximage"); 33354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3336c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 33374b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 33382914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 33394b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 33404b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 33414b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 33424b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 33434b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 33444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3347c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3348c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 33495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3350aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 33529519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33539519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 33554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 33564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 33574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 33584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 33594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 33604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 33614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 33624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 33634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 33644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 33674ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 33684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 33694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 33704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 33714ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 33724ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 33734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 33744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 33754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 33764ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 33794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 33804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 33814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 33824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 33834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 33844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 33854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 33864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 33871207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 33881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 33891207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 33906bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 33916bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 33926bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 33936bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 33946bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 33956bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 33966bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 33976bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 33981207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 33999540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 34009540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 340189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3402a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 340375280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 340475280a2c742ee241d392618a3b29548fce1520a9Brian Paul 34056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3406c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 34076bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3408c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 340989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 34106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 341189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 34129540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34139540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3414b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3415c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 34195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 34209540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 34216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3422f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3423f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3424c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 34266bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 34276bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 34286bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 34296bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 34306bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 34316bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34326bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34336bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34346bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34356bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 34366bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 34376bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 34386bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 34396bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 34406bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34416bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34426bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34436bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34446bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 34456bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 34466bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 34476bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 34486bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 34496bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34506bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34516bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34526bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34536bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 34546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3455c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34562914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34572914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 34582914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34592914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 34605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 34619540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 34631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34641207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3466c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 34676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 34686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 34696bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 34706bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 34716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 34726bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 34736bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 34746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 34756bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 34766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 34771207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 34781207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 34791207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 34801207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 34811207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34826bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 34836bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 34841207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34851207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34861207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3487c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 34881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 34891207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 34901207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 34911207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 34921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34936bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 34946bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 34951207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3496