teximage.c revision 5e3733fadf08178fca7c9f20a0f4783f940383aa
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" 43fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 451a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h" 46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 487179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 495e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 50afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 524cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul#define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \ 5863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul _NEW_BUFFERS | \ 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul _NEW_PIXEL) 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 824cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 834cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 84f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 85887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)). 86973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1. 87afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 88fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 89fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 90afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 93afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 94973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n < 0) 95afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 96973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul 97973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n == 0) 98973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul return 0; 99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 105887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul return log2 - 1; 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1151749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 1161749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1191749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 12389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 12489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 12589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 12673b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 12773b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 129b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 130f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1321749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 181f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 182f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 183f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 184f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 188f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 189f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 190f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 191f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 192f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 193f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 194e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 199f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 2004741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 202f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 2034741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 2044741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 2054741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 206f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 21189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 21233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 21333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 21433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 21533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 21633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 21733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 21833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 21933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 22033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 22133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 22233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 22333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 22433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 22533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 22633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 23289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 23489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2428f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2438f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 24740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 257663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 260663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 26589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 267f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 269f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2701749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 271f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 275f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 278f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 280f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 282f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 288f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 289f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 290f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 291f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 2928f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 293f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 294afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 295f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 296114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 297114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 298114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 299114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 300114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 301114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 302114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 303114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 304114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 305114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 306c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger if (ctx->Extensions.MESA_texture_signed_rgba) { 307c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 308c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 309c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 310c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 311c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 312c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 313c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 314c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 315114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3161ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3171ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3181ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3191ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3201ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3211ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3221ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3231ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3260a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3270a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3280a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3290a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3300a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3310a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3320a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3330a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_EXT: 3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 350abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3530a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3540a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 355abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 356abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 357abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 358abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 359abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 360abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 361abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 362abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 4026988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4036988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4046988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 4056988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4066988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4073ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4083ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4093ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4103ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4113ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4133ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4143ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4153ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4166988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4176988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4186988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4196988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4206988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4216988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4243ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4253ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4263ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4273ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4283ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4293ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4303ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4316988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4376988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4383ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4393ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4416988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4426988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4436988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4446988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4456988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4466988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4473ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4483ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4493ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4503ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4513ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4523ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4533ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4556988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4566988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4576988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4586988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4596988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4606988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul 489e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 491e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 492e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 494e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 495e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 4966988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4976988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4986988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4996988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 500abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 501abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 502f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 503afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 504afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 507e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 508e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 509e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 510e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 511e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 512519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 513519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 514519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 515519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 516519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 517519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 518519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 519519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 520519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 521519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 5306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5333893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 537fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5389c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5399c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 540fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 541fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5429c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5439c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5449c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5459c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 546a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 547a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 548fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 549fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 550fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 551a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 554a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 555a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 55977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 56077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 561f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 56277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 563a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 56477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 56577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 56677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 56777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 568a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5693e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 5704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 5713e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 5721eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 5733e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 5743e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 5753e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 5763e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 577f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx, 5784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 5793e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 580c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 581c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 5823e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 5833e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 5844cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 5853e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 5863e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 5873e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 5883e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 5893e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 5903e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 5913e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 5926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 5936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5941eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 5956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5963e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 597a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 59877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 5993c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 60177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.FreeTexImageData); 6065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 6075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 6083e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 609b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 61032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage->ImageOffsets); 61132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage); 61277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 61377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 61477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 621aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 62277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 62377ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 624aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 6252465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below */ 6262465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul assert(NUM_TEXTURE_TARGETS == 7); 6272465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 63127f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 632bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 633bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 634bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 635aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 636aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 637aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6393c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 6403c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * texture unit. 6416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 6436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 6446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 64935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 65035d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 6513c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 6523c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 65335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 65435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 65535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 65635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 6579818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 65835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 659fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 66035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 6619818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 66235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 663fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 66435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 6659818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 66635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 667fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 66835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 66935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 67035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 67135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 67235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 67335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 6745ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 675a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 6769818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 67735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 678a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 679fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 6808afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 6818afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 6829818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 6838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 6848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 685fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 686bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 687bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 6889818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 689bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 690bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 691fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 692bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 693bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 6949818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 695bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 696bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return ctx->Extensions.MESA_texture_array 697fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 69835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 69908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 70035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 70135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 70235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 70335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 70435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 706b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 707b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 708b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 709f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 710b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 711b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 712b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 713b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 714b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 715b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 716b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 717c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 718c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 719c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7221eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 726c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 727fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 728fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 7293c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 7303c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 7315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 732fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 733c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 7345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 735c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 736c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 737c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 738bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 739c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 740fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 741fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 742fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 743a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 744a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 745a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 746a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 747a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 748a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 749f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 750a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 751a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 752a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 7535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 7545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 7555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 7565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 7575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 758a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 759a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 760a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 761a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 762a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 763a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 7645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 765a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 766a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 7675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 768a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 769a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 770a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 771a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 772a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 773a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 774a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 775a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 776a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 777a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 778a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 779f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 780a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 781a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 78280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 783a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 784a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 785a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 786a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 787a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 788a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 789a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 790a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 79180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 79280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 793a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 794a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 795a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 79680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 79780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 798a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 799a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 800a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 80180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 80280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 803a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 804a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 805a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 80680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 80780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 808a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 810a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 81180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 81280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 813bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 814bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 815bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 81680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 81780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 818bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 819bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 820bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 82180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 82280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 82680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 82780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 82880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 82980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 83080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 83180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 83280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 83380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 83480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 83580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 83680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 83780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 83880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 8426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 8436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 8446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 8466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 8476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 8496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 8506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 852ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 853ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 854f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 855ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 856ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 857ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 858ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 859ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 860ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 861ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 862ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 863ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 864ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 865ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 866ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 867ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 868ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 869ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 870ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 871add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 872ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 873fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 874fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 875ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 876ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 877fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 878fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 879fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 880fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 881fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 882fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.MESA_texture_array 883fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 884ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 885ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 886ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 887ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 888ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 889ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 89083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 8915e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 89283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 89383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulstatic GLint 89483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulget_texture_dimensions(GLenum target) 89583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 89683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 89783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 89883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 89983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 90083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 90183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 90283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 90383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 90483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 90583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 90683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 90783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 90883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 90983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 91083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 91183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9125e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9135e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 91483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 91583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 91683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9175e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9185e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 91983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 92083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 92183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 92283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 92383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 92483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 92583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 92683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 92783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 92883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 929fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 93062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 931f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 932afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 933afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 9348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 935afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 9378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 938afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 9398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 9408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 9418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 942afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 943a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 944afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 945afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 946afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 947afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 948afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 95065d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 951afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 952afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 953afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 954afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 955afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 956afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 957afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 958afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 959afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 960afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 9618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 9628e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 9638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 9648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 9658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 9668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 9678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 9688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 9698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 9708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 9718e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 972afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 973afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 974afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 975afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 976a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 9778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 9788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 98062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 981afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 982afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 984738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 985f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 9866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 9886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9899c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 9909c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 991f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 992f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 993f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 9949c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 9959c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 996f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 9979c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 9989c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 999a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1000a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10019c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10029c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10039c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10049c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1005681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1006b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 100732f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 1008b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1009b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 10109c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10119c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10129c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10139c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10149c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10159c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10169c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10171f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10184f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10194f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10209c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10219c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10229c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10246628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1027b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 10286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 10296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 10306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 10316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 10326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 10336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 103483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 10356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1037887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 10386628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 10393893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1040f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 10413893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 10423893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 104383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 104483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 10456628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 104683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint i, dims; 1047b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 10486628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 10498bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 10508bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 10518bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1052b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1053a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1054a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1055a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 10566628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 10576628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 10586628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 10596628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1060c813b545ab4726fc5030f123ec6255224d64ad82Brian 10614d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 10624d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->WidthLog2 = logbase2(img->Width2); 1063c813b545ab4726fc5030f123ec6255224d64ad82Brian 1064c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1065c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 10666628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1067c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1068c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1069c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 10704d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->HeightLog2 = logbase2(img->Height2); 1071c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1072c813b545ab4726fc5030f123ec6255224d64ad82Brian 1073c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1074c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 10756628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1076c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1077c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1078c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 10794d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->DepthLog2 = logbase2(img->Depth2); 1080c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1081c813b545ab4726fc5030f123ec6255224d64ad82Brian 10826628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1083c813b545ab4726fc5030f123ec6255224d64ad82Brian 1084be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1085be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1086be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1087887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1088887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1089887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1090887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1091b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1092b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1093b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1094b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1095b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1096b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1097a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer if (img->ImageOffsets) 109832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 109932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); 1100b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1101b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1102b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1103b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11048afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11058afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11068afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11078afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11088afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11098afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11108afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11118afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11128afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11138afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11148afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11158afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11161a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul 111783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 111883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 111983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul dims = get_texture_dimensions(target); 112083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 112183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_set_fetch_functions(img, dims); 11226628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11236628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11246628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1125738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 112642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 112742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 112842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 112942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 113042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 113142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 113242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 113342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 113442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 11353c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 11363c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 113742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 113842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu ctx->Driver.FreeTexImageData(ctx, texImage); 113942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 114042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 114142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 114242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 114342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1144738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1145738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1146738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1147738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1148738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1149738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1150aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1151aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1152aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1153aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1154738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1155738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1156738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1157738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1158738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1159738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1160738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1161738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1162738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1163738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1164738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1165738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1166738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1167738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1168f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1169738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1170738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1171738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1172738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 11739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1174738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1175738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1176738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1177738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1178738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1179738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1180738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1181738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1182887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1183be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width >0 && !_mesa_is_pow_two(width - 2 * border)) || 1184738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1185738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or level */ 1186738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1187738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1188738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1189738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1190738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1191738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1192887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1193be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1194738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1195887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1196be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1197738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxTextureLevels) { 1198738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1199738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1200738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1201738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1202738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1203738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1204738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1205887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1206be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1207738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1208887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1209be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1210738318bb75dea8dac4465f53850987f6062a732dBrian Paul depth < 2 * border || depth > 2 + maxSize || 1211887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1212be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) || 1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.Max3DTextureLevels) { 1214738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or depth or level */ 1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1216738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1217738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1218738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1219aa328291c5b015e74ebfd9c5cdb39227265b3000Brian if (width < 0 || width > ctx->Const.MaxTextureRectSize || 1220aa328291c5b015e74ebfd9c5cdb39227265b3000Brian height < 0 || height > ctx->Const.MaxTextureRectSize || 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul level != 0) { 1222738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height or level */ 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (width < 2 * border || width > 2 + maxSize || 1229887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1230be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul height < 2 * border || height > 2 + maxSize || 1232887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul (!ctx->Extensions.ARB_texture_non_power_of_two && 1233be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1234738318bb75dea8dac4465f53850987f6062a732dBrian Paul level >= ctx->Const.MaxCubeTextureLevels) { 1235738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* bad width or height */ 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1238738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1239bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1240bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1241bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (width < 2 * border || width > 2 + maxSize || 1242bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1243be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1244bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level >= ctx->Const.MaxTextureLevels) { 1245bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick /* bad width or level */ 1246bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1247bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1248bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 1249bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) { 1250bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1251bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1252bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1253bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1254bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1255bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (width < 2 * border || width > 2 + maxSize || 1256bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1257be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian width > 0 && !_mesa_is_pow_two(width - 2 * border)) || 1258bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick height < 2 * border || height > 2 + maxSize || 1259bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.ARB_texture_non_power_of_two && 1260be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian height > 0 && !_mesa_is_pow_two(height - 2 * border)) || 1261bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level >= ctx->Const.MaxTextureLevels) { 1262bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick /* bad width or height or level */ 1263bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1264bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1265bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) { 1266bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1267bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1268bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1269738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1270738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1271738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1273738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1274738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1277064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick * Helper function to determine whether a target supports compressed textures 1278064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1279064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 1280f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergtarget_can_be_compressed(struct gl_context *ctx, GLenum target) 1281064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 1282646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1283646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1284646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 1285646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_TRUE; 1286646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1287646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1288646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1289646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1290646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1291646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1292646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1293646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1294646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1295646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1296646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.MESA_texture_array; 1297646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1298646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1299646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1300064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1301064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1302064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1303064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 13046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 13056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 13066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 130785288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 13086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 13096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 13106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 13116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 13126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 13136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 13146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 13156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 13166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 13176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 13186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 13196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 13206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 13213c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 13223c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1323afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1324c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 132585288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 132685288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1327c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1328c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1329c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1330c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1331afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 133277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul const GLboolean isProxy = _mesa_is_proxy_texture(target); 1333e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1334714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1335e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLenum proxy_target; 1336afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1337738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1338738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1339738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1340738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1341738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 13428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1343738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1344738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1345738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1346738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1347738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1348738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1349738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1350738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1351738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1352738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1353738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1354738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1355738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1356738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1357973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1358f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1359f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1360973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1361f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1362f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1363f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1364f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 1365738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1366738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1367738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1368738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 1369738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { 1370e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_1D; 1371e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick height = 1; 13727c4c82fc6d5301e27643868517aeb23fcb5c40e6Brian depth = 1; 13738afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 13748afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 137508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 1376afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1377afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1378afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1379afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 2) { 1380e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth = 1; 1381738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) { 1382e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_2D; 1383738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1384738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 1385738318bb75dea8dac4465f53850987f6062a732dBrian Paul (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1386738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 13878afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 13888afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 13898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 13908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1391e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_CUBE_MAP_ARB; 1392e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick sizeOK = (width == height); 13938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1394738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV || 1395738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_TEXTURE_RECTANGLE_NV) { 13968afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 13978afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 13988afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 13998afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1400e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_RECTANGLE_NV; 14018afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1402bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 1403bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_1D_ARRAY_EXT) { 1404bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick proxy_target = GL_PROXY_TEXTURE_1D_ARRAY_EXT; 1405bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 14068afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 14078afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)"); 14088afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 14098afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1410afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1411afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else if (dimensions == 3) { 1412738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) { 1413e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick proxy_target = GL_PROXY_TEXTURE_3D; 14148afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1415bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_2D_ARRAY_EXT || 1416bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_2D_ARRAY_EXT) { 1417bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick proxy_target = GL_PROXY_TEXTURE_2D_ARRAY_EXT; 1418bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 14198afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 142008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 1421afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1422afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1423afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1424afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 142508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( ctx, "bad dims in texture_error_check" ); 1426afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1427afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1428afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1429e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxy_target, level, 1430e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1431e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1432e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1433738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1434c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 14354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1436738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1437738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1438c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1439afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1440afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1441afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1442738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 144389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1444c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 14454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1446a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1447a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1448c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1449afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1450afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1451afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1452738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1453f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1454326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1455326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1456326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1457326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 145838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 145938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1460326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1461326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1462326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 14638a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 14648a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1465c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 146638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1467afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1468afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1469601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 147022e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1471ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul indexFormat = _mesa_is_index_format(format); 147222e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1473ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_index_format(internalFormat) && !indexFormat) || 1474ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1475ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1476ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1477ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1478601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1479601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 14808a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 14818a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1482601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1483601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1484601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1485601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1486601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1487c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1488601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1489601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1490c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1491fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 14922236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1493c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1494c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1495c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1496d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1497d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1498d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1499d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1500d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1501d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1502d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1503d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1504d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1505d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1506d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1507fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 15082236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1509fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1510c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1511d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1512d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1513d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1514c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1515c5b995066020191982b2315fc45d05e068eee761Brian Paul 1516601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1517601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 15182b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */ 1519601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1520601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1521601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 15222b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 15232b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 15242b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1525601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1526601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1527601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1528601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1529601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1530601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1531601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1532601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1533c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 1534064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick if (!target_can_be_compressed(ctx, target) && !isProxy) { 1535064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick _mesa_error(ctx, GL_INVALID_ENUM, 15362236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(target)", dimensions); 1537064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 153889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 153989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 154089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 154189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 15428978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 154389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 154489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 154589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 154689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 154789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1548326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1549326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1550326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1551326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1552326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1553326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1554326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1555326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1556326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1557326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1558326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1559326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1562afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 15656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1566c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 15676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 15696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 15706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 15716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 15726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 15736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 15746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 15756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 15766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 15776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 15786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 15796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 15806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15843c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 15853c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1586afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1587c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1588f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1589c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1590c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1591c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1592c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1594738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target */ 1595c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions == 1) { 1596738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target != GL_TEXTURE_1D) { 159708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); 1598c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1599afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1600c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1601c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 2) { 1602738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1603da62bcecfb92978d7243928cfa0fb076b3de762dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1604738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 1605738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1606738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1607738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1608fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 16095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell else if (target == GL_TEXTURE_RECTANGLE_NV) { 1610738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!ctx->Extensions.NV_texture_rectangle) { 1611738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1612738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1613738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1614d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1615bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 1616bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1617bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1618bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1619bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1620bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1621738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target != GL_TEXTURE_2D) { 162208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); 1623c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1624afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1625c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1626c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else if (dimensions == 3) { 1627bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (target == GL_TEXTURE_2D_ARRAY_EXT) { 1628bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1629bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 1630bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1631bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1632bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1633bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target != GL_TEXTURE_3D) { 163408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); 1635c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1637c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1638c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 1639738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem( ctx, "invalid dims in texture_error_check" ); 1640c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1641c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1642afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1643738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1644738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 16454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1646c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1647c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1649c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 16504e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 16514e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1652c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1653c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1654c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 16554e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 16564e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1657c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1658c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1659c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1660738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1661738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1662c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1663c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1666326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1667326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1668326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1669326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1670326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1671326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 16728a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 16738a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 16745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 16755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 16765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 16775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 16785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1679f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1680d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1681d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1682d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1683d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1684d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 16855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1686f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 16875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 16885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 16895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 16905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 16915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 16925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1693c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1694738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1695738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1696c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1697c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1699c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1700738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1701738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1702c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1704c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1705738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1706738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1707c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1708c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1709c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1710c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1711738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1712738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1713c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1715c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1716738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1717738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1718c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1719afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1720afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1721c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1722c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 172308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1724c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1725c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 172638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 172708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1728c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1730afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1731afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1732b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1733d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1734d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1735064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick if (!target_can_be_compressed(ctx, target)) { 173689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 17378978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(target=%s)", dimensions, 1738d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_lookup_enum_by_nr(target)); 1739e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1740e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1741d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1742d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1743d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1744d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1745d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1746d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1747e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17488978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1749d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1750e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1751e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1752d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1753d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1754e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17558978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1756e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 175789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1758d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 175989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17608978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 176189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 176289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1763e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1764e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1765c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1766c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1767afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1770c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 17716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 17736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 17746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 17756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 17766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 17776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 17786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 17796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 17806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 17826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 17843c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 17853c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1786afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1787c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1788f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1789c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1791afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 17920899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLenum type; 1793738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 17940899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1795afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1796738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1797738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 17995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 18005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 18015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 180334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 180434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 180534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 180634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 180734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 180834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 180934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 181034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 181134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 181234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1813738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1814738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1815738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1816738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1817738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1818738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1819738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1820738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 18210899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 18220899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 18230899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 18240899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 18250899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 18260899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 182734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 182834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 182934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 183034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 183134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 183234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 18339c936403de1aa868de1218deb2b93344b0d8d95dBrian Paul /* NOTE: the format and type aren't really significant for 18349c936403de1aa868de1218deb2b93344b0d8d95dBrian Paul * TestProxyTexImage(). Only the internalformat really matters. 18350899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul */ 1836738318bb75dea8dac4465f53850987f6062a732dBrian Paul type = GL_FLOAT; 1837738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1838738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check target and call ctx->Driver.TestProxyTexImage() to check the 1839738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth. 1840738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1841fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1842738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_1D) { 1843738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D, 1844738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1845738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1846738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, 1, 1, border); 1847738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1848738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 184908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); 1850fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1851fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1852c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1853fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1854738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (target == GL_TEXTURE_2D) { 1855738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D, 1856738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1857738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1858738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1859738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1860738318bb75dea8dac4465f53850987f6062a732dBrian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1861738318bb75dea8dac4465f53850987f6062a732dBrian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 18628afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 18638afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 18648afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return GL_TRUE; 18658afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1866738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = (width == height) && 1867738318bb75dea8dac4465f53850987f6062a732dBrian Paul ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB, 1868738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, format, type, 1869738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 18708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 18718afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 18728afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 187308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1874fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1875fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1876738318bb75dea8dac4465f53850987f6062a732dBrian Paul sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1877738318bb75dea8dac4465f53850987f6062a732dBrian Paul GL_PROXY_TEXTURE_RECTANGLE_NV, 1878738318bb75dea8dac4465f53850987f6062a732dBrian Paul level, internalFormat, 1879738318bb75dea8dac4465f53850987f6062a732dBrian Paul format, type, 1880738318bb75dea8dac4465f53850987f6062a732dBrian Paul width, height, 1, border); 1881fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1882bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 1883bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1884bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)"); 1885bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1886bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1887bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick sizeOK = ctx->Driver.TestProxyTexImage(ctx, 1888bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick GL_PROXY_TEXTURE_1D_ARRAY_EXT, 1889bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick level, internalFormat, 1890bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick format, type, 1891bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick width, height, 1, border); 1892bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1893738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 189408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); 1895fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1896fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1897c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1898738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1899738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "invalid dimensions in copytexture_error_check"); 1900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1901c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1902c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1903738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1904738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19054e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1906738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1907c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1908738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1909738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1910738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1911738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1912ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1913c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1914c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1915c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1916c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 191753cf87be1b93c760228e6a9af8115d2a9ff99337Brian if (!target_can_be_compressed(ctx, target)) { 191889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 19192236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 192089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 192189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 192289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 192389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19248978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 192589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 192689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 192789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1928ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depth_format(internalFormat)) { 19290899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19301a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 19310899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19328978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth)", dimensions); 19330899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19340899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19350899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 1936ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depthstencil_format(internalFormat)) { 19370899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19381a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 19390899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19408978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth/stencil buffer)", dimensions); 19410899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19420899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19430899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 194489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1945c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1946c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1947c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1948c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1949c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 19506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 195134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 19529dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 19539dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 19546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 19566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 19576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 19586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 19596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 19616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 1962c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1963f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 19649dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 1965c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 196634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 196734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 196834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 196934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 197034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 197134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 197234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 197334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 197434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 197534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 19769dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check target */ 1977fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (dimensions == 1) { 1978fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul if (target != GL_TEXTURE_1D) { 197908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); 1980fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1981fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1982c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1983fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 2) { 1984fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 1985fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 1986fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) { 1987fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1988fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul return GL_TRUE; 1989fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 1990fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul } 1991fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul else if (target == GL_TEXTURE_RECTANGLE_NV) { 1992fa268adc9df30c8e3413990ee0e68c139ca0c069Brian Paul if (!ctx->Extensions.NV_texture_rectangle) { 199308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 1994fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 1995fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1996fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 1997bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_TEXTURE_1D_ARRAY_EXT) { 1998bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (!ctx->Extensions.MESA_texture_array) { 1999bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2000bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 2001bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 2002bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 2003fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (target != GL_TEXTURE_2D) { 200408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); 2005fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul return GL_TRUE; 2006fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2007c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2008fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul else if (dimensions == 3) { 2009bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (((target != GL_TEXTURE_2D_ARRAY_EXT) || 2010bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (!ctx->Extensions.MESA_texture_array)) 2011bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick && (target != GL_TEXTURE_3D)) { 2012bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); 2013bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 2014fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul } 2015c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2016c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2017738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2018738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20194e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2021c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2022c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2023c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 20255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 20265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 20279dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20289dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 20299dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 20309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 20319dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 20329dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 20339dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 20349dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 20359dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 20365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2037f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 20385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 20395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 20405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 20415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 20425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 20439dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2044c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 20454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2046b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2047b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2048c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2049c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2050c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20519dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 20529dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 20539dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20549dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 20559dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20569dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20579dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 20589dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20599dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 20609dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20619dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20629dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20639dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2064c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 20654e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2067c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2068c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 206938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 20704e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20714e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2072c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 20764e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20774e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2078c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2079c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2080c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 208138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 20824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20834e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2084c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2085c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2086c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2087c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2089c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2090c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 20914e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20924e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2093c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2094c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 209538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 20964e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2098c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2099c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2100c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2101c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2102b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 210353cf87be1b93c760228e6a9af8115d2a9ff99337Brian if (!target_can_be_compressed(ctx, target)) { 210489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 21052236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexSubImage%dD(target)", dimensions); 2106e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2107e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 210889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 210989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 211089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21118978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2112e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2113e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 211489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2115798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 211689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21178978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2118e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 211989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2120798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 212189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21228978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 212389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 212489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2125e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2126e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2127a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2128d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2129d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2130d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2131d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2132985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2133985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2134803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2135803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2136985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2137985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2138985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2139a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 21401a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 21410899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21428978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth buffer)", 21430899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21440899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21450899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21460899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2147a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 21481a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 21490899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21508978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth/stencil buffer)", 21510899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21520899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21530899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21540899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21550899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2156326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2157326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2158326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2159412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2160326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2161412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2162326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2163326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2164326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2165326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2166326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2167326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2168326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2169c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2170c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2171c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2172c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2173c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21742897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 21752897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 21762897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2177f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 21782897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 21792897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 21802897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 21812897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2183519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 21842897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2185519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2186519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 21872897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2188519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 21892897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 21902897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2191f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 21922897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 21932897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 21942897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21952897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 21962897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2197519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 21982897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2199519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 22002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2201519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2202519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2203519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2204519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2205519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]); 2206519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2207ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 22082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 22092897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2210519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2211519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2212519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2213519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2214519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2215519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 22162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 22172897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 22182897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 22192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 22202897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 22212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 22222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2223f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 22242897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 22252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 22262897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 22272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 22282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 22292897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 22302897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 22312897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 22322897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 22332897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 22342897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 22352897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 22362897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22372897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22382914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 22392914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 22402914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 22412914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 22422914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 22432914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void 2244f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 22452914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 22462914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 22472914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2248ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2249ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2250ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 22512914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 22522914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 22532914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 22542914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 22552914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22562914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22571826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 22581826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 22591826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 22601826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 22611826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 22621826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 22631826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 22641826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 22651826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 22661826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22671826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 22681826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 22691826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 22701826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 22711826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22721826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 22731826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 22741826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22751826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 22761826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22771826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 22781826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 22791826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22801826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 22811826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22821826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 22831826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 22841826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22851826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 22861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 22881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 22891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 22901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 22921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 22931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 22961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 22981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 22991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2300519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2301bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2302bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2303bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2304bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2305bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2306bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2307bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2308bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 230983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2310f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2311bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2312bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2313bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2314bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 231583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 231683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2317bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2318bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2319bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2320bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2321bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2322bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2323bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2324bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2325bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2326bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2327bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 232883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 232983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2330bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2331bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2332bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2333bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 233483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 233583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 233683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2337bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2338bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2339bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2340bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2341289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul/* 2342c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Called from the API. Note that width includes the border. 2343c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2344c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 234543911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2346fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border, GLenum format, 2347fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum type, const GLvoid *pixels ) 2348c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2349fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2350cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2351c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2352d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2353d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexImage1D %s %d %s %d %d %s %s %p\n", 2354d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2355d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), width, border, 2356d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2357d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2358d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 23591826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = override_internal_format(internalFormat, width, 1); 23601826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 23618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_1D) { 23628c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 23630293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 23640293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2365e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2366f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 236785288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 1, target, level, internalFormat, 236885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, 1, 1, border)) { 23698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2370c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2371c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 23721ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 23735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2374fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2375b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 23765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 23775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 23785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 23795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 23805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 23815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2382ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 238383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 238483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2385ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2386ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2387ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2388ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2389ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 2390ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 239183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 239283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 239383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 239483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2395ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 23968fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, 1, 1, 239783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, 239883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat); 239911caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2400ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* Give the texture to the driver. <pixels> may be null. */ 2401ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexImage1D); 2402ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2403ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, border, format, type, pixels, 2404ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul &ctx->Unpack, texObj, texImage); 2405ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24062914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 24072914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2408ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul update_fbo_texture(ctx, texObj, face, level); 240962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2410ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* state update */ 2411ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul texObj->_Complete = GL_FALSE; 2412ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2413ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2414ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 24155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2416c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 241738d3f3d660225150715bc06f6b33e394ba803299Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 2418c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* Proxy texture: check for errors and update proxy state */ 2419738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2420738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 242185288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 1, target, level, internalFormat, 242285288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, 1, 1, border)) { 2423738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2424a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2425a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2426c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 242789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 242889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2429bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2430bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 243183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, target, 243283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul level, 243383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 243483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 243583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 243683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 243789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2438c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2439c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 244008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); 2441c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return; 2442c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2443c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2444c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2445c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2446c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 244743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2448fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLint border, 2449fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2450fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2451c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2452fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2453cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2454c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2455d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2456d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexImage2D %s %d %s %d %d %d %s %s %p\n", 2457d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2458d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), width, height, 2459d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora border, _mesa_lookup_enum_by_nr(format), 2460d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2461d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 24621826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = override_internal_format(internalFormat, width, height); 24631826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 24648e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 2465a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 2466fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 24678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) || 24688afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (ctx->Extensions.NV_texture_rectangle && 2469bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_RECTANGLE_NV) || 2470bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2471bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_1D_ARRAY_EXT)) { 24728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 24730293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24740293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2475e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2476f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 247785288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 2, target, level, internalFormat, 247885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, height, 1, border)) { 24798e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2480c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2481c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24821ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 24835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2484fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2485b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 24865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 24895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 24905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 24915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2492ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 249383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 249483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2495ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2496ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2497ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2498ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2499ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 2500ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 250183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 250283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 250383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 250483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 250583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 250683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 250711caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2508ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* Give the texture to the driver. <pixels> may be null. */ 2509ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexImage2D); 2510ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2511ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, height, border, format, type, 2512ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul pixels, &ctx->Unpack, texObj, texImage); 2513ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 25142914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 25152914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2516ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul update_fbo_texture(ctx, texObj, face, level); 2517ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2518ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* state update */ 2519ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul texObj->_Complete = GL_FALSE; 2520ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2521ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2522ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 25235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2525172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul else if (target == GL_PROXY_TEXTURE_2D || 2526172281dad8d1f1d32f5f31583a5fa565aa1bf5daBrian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 25278afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul ctx->Extensions.ARB_texture_cube_map) || 25288afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul (target == GL_PROXY_TEXTURE_RECTANGLE_NV && 2529bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick ctx->Extensions.NV_texture_rectangle) || 2530bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2531bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT)) { 2532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2533738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2534738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 253585288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 2, target, level, internalFormat, 253685288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, height, 1, border)) { 2537738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2538a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2539ea4b183b8c3730ec2c6b5152cad1a68889634487Brian Paul clear_teximage_fields(texImage); 2540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 254189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 254289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2543bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2544bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 254583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 254683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target, level, 254783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 254883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 254983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 255083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 255189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2552afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 255408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); 2555afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2562afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2564c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2565b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2566fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2567fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2568fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2570fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2571cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2573d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2574d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n", 2575d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2576d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), width, height, 2577d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora depth, border, _mesa_lookup_enum_by_nr(format), 2578d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2579d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 25801826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = override_internal_format(internalFormat, width, height); 25811826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2582bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (target == GL_TEXTURE_3D || 2583bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2584bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_TEXTURE_2D_ARRAY_EXT)) { 2585519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* non-proxy target */ 25860293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 25870293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2588e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2589289d47eee5342bd7ec1c25a29d9bdc8d6f9dc4edBrian Paul 259085288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 3, target, level, (GLint) internalFormat, 259185288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, height, depth, border)) { 25928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2594afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 25951ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 25965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 25975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 2598b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 25995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 26025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 26035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 26045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2605ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 260683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 260783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2608ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2609ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2610ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2611fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2612ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 261383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 261483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 261583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 2616ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2617ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, height, depth, 261883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 261911caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2620ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* Give the texture to the driver. <pixels> may be null. */ 2621ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexImage3D); 2622ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2623ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, height, depth, border, format, type, 2624ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul pixels, &ctx->Unpack, texObj, texImage); 2625afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26262914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 26272914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2628ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul update_fbo_texture(ctx, texObj, face, level); 2629519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2630ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* state update */ 2631ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul texObj->_Complete = GL_FALSE; 2632ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2633ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 26345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2637bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick else if (target == GL_PROXY_TEXTURE_3D || 2638bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick (ctx->Extensions.MESA_texture_array && 2639bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT)) { 2640afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* Proxy texture: check for errors and update proxy state */ 2641738318bb75dea8dac4465f53850987f6062a732dBrian Paul struct gl_texture_image *texImage; 2642738318bb75dea8dac4465f53850987f6062a732dBrian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 264385288ad722aa0ad378004c523a0e1a4984e15316Brian Paul if (texture_error_check(ctx, 3, target, level, internalFormat, 264485288ad722aa0ad378004c523a0e1a4984e15316Brian Paul format, type, width, height, depth, border)) { 2645738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2646a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2647a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 264989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 265089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2651bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2652bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 265383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 265483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target, level, 265583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 265683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 26579f6022d0567dc1288888212d7128acc48795b306Brian _mesa_init_teximage_fields(ctx, target, texImage, width, height, 265883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul depth, border, internalFormat, texFormat); 265989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2661afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 266208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); 2663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 2664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2665afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2667afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2668c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 266943911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2670663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2671663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2672663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2673663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 267489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2675663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2676663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2677663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2678663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2679d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2680d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2681d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2682d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2683d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2684d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 268517efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 268617efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2687d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 26882002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 26892002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 26902002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 26912002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 26922002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 26932002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2694d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2695d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2696d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2697d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2698d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2699d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2700d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 2701d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2702d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2703d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2704d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2705d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2706d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2707d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2708d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2709d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 2710d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (texImage->Data) 2711d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.FreeTexImageData( ctx, texImage ); 2712d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2713d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ASSERT(texImage->Data == NULL); 2714d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2715d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2716d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2717d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2718d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2719d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2720d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2721d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2722d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2723d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2724d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2725d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2726afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2727c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2728fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 2729fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLsizei width, 2730fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2731fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2732afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27330293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2734b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 27352c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 273675280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 273775280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2738d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2739d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexSubImage1D %s %d %d %d %s %s %p\n", 2740d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2741d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora xoffset, width, _mesa_lookup_enum_by_nr(format), 2742d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2743d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 27441ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 274508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 27462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2747c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 27488fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, 1, 1, format, type)) { 2749f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2750afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2751afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 2753b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 27545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texObj); 2755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2759afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 27605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (subtexture_error_check2(ctx, 1, target, level, xoffset, 0, 0, 27618fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, 1, 1, format, type, texImage)) { 2762a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 27635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2764a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else if (width > 0) { 2765ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2766ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul xoffset += texImage->Border; 2767347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2768ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexSubImage1D); 2769ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, xoffset, width, 2770ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul format, type, pixels, &ctx->Unpack, 2771ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul texObj, texImage); 27722914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 27732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 27742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2775ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2776ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 27775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2782c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2783fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2784fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2785fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2786fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2787fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27890293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 27900293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 27912c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 279275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 279375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2794d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2795d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n", 2796d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2797d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora xoffset, yoffset, width, height, 2798d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2799d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2800d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 28011ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 280208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 28032aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2804c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 28058fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, height, 1, format, type)) { 2806f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2807afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2808afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2809b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2810a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 28115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2814afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (subtexture_error_check2(ctx, 2, target, level, xoffset, yoffset, 0, 28168fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, height, 1, format, type, texImage)) { 2817a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 28185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2819a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else if (width > 0 && height >= 0) { 2820ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2821ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul xoffset += texImage->Border; 2822ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul yoffset += texImage->Border; 2823347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2824ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexSubImage2D); 2825ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset, 2826ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, height, format, type, pixels, 2827ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul &ctx->Unpack, texObj, texImage); 28282914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28292914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 28302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2831ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2832ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 28335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2835c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2836afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2837afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2838afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2839c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2840fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2841fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2842fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2843fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2844fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2845afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28460293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 28470293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 28482c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 284975280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 285075280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2851d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2852d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n", 2853d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2854d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora xoffset, yoffset, zoffset, width, height, depth, 2855d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2856d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2857d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 28581ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul if (ctx->NewState & _MESA_NEW_TRANSFER_STATE) 285908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 28602aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 2861c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 2862c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul width, height, depth, format, type)) { 2863f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2864afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2865afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2866b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 28675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 28715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 2872a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (subtexture_error_check2(ctx, 3, target, level, 2873a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset, yoffset, zoffset, 2874a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul width, height, depth, 2875a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul format, type, texImage)) { 2876a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 28775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2878a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else if (width > 0 && height > 0 && height > 0) { 2879ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 2880ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul xoffset += texImage->Border; 2881ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul yoffset += texImage->Border; 2882ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul zoffset += texImage->Border; 28835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 2884ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(ctx->Driver.TexSubImage3D); 2885ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 2886ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul xoffset, yoffset, zoffset, 2887ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul width, height, depth, 2888ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul format, type, pixels, 2889ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul &ctx->Unpack, texObj, texImage ); 28902914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28912914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 28922914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2893ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2894ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 28955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2897afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2898afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2899afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2900afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2901c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2902fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 2903fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum internalFormat, 2904fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, 2905fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLint border ) 2906afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 29072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 29082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2909e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2910fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2911cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2912afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2913d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2914d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCopyTexImage1D %s %d %s %d %d %d %d\n", 2915d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2916d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 2917d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora x, y, width, border); 2918d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 291963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 292008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2921fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2922ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 1, target, level, internalFormat, 29238fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, 1, border)) 2924ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2925ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2926b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2927a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 29285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 29315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 29325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); 29335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2934c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 293583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 293683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2937c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 2938c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2939c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 29407dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 2941c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 29427dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 294383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 294483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 294583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 29462aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 294783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 294883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 294911caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2950c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(ctx->Driver.CopyTexImage1D); 2951c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat, 2952c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul x, y, width, border); 29532aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 29542914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 29552914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2956c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul update_fbo_texture(ctx, texObj, face, level); 2957519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2958c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul /* state update */ 2959c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj->_Complete = GL_FALSE; 2960c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2961c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 29625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2964afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2965afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2966afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2967afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2968c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2969fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 2970fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 2971fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border ) 2972afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 29732aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 29742aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2975e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 2976fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2977cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2978afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2979d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2980d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n", 2981d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2982d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 2983d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora x, y, width, height, border); 2984d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 298563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 298608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2987fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2988ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul if (copytexture_error_check(ctx, 2, target, level, internalFormat, 29898fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, height, border)) 2990ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2991ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2992b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 29937dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 29945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2997afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 29995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); 30005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3001c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 300283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 300383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3004c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3005c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3006c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 30072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 3008c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 30094f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul 301083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 301183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 301283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 3013519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 301483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 301583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 301611caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 3017c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 3018c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat, 3019c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul x, y, width, height, border); 3020c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 30212914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 30222914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3023c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul update_fbo_texture(ctx, texObj, face, level); 3024c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 3025c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul /* state update */ 3026c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj->_Complete = GL_FALSE; 3027c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->NewState |= _NEW_TEXTURE; 3028c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 30295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3032afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3034c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3035fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 3036fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 3037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 30385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3039347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 304003bafd1f9fa000abdb794b2ae344a68840c83201Brian GLint yoffset = 0; 304103bafd1f9fa000abdb794b2ae344a68840c83201Brian GLsizei height = 1; 304203bafd1f9fa000abdb794b2ae344a68840c83201Brian 3043fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3044cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3045afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3046d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3047d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCopyTexSubImage1D %s %d %d %d %d %d\n", 3048d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 3049d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora level, xoffset, x, y, width); 3050d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 305163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 305208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3053fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 30549dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 1, target, level)) 3055ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3056ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3057b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 30585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 30605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 30615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 30625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 30635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (copytexsubimage_error_check2(ctx, 1, target, level, 30648fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul xoffset, 0, 0, width, 1, texImage)) { 3065a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 306603bafd1f9fa000abdb794b2ae344a68840c83201Brian } 3067a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 3068a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 3069a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset += texImage->Border; 307003bafd1f9fa000abdb794b2ae344a68840c83201Brian 3071a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 3072a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 3073a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ASSERT(ctx->Driver.CopyTexSubImage1D); 3074a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 3075a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset, x, y, width); 30762914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 30772914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 30782914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3079a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 3080a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 3081a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 30825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3084afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3085afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3086afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3087afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3088c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3089fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 3090fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 3091fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3092afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 30935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3094347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 3095fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3096cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3097afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3098d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3099d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n", 3100d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 3101d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora level, xoffset, yoffset, x, y, width, height); 3102d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 310363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 310408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3105fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 31069dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 2, target, level)) 3107ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3108ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3109b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 31105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 31115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 31125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 31135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 3114347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 3115a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (copytexsubimage_error_check2(ctx, 2, target, level, 3116a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset, yoffset, 0, 31178fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul width, height, texImage)) { 3118a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 311903bafd1f9fa000abdb794b2ae344a68840c83201Brian } 3120a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 3121a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 3122a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset += texImage->Border; 3123a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul yoffset += texImage->Border; 312403bafd1f9fa000abdb794b2ae344a68840c83201Brian 3125a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 3126a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 3127a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ASSERT(ctx->Driver.CopyTexSubImage2D); 3128a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, xoffset, yoffset, 3129a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul x, y, width, height); 31302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 31312914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 31322914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3133a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 3134a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 3135a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 31365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 31375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3142c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3143fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 3144fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 3145fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 31475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3148347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 3149fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 3150cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3152d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3153d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n", 3154d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 3155d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora level, xoffset, yoffset, zoffset, x, y, width, height); 3156d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 315763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 315808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3159fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 31609dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (copytexsubimage_error_check1(ctx, 3, target, level)) 3161ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3162ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3163b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3164347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 31655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 31665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 31675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 3168347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 31695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (copytexsubimage_error_check2(ctx, 3, target, level, xoffset, yoffset, 31708fb49554d9404cd3538f569003a0f917fbdfb2d8Brian Paul zoffset, width, height, texImage)) { 3171a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recored */ 317203bafd1f9fa000abdb794b2ae344a68840c83201Brian } 3173a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 3174a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* If we have a border, xoffset=-1 is legal. Bias by border width */ 3175a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset += texImage->Border; 3176a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul yoffset += texImage->Border; 3177a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul zoffset += texImage->Border; 317803bafd1f9fa000abdb794b2ae344a68840c83201Brian 3179a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 3180a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 3181a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ASSERT(ctx->Driver.CopyTexSubImage3D); 3182a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 3183a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul xoffset, yoffset, zoffset, 3184a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul x, y, width, height); 31852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 31862914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 31872914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3188a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 3189a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 3190a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 31915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 31925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 31941207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 31951207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 31961207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 319789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 319989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 320089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 320189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 320454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 320554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 320654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 320754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 320854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 320954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 321054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 321154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 321254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 321354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 321454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 321507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 321607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 321707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 321807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 321907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 322007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 322107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 322207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 322307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 322454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 322554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 322654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 322789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 322889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 322989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 323089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3231f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 323289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 323389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 323489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 323589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei imageSize) 323689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 3237c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 323889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 323989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 324089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 324189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 324289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 324389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 324489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 324589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 324689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 324789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 324889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 324989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 325089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 325189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 325289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 325389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 325489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 325589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 325689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 325789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 325889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 325989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 326089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 326289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 326389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 326589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 326689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 326789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 326889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 32695f9d7bb2425aee65e75667953a6cc304072f2b11Vinson Lee else { 32705f9d7bb2425aee65e75667953a6cc304072f2b11Vinson Lee assert(0); 32715f9d7bb2425aee65e75667953a6cc304072f2b11Vinson Lee return GL_INVALID_ENUM; 32725f9d7bb2425aee65e75667953a6cc304072f2b11Vinson Lee } 327389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 327489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 327589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3276c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 3277c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, internalFormat)) 327889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 327989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3280c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3281a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick if (_mesa_base_tex_format(ctx, internalFormat) < 0) 3282a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3283a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 328489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) 328589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 328689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3287887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul /* 3288887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * XXX We should probably use the proxy texture error check function here. 3289887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul */ 3290887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize || 3291be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(width))) 329289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 329389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3294887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize || 3295be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(height))) 329689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 329789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 329889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3299887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((depth < 1 || depth > maxTextureSize || 3300be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(depth))) 330189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 2) 330289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 330389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 330489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 330589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 330689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 330789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 330889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 330989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 331089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 331189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 331254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, internalFormat); 331389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 331489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 331589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 33160a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 33170a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if ((internalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT || 33180a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT || 33190a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT || 33200a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) 33210a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul && border != 0) { 33220a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_INVALID_OPERATION; 33230a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 33240a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif 33250a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 332689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 332789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 332889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 332989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 333089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 333189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 33322371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 33332371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 33342371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 333589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 333689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 333789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3338f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 333989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 334089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 334189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 334289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 334389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 334489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 334507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3346a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 334789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 334889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 334989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 335089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 335189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 335289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 335389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 335489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 335589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 335689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 335789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 335889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 335989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 336089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 336189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 336289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 336389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 336489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 336589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 336689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 336789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 336889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 336989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 337189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 337289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 337589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 337689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 337789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 337889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 337989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 338089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3381c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3382c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 338389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 338489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3385887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 338689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 338789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3388887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 338989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 339089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 339189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 339289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 339389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 339489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 339507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 339607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 33972371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 339807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 339907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 340007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 340189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 340307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 340489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 340607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 340789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 340889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 340954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 341089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 341189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 341289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 341389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 341489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 341589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 341689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3417f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3418f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3419f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3420f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3421f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3422f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3423f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3424f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3425f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3426f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3427f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3428f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3429f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3430f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3431f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3432f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3433f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3434f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3435ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3436ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3437f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3438f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3439f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3440f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3441f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3442f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3443f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3444ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3445ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3446f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3447f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3448f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3449f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3450f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3451f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3452f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3453f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3454ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3455ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3456f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3457f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3458f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3459f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3460f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3461f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3462f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3463f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3464f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3465f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 346689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3467c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 34681207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 3469aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 34701207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint border, GLsizei imageSize, 34711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 34721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3473aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3474cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3475aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3476d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3477d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n", 3478d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3479d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 3480d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora width, border, imageSize, data); 3481d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 3482aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul if (target == GL_TEXTURE_1D) { 34838c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3484aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3485aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 348689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 348789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 348889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 348989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage1D"); 349089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3491aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3492aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3493b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3494aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 34955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 34985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 34995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D"); 35005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3501c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 350283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 350383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3504c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3505c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3506c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3507c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 35085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 350983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 351083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 351183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 35126628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 351383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 351483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 351511caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 3516c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 3517c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 3518c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul internalFormat, width, border, 3519c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul imageSize, data, 3520c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj, texImage); 3521aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 35222914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 35232914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3524c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul /* state update */ 3525c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj->_Complete = GL_FALSE; 3526c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->NewState |= _NEW_TEXTURE; 3527c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 35285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3530aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3531aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_1D) { 3532aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 353389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 1, target, level, 353489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, 1, 1, border, imageSize); 35358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 35368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 353738d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 353838d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 353938d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, 1, 1, border); 354038d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 354138d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3542aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3543a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3544a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3545a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3546a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3547aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 354889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 354989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 35505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 355189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 355283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 35539519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 3554b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 35555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 35565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 35575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 35585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 355983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 356083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 356183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 35625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1, 356383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 35645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 356689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3567aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3568aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 356989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1D(target)"); 3570aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3571aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 35721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35731207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3574c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35751207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 3576aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 35771207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLint border, GLsizei imageSize, 35781207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35791207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3580aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3581cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3582aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3583d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3584d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n", 3585d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3586d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 3587d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora width, height, border, imageSize, data); 3588d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 35897179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#if FEATURE_ES 35907179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg switch (internalFormat) { 35917179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE4_RGB8_OES: 35927179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE4_RGBA8_OES: 35937179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE4_R5_G6_B5_OES: 35947179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE4_RGBA4_OES: 35957179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE4_RGB5_A1_OES: 35967179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE8_RGB8_OES: 35977179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE8_RGBA8_OES: 35987179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE8_R5_G6_B5_OES: 35997179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE8_RGBA4_OES: 36007179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg case GL_PALETTE8_RGB5_A1_OES: 36017179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 36027179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg width, height, imageSize, data); 36037179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 36047179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 36057179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#endif 36067179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 36078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (target == GL_TEXTURE_2D || 3608a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell (ctx->Extensions.ARB_texture_cube_map && 36099540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 361089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { 36118c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3612aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3613aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 36149519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 361589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 361689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 361789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 361889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage2D"); 361989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3620aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3621aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3622b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3623aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 36245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 36255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 36265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 36275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 36285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); 36295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3630c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 363183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 363283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3633c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3634c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3635c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3636c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3637c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 363883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 363983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 364083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 3641c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 364283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 364383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 364411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 3645c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 3646c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 3647c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul internalFormat, width, height, 3648c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul border, imageSize, data, 3649c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj, texImage); 3650c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 36512914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 36522914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3653c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul /* state update */ 3654c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj->_Complete = GL_FALSE; 3655c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->NewState |= _NEW_TEXTURE; 3656c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3657c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 36585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3659aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 366089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_2D || 366189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB && 366289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul ctx->Extensions.ARB_texture_cube_map)) { 3663aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 366489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 2, target, level, 366589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, 1, border, imageSize); 36668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 36678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 366838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 366938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 367038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, 1, border); 367138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 367238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3673aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3674a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3675a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3676a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3677a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3678aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 367989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 368089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 36815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 368289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 368383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 36849519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 3685b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 36865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 36875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 36885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 36895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 369083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 369183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 369283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 36935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 369483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 36955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 36965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 369789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3698aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3699aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 370089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(target)"); 3701aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3702aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 37031207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37041207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37051207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3706c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 37071207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 3708aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GLenum internalFormat, GLsizei width, 37091207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLint border, 37101207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 37111207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 3712aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul GET_CURRENT_CONTEXT(ctx); 3713cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3714aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3715d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 3716d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_debug(ctx, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n", 3717d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3718d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 3719d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora width, height, depth, border, imageSize, data); 3720d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 37219540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul if (target == GL_TEXTURE_3D) { 37228c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3723aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3724aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 372589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 372689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 372789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 372889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, error, "glCompressedTexImage3D"); 372989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3730aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3731aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3732b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 37339519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 37345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 37365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 37375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 37385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D"); 37395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3740c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 374183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 374283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3743c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3744c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3745c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3746c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3747c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 374883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 374983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 375083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 375183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3752c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, 3753c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul width, height, depth, 375483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul border, internalFormat, texFormat); 375511caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 3756c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 3757c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 3758c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul internalFormat, 3759c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul width, height, depth, 3760c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul border, imageSize, data, 3761c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj, texImage); 3762c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 37632914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 37642914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3765c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul /* state update */ 3766c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul texObj->_Complete = GL_FALSE; 3767c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->NewState |= _NEW_TEXTURE; 3768c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3769c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 37705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3771aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3772aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else if (target == GL_PROXY_TEXTURE_3D) { 3773aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* Proxy texture: check for errors and update proxy state */ 377489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error = compressed_texture_error_check(ctx, 3, target, level, 377589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul internalFormat, width, height, depth, border, imageSize); 37768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 37778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul ASSERT(ctx->Driver.TestProxyTexImage); 377838d3f3d660225150715bc06f6b33e394ba803299Brian Paul error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, 377938d3f3d660225150715bc06f6b33e394ba803299Brian Paul internalFormat, GL_NONE, GL_NONE, 378038d3f3d660225150715bc06f6b33e394ba803299Brian Paul width, height, depth, border); 378138d3f3d660225150715bc06f6b33e394ba803299Brian Paul } 378238d3f3d660225150715bc06f6b33e394ba803299Brian Paul if (error) { 3783aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul /* if error, clear all proxy texture image parameters */ 3784a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 3785a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 3786a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 3787a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 3788aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 378989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 379089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* store the teximage parameters */ 37915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 379289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul struct gl_texture_image *texImage; 379383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 37949519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 3795b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 37969519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 37975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 37995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 380083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 380183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 380283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 38035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_init_teximage_fields(ctx, target, texImage, width, height, 380483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul depth, border, internalFormat, 380583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat); 38065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 38075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 380889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3809aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3810aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 381189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3D(target)"); 3812aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3813aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 38141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 38151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 38161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 38176bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 38186bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 38196bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 38206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 38216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 38226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 38236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 38246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 38251207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 38269540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 38279540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 382889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3829a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 383075280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 383175280a2c742ee241d392618a3b29548fce1520a9Brian Paul 38326bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3833c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 38346bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3835c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 383689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 38376bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 383889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 38399540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 38409540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3841b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3842c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 38435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 38445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 38455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 38465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 38479540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 38486bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3849f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3850f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3851c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 38526bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 38536bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 38546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 38556bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 38566bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 38576bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 38586bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 38596bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 38606bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 38616bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 38626bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 38636bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 38646bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 38656bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 38666bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 38676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 38686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 38696bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 38706bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 38716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 38726bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 38736bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 38746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 38756bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 38766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 38776bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 38786bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 38796bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 38806bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 38816bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3882c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 38832914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 38842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 38852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 38862914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 38875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 38889540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 38895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 38901207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 38911207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 38921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3893c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 38946bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 38956bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 38966bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 38976bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 38986bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 38996bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 39006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 39016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 39026bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 39036bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 39041207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 39051207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 39061207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 39071207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 39081207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 39096bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 39106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 39111207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 39121207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 39131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3914c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 39151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 39161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 39171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 39181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 39191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 39206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 39216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 39221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3923