teximage.c revision 7ecb61c30c4984a8513b306b640f9d274d8ecf61
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian * mesa 3-D graphics library 325be043940b25a5fe6eb8058070b3e8f12e92039Brian Paul * Version: 7.6 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 59f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 33fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 34b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 36d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h" 3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 3834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 413c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 42ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 43db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 44fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 461a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 497179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 505e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 534cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 587ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul#define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL) 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 634cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 824cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 83f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/* 84887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)). 85973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1. 86afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 87fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int 88fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n ) 89afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 90afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint i = 1; 91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg GLint log2 = 0; 92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 93973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n < 0) 94afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return -1; 95973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul 96973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (n == 0) 97973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul return 0; 98afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg while ( n > i ) { 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg i *= 2; 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg log2++; 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (i != n) { 104887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul return log2 - 1; 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg else { 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return log2; 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1141749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 1151749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 1166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1181749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 1196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 12289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 12389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 12489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 12573b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 12673b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 128b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 129f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1311749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 180f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 181f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 182f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 183f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 184f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke if (ctx->Extensions.EXT_texture_format_BGRA8888) { 185f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 186f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke case GL_BGRA_EXT: 187f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 188f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 189f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 190f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 191f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 192f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 193f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 194f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 199f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 200f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 202e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 203f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 204f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 2084741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 2114741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 2124741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 2134741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 214f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 215f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 216f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 217f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 21989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 22033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 22133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 22233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 22333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 22433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 22533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 22633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 22733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 22833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 22933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 23033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 23133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 23233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 23333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 23433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 24089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 24289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2508f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2518f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 25540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 257f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 260f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 265663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 267f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 268663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 269f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 270f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 271f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 27389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 275f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2781749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 280f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 282f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 288f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 289f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 290f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 291f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 292f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 293f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 294f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 295f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 296f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 297f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 298f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 299f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 3008f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 301f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 302afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 303f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 304114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 305114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 306114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 307114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 308114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 309114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 310114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 311114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 312114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 313114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 314c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger if (ctx->Extensions.MESA_texture_signed_rgba) { 315c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 316c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 317c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 318c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 319c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 320c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 321c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 322c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 323114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3261ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3271ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3281ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3291ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3301ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3311ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3321ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3331ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3500a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3530a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3540a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3553488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3560a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3570a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 358abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3590a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3600a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3610a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3620a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 402abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 403abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 404abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 405abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 406abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 407abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 408abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 409abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 4106988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4116988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 4136988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4146988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4153ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4163ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4173ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4183ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4193ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4206988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4246988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4256988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4266988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4276988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4286988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4296988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4303ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4313ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4373ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4383ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4396988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4413ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4423ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4433ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4443ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4456988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4463ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4473ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4483ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4496988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4506988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4536988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4553ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4563ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4573ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4583ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4593ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4603ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4613ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4896988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4916988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4926988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4946988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4956988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4966988f65e43297ae63bbce30bf882f870b370096cBrian Paul 497e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4986988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 499e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 500e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 5016988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 502e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 503e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 5046988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 5056988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 5066988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 5076988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 508abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 509abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 5107d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák if (ctx->Extensions.EXT_texture_compression_latc) { 5117d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák switch (internalFormat) { 5127d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 5137d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 5147d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE; 5157d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 5167d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 5177d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE_ALPHA; 5187d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák default: 5197d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák ; /* fallthrough */ 5207d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5217d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5227d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 52369f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák if (ctx->Extensions.ATI_texture_compression_3dc) { 52469f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák switch (internalFormat) { 52569f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 52669f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák return GL_LUMINANCE_ALPHA; 52769f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák default: 52869f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák ; /* fallthrough */ 52969f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 53069f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 53169f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák 532f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 535afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 537e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 538e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 539e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 540e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 541e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 542519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 543519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 544519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 545519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 546519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 547519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 548519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 549519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 550519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 551519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 5606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 562afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5633893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5653893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 567fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5689c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5699c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 570fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 571fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5729c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5739c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5749c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5759c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 576a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 577a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 578fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 579fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 580fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 581a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 584a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 585a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 58977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 59077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 591f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 59277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 593a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 59477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 59577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 59677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 59777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 598a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5993e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 6004cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 6013e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6021eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6033e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6043e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 6053e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 6063e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 607f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx, 6084cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 6093e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 610c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 611c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 6123e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 6133e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 6144cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 6153e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 6163e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 6183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 6193e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6203e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6213e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 6226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 6236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6241eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6263e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 627a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 62877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6293c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6303c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 63177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.FreeTexImageData); 6365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 6375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 6383e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 639b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 64032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage->ImageOffsets); 64132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage); 64277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 64377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 64477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 651aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 65277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 65377ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 654aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 6552465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below */ 6562465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul assert(NUM_TEXTURE_TARGETS == 7); 6572465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 66127f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 662bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 663bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 664bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 665aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 666aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 667aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 66935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target 67035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 67135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum 67235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target) 67335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{ 67435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul switch (target) { 67535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D: 67635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D: 67735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D; 67835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D: 67935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D: 68035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D; 68135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_3D: 68235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_3D: 68335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_3D; 68435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 68535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 68635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 68735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 68835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 68935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 69035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 69135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 69235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_CUBE_MAP_ARB; 69335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_RECTANGLE_NV: 69435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 69535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_RECTANGLE_NV; 69635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 69735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 69835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D_ARRAY_EXT; 69935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 70035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 70135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D_ARRAY_EXT; 70235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul default: 70335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul _mesa_problem(NULL, "unexpected target in get_proxy_target()"); 70435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return 0; 70535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul } 70635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul} 70735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 70835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 70935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/** 7103c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 7113c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * texture unit. 7126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 7156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 7186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 72035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 72135d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 7223c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 7233c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 72435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 72535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 726f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array || 727f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 728f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul 72935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7319818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 73235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 733fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 73435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7359818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 73635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 737fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 73835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 7399818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 74035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 741fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 74235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 74335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 74435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 74535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 74635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 74735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7485ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 749a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7509818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 75135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 752a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 753fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7548afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7569818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7578afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7588afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 759fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 760bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 761f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 762bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 763f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 764bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 765f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 766bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 767f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 76835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 76908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 77035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 77135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 77235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 77335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 77435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 776b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 777b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 778b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 779f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 780b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 781b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 782b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 783b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 784b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 785b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 786b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 787c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 788c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 789c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7921eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 796c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 797fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 798fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 7993c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 8003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 8015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 802fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 803c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 8045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 805c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 806c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 807c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 808bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 809c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 810fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 811fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 812fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 813a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 818a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 819f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 820a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 8235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 8255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 828a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 829a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 830a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 838a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 842a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 843a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 847a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 848a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 849f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 85280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 853a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 855a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 856a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 857a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 858a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 859a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 860a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 86280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 863a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 865a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 86780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 868a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 870a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 87280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 873a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 874a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 875a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 87780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 878a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 879a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 880a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 88180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 88280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 883bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 884bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 885bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 88680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 88780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 888bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 889bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 890bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 89180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 89280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 893a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 894a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 895a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 89680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 89780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 89880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 89980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 90080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 90180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 90280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 90380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 90580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 90680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 90780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 909a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 910a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 911a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 9126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 9136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 9146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 9166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 9176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 922ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 923ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 924f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 925ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 928ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 929ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 930ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 931ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 932ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 933ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 934ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 935ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 936ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 937ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 938ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 941add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 942ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 943fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 944fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 945ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 946ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 947fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 948fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 949fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 950fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 951fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 952f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 953f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array) 954fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 955ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 956ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 957ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 958ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 959ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 960ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 96183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9625e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 96383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 964a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 965a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 96683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 96783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 96883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 96983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 97083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 97183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 97283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 97383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 97483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 97583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 97683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 97783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 97883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 97983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 98083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 98183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 98283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9835e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9845e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 98583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 98683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 98783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9885e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9895e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 99083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 99183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 99283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 99383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 99483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 99583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 99683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 99783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 99883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 99983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1000fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 100162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 1002f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 1003afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 1004afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 10058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 1006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 10088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 1009afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 1013afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1014a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 1015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 1017afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 1018afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 1019afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 102165d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1027afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1028afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1029afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10338e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10348e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1043afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1044afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1045afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1046afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1047a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1050afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 105162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1052afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1053afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1054afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1055738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1056f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10609c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10619c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1062f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1063f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1064f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10659c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10669c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1067f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10689c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10699c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1070a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1071a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10729c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10759c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1076681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1077b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 107832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 1079b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1080b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 10819c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10829c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10839c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10849c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10859c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10869c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10879c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10881f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10894f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10904f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10919c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10929c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10939c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1098b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 10996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 11006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 11016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 11026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 11036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 11046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 110583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 11066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1108887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 11096628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 11103893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1111f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 11123893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 11133893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 111483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 111583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 11166628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 111783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint i, dims; 1118b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11196628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11208bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11218bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11228bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1123b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1124a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1125a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1126a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11276628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11286628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11296628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11306628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1131c813b545ab4726fc5030f123ec6255224d64ad82Brian 11324d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 11334d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->WidthLog2 = logbase2(img->Width2); 1134c813b545ab4726fc5030f123ec6255224d64ad82Brian 1135c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1136c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 11376628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1138c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1139c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1140c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 11414d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->HeightLog2 = logbase2(img->Height2); 1142c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1143c813b545ab4726fc5030f123ec6255224d64ad82Brian 1144c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1145c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 11466628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1147c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1148c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1149c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 11504d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->DepthLog2 = logbase2(img->Depth2); 1151c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1152c813b545ab4726fc5030f123ec6255224d64ad82Brian 11536628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1154c813b545ab4726fc5030f123ec6255224d64ad82Brian 1155be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1156be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1157be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1158887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1159887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1160887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1161887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1162b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1163b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1164b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1165b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1166b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1167b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1168a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer if (img->ImageOffsets) 116932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 117032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); 1171b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1172b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1173b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1174b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11758afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11768afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11778afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11788afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11798afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11808afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11818afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11828afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11868afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11871a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul 118883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 118983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1190a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie dims = _mesa_get_texture_dimensions(target); 119183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 119283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_set_fetch_functions(img, dims); 11936628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11946628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11956628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1196738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 119742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 119842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 119942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 120042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 120142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 120242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 120342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 120442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 120542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 12063c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 12073c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 120842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 120942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu ctx->Driver.FreeTexImageData(ctx, texImage); 121042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 121142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 121242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 121342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 121442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1216738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1217738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1218738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1219738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1220738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1221aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1222aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1223aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1224aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1229738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1232738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1234738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1235738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1238738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1239f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1240738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1241738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1242738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1243738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12449c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1245738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1246738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1247738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1248738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1249738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1250738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1251738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1252c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1253738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1254c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1255c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1256c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1258c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1259738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1260738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1262738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1263738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1265c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1267738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1268c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1271c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1272c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1274c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1279738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1280c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1281c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1283738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1284c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 2 * border || depth > 2 + maxSize) 1285c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1286c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1287c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1288c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1289c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1291c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1292c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1294c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1295738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1296738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1297c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1298738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1299c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1300c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1301c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1302c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1303c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1304c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1305738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1306738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1307c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1308738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1309738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1310c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1311c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1313c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1314c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1315738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1316c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1317c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1318c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1319c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1320c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1321738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1322738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1323c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1324bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1325bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1326c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1327bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1328c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1329bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1330c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1331c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1332c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1333c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1334c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1335bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1336bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1337c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1338bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1339bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1340c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1341bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1342c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1343c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1344c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1345bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1346c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1347c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1348c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1349c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1350c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1351c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1352c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1353bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1354bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1355c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1356738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1357738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1358738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1359738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1360738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1361738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1362738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1363738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 13644b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 13654b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 13664b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 13674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 13684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 13694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 13704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 13714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 13724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 13734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 13744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 13754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 13764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 13774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 13784b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13814b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 13827404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 13837404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1384064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1385064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1388064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13897404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 13907404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1391646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1392646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1393646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 13947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1395646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1396646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1397646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1398646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1399646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1400646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1401646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1402646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1403646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1404646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1405f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1406684c66bb8b8cdaa7fc18b64a6f739ad70a10cd54Brian Paul ctx->Extensions.EXT_texture_array); 1407646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1408646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1409646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1410064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1411064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1412064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1413064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1414d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D: 1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.NV_texture_rectangle; 1445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1447f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1448f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1453d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_3D: 1456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1459f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1460f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1463d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1464d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 147211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 147309a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 147409a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 147509a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 147611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 147711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 147809a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 147911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 148011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 148111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 148211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return target == GL_TEXTURE_1D; 148311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 148411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 148511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 148611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 148711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 148811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 148911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 149011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 149111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 149211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 149311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 149411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 149511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.NV_texture_rectangle; 149611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1497f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1498f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 149911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 150011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 150111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 150209a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 150309a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 150409a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 150509a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 150609a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1507f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1508f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 150909a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 151009a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 151109a5e028a6d254f619132e302a96c8535018603dBrian Paul } 151211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 151309a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 151409a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 151511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 151611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 151711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 151811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 151911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 152011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 15216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 15226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 152485288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 15256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 15266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 15276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 15286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 15296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 15306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 15316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 15326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 15336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 15346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15383c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 15393c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1541c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 154285288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 154385288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1544c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1545c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1546c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1547c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 154935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 155035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1551e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1552714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1554738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1555738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1556738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1557738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1558738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 15598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1560738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1561738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1562738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1563738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1564738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1565738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1566738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1567738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1568738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1569738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1570738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1571738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1572738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1573738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1574973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1575f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1576f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1577973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1578f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1579f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1580f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1581f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 158235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 158335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 158435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1585afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1586d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 158735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 158835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 158935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 159035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 159135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1592e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1593e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1594e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1595738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1596c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1598738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1599738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1600c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1601afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1602afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1603afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1604738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 160589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1606c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 16074e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1608a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1609a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1610c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1611afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1612afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1613afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1614738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1615f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1616326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1617326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1618326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1619326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 162038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 162138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1622326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1623326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1624326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 16258a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 16268a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1627c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 162838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1629afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1630afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1631601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 163222e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1633ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul indexFormat = _mesa_is_index_format(format); 163422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1635ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_index_format(internalFormat) && !indexFormat) || 1636ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1637ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1638ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1639ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1640601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1641601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16428a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 16438a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1644601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1645601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1646601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1647601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1648601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1649c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1650601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1651601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1652c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1653fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16542236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1655c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1656c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1657c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1658d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1659d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1660d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1661d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1662d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1663d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1664d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1665d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1666d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1667d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1668d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1669fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16702236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1671fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1672c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1673d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1674d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1675d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1676c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1677c5b995066020191982b2315fc45d05e068eee761Brian Paul 1678601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1679601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 16802b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */ 1681601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1682601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1683601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16842b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 16852b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16862b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1687601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1688601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1689601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1690601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1691601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1692601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1693601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1694601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1695c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 16967404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 16977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 16987404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 16997404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1700064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 170189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 170289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 170389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 170489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17058978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 170689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 170789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 170889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 170989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1711326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1712326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1713326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1714326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1715326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1716326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1717326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1718326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1719326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1720326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1721326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1722326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1725afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1726afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1727afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1729c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 17306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 17326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 17336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 17346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 17356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 17366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 17376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 17386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 17396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 17406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 17416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 17426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 17436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 17456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 17473c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 17483c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1749afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1750c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1751f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1752c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1753c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1754c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1755c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1756afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1757738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1758738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17594e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1760c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1761c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 176345124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1764c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 17654e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1768c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1769c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 17704e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17714e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1772c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1773c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1774c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1775738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1776738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1777c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1781326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1782326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1783326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1784326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1785326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1786326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 17878a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 17888a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 17895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 17905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 17915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 17925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 17935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1794f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1795d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1796d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1797d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1798d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1799d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 18005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1801f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 18025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 18035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 18045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 18055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 18065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 18075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1808c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1809738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1810738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1811c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1812c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1813afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1814c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1815738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1816738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1817c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1818afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1819c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1820738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1821738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1822c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1823c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1824c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1825c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1826738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1827738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1828c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1830c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1831738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1832738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1833c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1834afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1835afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1836c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1837c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 183808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1839c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1840c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 184138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 184208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1843c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1844c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1845afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1846afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1847b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1848d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1849d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1850d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1851d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1852d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1853d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1854d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1855e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18568978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1857d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1858e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1859e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1860d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1861d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1862e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18638978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1864e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 186589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1866d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 186789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18688978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 186989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 187089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1871e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1872e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1873c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1874c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1875afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1876afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1878c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 18886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18923c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 18933c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1894afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1895c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1896f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1897c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1898c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1899afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 190011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 190111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 1902738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 19030899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1904afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 190511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 190609a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 190711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 190811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 190911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 191011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 191111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1912738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1913738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 19145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 19155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 19165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 19175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 19185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 191934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 192034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 1921b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 1922b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 1923b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 192434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 192534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 192634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 192734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 192834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 192934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 193034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1931738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1932738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1933738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1934738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1935738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1936738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1937738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1938738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 19390899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 19400899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19410899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 19420899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19430899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19440899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 194534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 194634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 194734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 194834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 194934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 195034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 195111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 195211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 195311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 1954738318bb75dea8dac4465f53850987f6062a732dBrian Paul 195511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 195611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul internalFormat, format, 195711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 195811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 1959c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1960738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1961738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19624e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1963738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1964c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1965738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1966738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1967738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1968738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1969ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1970c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1971c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1972c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1973c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 19747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 197589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 19762236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 197789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 197889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 197989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 198089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19818978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 198289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 198389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 198489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1985ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depth_format(internalFormat)) { 19860899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19871a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 19880899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19898978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth)", dimensions); 19900899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19910899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19920899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 1993ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depthstencil_format(internalFormat)) { 19940899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19951a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 19960899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19978978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth/stencil buffer)", dimensions); 19980899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19990899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20000899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 200189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2002c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2003c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2004c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2005c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2006c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 200834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 20099dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 20109dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 20116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 20136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 20146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 20156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 20166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 20186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2019c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 2020f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 20219dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 2022c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 202334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 202434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 2025b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 2026b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 2027b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 202834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 202934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 203034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 203134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 203234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 203334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 203434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 20351c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 203609a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 20371c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 20381c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 20391c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 2040c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2041c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2042738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2043738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20444e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2046c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2047c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2048c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 20505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 20515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 20529dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20539dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 20549dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 20559dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 20569dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 20579dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 20589dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 20599dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 20609dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 20615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2062f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 20635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 20645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 20655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 20665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 20675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 20689dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2069c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 20704e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2071b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2072b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20769dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 20779dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 20789dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20799dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 20809dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20819dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20829dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 20839dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20849dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 20859dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20869dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20879dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2089c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 20904e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20914e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2092c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2093c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 209438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 20954e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20964e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2097c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2098c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2099c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2100c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 21014e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2103c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2104c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2105c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 210638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 21074e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21084e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2109c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2110c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2111c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2112c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21139dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2114c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2115c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 21164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21174e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2118c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2119c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 212038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 21214e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21224e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2123c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2124c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2125c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2126c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2127b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 212889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 212989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 213089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21318978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2132e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2133e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 213489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2135798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 213689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21378978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2138e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 213989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2140798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 214189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21428978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 214389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 214489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2145e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2146e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2147a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2148d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2149d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2150d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2151d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2152985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2153985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2154803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2155803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2156985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2157985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2158985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2159a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 21601a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 21610899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21628978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth buffer)", 21630899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21640899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21650899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21660899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2167a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 21681a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 21690899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21708978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth/stencil buffer)", 21710899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21720899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21730899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21740899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21750899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2176326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2177326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2178326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2179412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2180326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2181412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2182326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2183326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2184326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2185326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2186326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2187326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2188326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2189c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2190c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2191c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2192c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2193c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21942897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 21952897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 21962897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2197f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 21982897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 21992897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 22002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 22012897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2203519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 22042897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2205519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2206519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 22072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2208519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 22092897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 22102897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2211f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 22122897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 22132897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 22142897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22152897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 22162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2217519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 22182897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2219519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 22202897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2221519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2222519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2223519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2224519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2225519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]); 2226519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2227ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 22282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 22292897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2230519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2231519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2232519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2233519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2234519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2235519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 22362897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 22372897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 22382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 22392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 22402897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 22412897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 22422897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2243f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 22442897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 22452897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 22462897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 22472897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 22482897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 22492897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 22502897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 22512897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 22522897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 22532897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 22542897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 22552897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 22562897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22572897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22582914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 22592914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 22602914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 22612914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 22622914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 22632914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void 2264f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 22652914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 22662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 22672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2268ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2269ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2270ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 22712914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 22722914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 22732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 22742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 22752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22762914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22771826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 22781826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 22791826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 22801826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 22811826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 22821826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 22831826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 22841826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 22851826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 22861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 22881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 22891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 22901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 22911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 22931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 22941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 22951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 22961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 22981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 22991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23001826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 23011826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23021826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 23031826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 23041826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23051826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 23061826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23071826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 23081826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 23091826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 23101826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23111826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 23121826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 23131826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23141826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23151826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 23161826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23171826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 23181826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 23191826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2320519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2321bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2322bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2323bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2324bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2325bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2326bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2327bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2328bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 232983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2330f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2331bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2332bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2333bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2334bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 233583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 233683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2337bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2338bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2339bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2340bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2341bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2342bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2343bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2344bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2345bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2346bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2347bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 234883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 234983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2350bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2351bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2352bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2353bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 235483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 235583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 235683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2357bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2358bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2359bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2360d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2361d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2362c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2363d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2364d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2365d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2366d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2367d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2368d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2369c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2370d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 2371d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2372cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2373c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2374d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2375d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2376d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2377d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2378d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2379d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2380d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2381d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2382d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2383d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 238411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2385d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2386d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2387d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2388d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2389d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2390d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2391ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2392d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2393d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2394d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 23952914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2396d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 240062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2401d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2402738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2403a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2404a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2405c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 240689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 240789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2408bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2409bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 241283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 241383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2414d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 2417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 24194b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24204b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 24214b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 24224b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 242389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2424c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2425c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 24268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 24280293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24290293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2430f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 24328e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2433c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2434c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24357ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 24365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2437fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2438b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2447ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 244883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 244983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2450ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2451ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2452ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2453ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2454ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 245583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 245683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 245783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 245883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 246311caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 24644b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ASSERT(ctx->Driver.TexImage3D); 2466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 2467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 2468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, border, format, 2470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2472d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 2474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, border, format, 2476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 2480d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2481d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, format, 2482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2484d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2485d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 2486d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in teximage()", dims); 2487d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2488ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24894b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 24902914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 24914b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2492ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24934b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 24944b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 24954b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 24964b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24974b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2498d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24994b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2500ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2501ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 25025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2503afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2504d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2505d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2506d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2507d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2508d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2509d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2510d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2511d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2512d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2513d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2514d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2515d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2516d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2517d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2518d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2519d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2520d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2521d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2522d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2523d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2524d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2525d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2526d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2527d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2528d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2529d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2530afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2531afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2535afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2536afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2537c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2538b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2539fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2540fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2541fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2543fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2544d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2545d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2549c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 255043911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2551663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2552663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2553663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2554663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 255589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2556663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2557663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2558663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2559663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2560d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2561d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2562d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2563d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2564d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2565d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 256617efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 256717efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2568d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25692002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 25702002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 25712002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 25722002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 25732002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 25742002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2575d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2576d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2577d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2578d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2579d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2580d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25817ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 2582d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2583d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2584d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2585d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2586d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2587d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2588d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2589d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2590d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 2591d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (texImage->Data) 2592d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.FreeTexImageData( ctx, texImage ); 2593d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2594d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ASSERT(texImage->Data == NULL); 2595d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2596d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2597d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2598d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2599d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2600d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2601d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2602d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2603d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2604d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2605d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2606d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 260845124e043da5a67e1081526d61b99422f4ccde19Brian Paul 260945124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 261045124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 261145124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 261245124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 261345124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 261445124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 261545124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 261645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2617afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26180293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2619b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 262045124e043da5a67e1081526d61b99422f4ccde19Brian Paul 262175280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 262275280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2623d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 262445124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 262545124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2626d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 262745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 262845124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2629d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2630d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 263145124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 263209a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 263345124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 263445124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 263545124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 263645124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 263745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 26387ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 263908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 26402aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 264145124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 264245124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2643f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2645afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2646b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2651afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 265245124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 265345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 265445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 265545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2656a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 26575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 265845124e043da5a67e1081526d61b99422f4ccde19Brian Paul else if (width > 0 && height > 0 && height > 0) { 265945124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 266045124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 266145124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 266245124e043da5a67e1081526d61b99422f4ccde19Brian Paul zoffset += texImage->Border; 266345124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 266545124e043da5a67e1081526d61b99422f4ccde19Brian Paul yoffset += texImage->Border; 266645124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 266745124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 266845124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 266945124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2670347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 267145124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 267245124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 267345124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, 267445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, width, 267545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 267645124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 267745124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 267945124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, 268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, width, height, 268145124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 268245124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 268345124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 268445124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 268545124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 268645124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 268745124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 268845124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 268945124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 269045124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 269145124e043da5a67e1081526d61b99422f4ccde19Brian Paul default: 269245124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_problem(ctx, "unexpected dims in subteximage()"); 269345124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 26942914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 26952914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 26962914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2697ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2698ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 26995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2701afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2704c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 270545124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 270645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 270745124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 270845124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 270945124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 271045124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 271145124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 271245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 271345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 271445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 271545124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 271645124e043da5a67e1081526d61b99422f4ccde19Brian Paul 271745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 271845124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2719fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2720fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2721fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2722fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2723fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27252c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 272645124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 272745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 272845124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 272945124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2730c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2731afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2732afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2734c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2735fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2736fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2737fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2738fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2739fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27412c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 274245124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 274345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 274445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 274545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2747afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2748afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2749afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 275011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 275111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 275211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 275311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 275411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 275511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 275611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 2757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27582aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 27592aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2760e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 276111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2762cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2764d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 276511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 276611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 2767d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2768d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 276911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2770d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 277163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 277208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2773fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 277411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 277511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 2776ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2777ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2778b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2779a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 27805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 278311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 27845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 278511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2787c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 278883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 278983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2790c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 2791c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2792c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 27937dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 2794c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 27957dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 279683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 279783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 279883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 27992aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 280011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 280111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 28024b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 280311caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 280411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ASSERT(ctx->Driver.CopyTexImage2D); 280511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (dims == 1) 280611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat, 280711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, border); 280811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul else 280911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat, 281011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 28112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 28124b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 28132914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28144b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2815519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 28164b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 28174b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 28184b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 28194b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 28204b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 282111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 28224b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2823c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 28245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2826afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2830c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 283111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 283211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 283311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 283411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 2835afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2836fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 283711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 283811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 2839c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 28402914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2841c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 284211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 284311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 284411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 284511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 284611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 284711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 284811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 284911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2852afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28531c23b860cea93534f726d2a18658444f37f43538Brian Paul 28541c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 28551c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 28561c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 28571c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 28581c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 28591c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 28601c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 2861afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 2863347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 286403bafd1f9fa000abdb794b2ae344a68840c83201Brian 2865cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2866afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2867d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 28681c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 28691c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 2870d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 28711c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 2872d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 287363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 287408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2875fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 28761c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 2877ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2878ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2879b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 28805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 28845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28851c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 28861c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 28871c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 288803bafd1f9fa000abdb794b2ae344a68840c83201Brian } 2889a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 28901c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 28911c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 28921c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 28931c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset += texImage->Border; 28941c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28951c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 28961c23b860cea93534f726d2a18658444f37f43538Brian Paul yoffset += texImage->Border; 28971c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28981c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 28991c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 29001c23b860cea93534f726d2a18658444f37f43538Brian Paul } 290103bafd1f9fa000abdb794b2ae344a68840c83201Brian 2902a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 2903a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 29041c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 29051c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 29061c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 29071c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, x, y, width); 29081c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29091c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 29101c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, 29111c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, 29121c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29131c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29141c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 29151c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 29161c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, zoffset, 29171c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29181c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29191c23b860cea93534f726d2a18658444f37f43538Brian Paul default: 29201c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_problem(ctx, "bad dims in copytexsubimage()"); 29211c23b860cea93534f726d2a18658444f37f43538Brian Paul } 29222914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 29232914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 29242914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2925a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 2926a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 2927a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 29285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2930afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2931afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2932afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29331c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 29341c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 29351c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 29361c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 29371c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 29381c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 29391c23b860cea93534f726d2a18658444f37f43538Brian Paul} 29401c23b860cea93534f726d2a18658444f37f43538Brian Paul 29411c23b860cea93534f726d2a18658444f37f43538Brian Paul 2942afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2943c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2944fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2945fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2946fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2947afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2948fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29491c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 29501c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 2951afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2952afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2953afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2954afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2955c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2956fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2957fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2958fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2959afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2960fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29611c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 29621c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 2963afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 29641207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 296789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 296889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 296989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 297089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 297189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 297289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 297389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 297454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 297554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 297654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 297754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 297854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 297954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 298054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 298154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 298254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 298354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 298454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 298507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 298607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 298707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 298807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 298907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 299007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 299107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 299207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 299307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 299454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 299554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 299654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 299789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 299889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 299989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 300089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3001f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 300289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 300389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 300489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 300589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei imageSize) 300689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 30074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 30084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 30094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 301089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check level */ 30124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (level < 0 || level >= maxLevels) 30134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul return GL_INVALID_VALUE; 301489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30157404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 30167404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 30177404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30187404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 3019c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 3020c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, internalFormat)) 302189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 302289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3023c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3024a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick if (_mesa_base_tex_format(ctx, internalFormat) < 0) 3025a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3026a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 30274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 302889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) 302989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 303089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 303189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 303289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 303389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) 303489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 303589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30367404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 30377404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 30387404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 30397404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul ctx->Driver.ChooseTextureFormat(ctx, internalFormat, 30407404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GL_NONE, GL_NONE); 30417404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 30427404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30437404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 30447404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 30457404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 30467404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 30477404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 30487404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 30497404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 30507404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 30517404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30527404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30537404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30547404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 30564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 30574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE, 30584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border)) { 30597404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 30607404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 306289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 306454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, internalFormat); 30657404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 30667404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 30677404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 30687404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 30697404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 307089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 30717404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 307289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 307389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 307489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 307589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 307689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 307789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 307889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 30792371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 30802371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 30812371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 308289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 308389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 308489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3085f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 308689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 308789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 308889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 308989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 309089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 309189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 309207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3093a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 309489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 309589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 309689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 309789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 309889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 309989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 310089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 310189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 310289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 310389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 310489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 310589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 310689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 310789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 310889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 310989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 311089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 311189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 311289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 311389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 311489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 311589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 311689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 311789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 311889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 311989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 312089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 312189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 312289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 312389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 312489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 312589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 312789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3128c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3129c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 313089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 313189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3132887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 313389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 313489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3135887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 313689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 313789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 313889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 314089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 314189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 314207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 314307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 31442371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 314507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 314607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 314707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 314889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 314989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 315007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 315189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 315289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 315307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 315489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 315589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 315654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 315789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 315889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 315989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 316089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 316189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 316289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 316389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3164f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3165f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3166f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3167f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3168f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3169f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3170f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3171f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3172f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3173f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3174f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3175f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3176f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3177f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3178f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3179f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3180f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3181f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3182ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3183ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3184f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3185f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3186f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3187f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3188f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3189f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3190f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3191ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3192ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3193f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3194f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3195f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3196f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3197f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3198f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3199f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3200f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3201ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3202ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3203f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3204f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3205f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3206f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3207f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3208f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3209f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3210f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3211f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3212f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 32134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 32144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 32154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 32164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 32174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 32184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 32194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 32204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 32214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 32221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 32244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3225cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3226aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3227d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 32284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 32294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 32304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3231d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3232d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 32334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 32345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 32367404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 32374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 32384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3239aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3240aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32411207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 32434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 32444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize); 3245d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 32467179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#if FEATURE_ES 32474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* XXX this is kind of a hack */ 32484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 32494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glTexImage2D"); 32507179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 32517179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 32527179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 32534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (dims == 2) { 32544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 32554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 32564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 32574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 32594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 32604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 32614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 32634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 32644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 32654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 32664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 326789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3268aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 32704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3271aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 32724ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 32734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 32744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 32752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 32768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 32774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 32784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 32794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 32804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 32814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 32824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 32834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 32844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3285aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 32884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 32894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 32904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 32914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 32924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 32934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 32944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 32954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 32964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 32974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 32984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 329989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3300aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3301aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 33028c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3303aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3304aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 33054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 330689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 33074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD", dims); 330889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3309aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3310aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3311b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 33129519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 33145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 33155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 33165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 33174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3320c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 332183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 332283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3323c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3324c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3325c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3326c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3327c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 332883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 332983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 333083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 333183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 33324b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 33334b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 33344b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 33354b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 333611caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 33374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (dims) { 33384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 1: 33394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 33404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 33414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 33434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 2: 33474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 33484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 33494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 33514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 3: 33554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 33564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 33574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, 33594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul default: 33634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_problem(ctx, "bad dims in compressedteximage"); 33644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3365c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 33664b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 33672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 33684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 33694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 33704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 33714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 33724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 33734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3376c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3377c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 33785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3379aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 33819519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33829519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 33844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 33854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 33864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 33874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 33884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 33894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 33904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 33914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 33924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 33934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 33954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 33964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 33974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 33984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 33994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 34034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 34044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 34094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 34114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 34124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 34154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 34161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34196bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 34206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 34216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 34226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 34236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 34246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 34256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 34266bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 34271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34289540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 34299540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 343089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3431a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 343275280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 343375280a2c742ee241d392618a3b29548fce1520a9Brian Paul 34346bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3435c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 34366bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3437c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 343889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 34396bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 344089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 34419540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34429540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3443b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3444c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 34485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 34499540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 34506bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3451f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3452f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3453c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 34556bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 34566bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 34576bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 34586bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 34596bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 34606bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34616bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34626bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34636bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34646bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 34656bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 34666bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 34676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 34686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 34696bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34706bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34726bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34736bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 34746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 34756bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 34766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 34776bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 34786bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34796bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34806bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34816bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34826bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 34836bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3484c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34862914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 34872914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34882914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 34895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 34909540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 34921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34941207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3495c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 34966bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 34976bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 34986bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 34996bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 35006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 35016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 35026bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 35036bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35046bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 35061207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 35071207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 35081207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 35091207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35101207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35116bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 35126bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 35131207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35141207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3516c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 35181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 35191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 35201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 35211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 35236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 35241207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3525