teximage.c revision 0bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2120d71a45cfda1edfa8cd6b1732e209eb98b53d8Brian Paul * Mesa 3-D graphics library 35e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 49f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 135e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 165e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 26add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2877ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 29add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 33b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 34afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 35d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h" 3634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h" 39afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 403c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 41ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 42db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 43fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 451a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h" 46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 487179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 495e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 50afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 524cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 577ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul#define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL) 5863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 624cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 634cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 831749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 841749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 871749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 9189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 9289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 9389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 9473b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 9573b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 96afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 97b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 98f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1001749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 149f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 150f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 151f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 152f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 153f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke if (ctx->Extensions.EXT_texture_format_BGRA8888) { 154f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 155f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke case GL_BGRA_EXT: 156f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 157f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 158f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 159f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 160f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 161f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 162f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 163f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 164f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 165f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 166f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 167f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 168f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 169f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 170f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 171e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 172f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 173f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 174f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 175f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 176f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 1774741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 178f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 179f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 1804741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 1814741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 1824741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 183f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 184f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 18889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 18933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 19033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 19133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 19233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 19333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 19433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 19533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 19633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 19733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 19833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 19933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 20033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 20133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 20233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 20333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 204f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 20989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 21189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 212f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 213f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 214f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 215f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 216f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 217f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2198f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2208f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 221f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 222f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 223f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 22440bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 225f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 226f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 234663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 237663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 24289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2471749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 257f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 260f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 265f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 267f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 2698f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 270f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 271afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 273114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 274114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 275114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 276114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 277114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 278114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 279114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 280114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 281114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 282114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 2830be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák if (ctx->Extensions.EXT_texture_snorm) { 284c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 2850be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RED_SNORM: 2860be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R8_SNORM: 2870be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R16_SNORM: 2880be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RED; 2890be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG_SNORM: 2900be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG8_SNORM: 2910be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG16_SNORM: 2920be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RG; 2930be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB_SNORM: 2940be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB8_SNORM: 2950be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB16_SNORM: 2960be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RGB; 297c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 298c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 2990be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGBA16_SNORM: 300c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 3010be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA_SNORM: 3020be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA8_SNORM: 3030be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA16_SNORM: 3040be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_ALPHA; 3050be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_SNORM: 3060be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_SNORM: 3070be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_SNORM: 3080be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE; 3090be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_ALPHA_SNORM: 3100be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_ALPHA8_SNORM: 3110be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_ALPHA16_SNORM: 3120be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE_ALPHA; 3130be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY_SNORM: 3140be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY8_SNORM: 3150be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY16_SNORM: 3160be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_INTENSITY; 317c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 318c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 319c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 320c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 321114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3221ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3231ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3261ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3271ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3281ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3291ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3301ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3311ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3320a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3330a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3500a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3533488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3540a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3550a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 356abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3570a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3580a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3590a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3600a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 361abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 362abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 402abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 403abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 404abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 405abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 406abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 407abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 4086988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4096988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4106988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 4116988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4133ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4143ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4153ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4163ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4173ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4186988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4193ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4203ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4226988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4236988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4246988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4256988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4266988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4276988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4283ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4293ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4303ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4313ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4376988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4383ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4393ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4413ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4423ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4436988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4443ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4453ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4463ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4476988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4486988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4496988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4506988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4533ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4543ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4553ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4563ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4573ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4583ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4593ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4606988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4896988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4916988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4926988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4946988f65e43297ae63bbce30bf882f870b370096cBrian Paul 495e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4966988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 497e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 498e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 4996988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 500e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 501e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 5026988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 5036988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 5046988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 5056988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 506abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 507abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 5087d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák if (ctx->Extensions.EXT_texture_compression_latc) { 5097d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák switch (internalFormat) { 5107d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 5117d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 5127d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE; 5137d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 5147d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 5157d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE_ALPHA; 5167d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák default: 5177d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák ; /* fallthrough */ 5187d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5197d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5207d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 52169f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák if (ctx->Extensions.ATI_texture_compression_3dc) { 52269f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák switch (internalFormat) { 52369f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 52469f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák return GL_LUMINANCE_ALPHA; 52569f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák default: 52669f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák ; /* fallthrough */ 52769f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 52869f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 52969f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák 530f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 531afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 535e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 536e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 537e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 538e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 539e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 540519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 541519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 542519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 543519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 544519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 545519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 546519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 547519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 548519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 549519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5593893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5603893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5613893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 563fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5649c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5659c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 566fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 567fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5689c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5699c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5709c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5719c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 572a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 573a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 574a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Level = level; 575a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Face = face; 576fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 577fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 578fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 579a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 582a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 583a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 58777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 58877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 589f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 59077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 591a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 59277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 59377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 59477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 59577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 596a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5973e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 5980bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer(). 5993e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6001eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6013e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6023e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 6033e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 6043e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 605f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx, 6064cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 6073e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 608c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 609c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 6103e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 6113e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 6124cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 6133e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 6143e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6153e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 6163e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 6173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6193e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 6206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 6216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6221eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6243e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 625a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 62677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6273c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6283c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 62977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6330bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ASSERT(ctx->Driver.FreeTextureImageBuffer); 6340bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 6355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 6363e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 637b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 63832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage->ImageOffsets); 63932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage); 64077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 64177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 64277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 649aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 65077ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 65177ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 652aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 653874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below, 654874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * except there's no proxy for GL_TEXTURE_BUFFER. 655874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 656874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul assert(NUM_TEXTURE_TARGETS == 8); 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 711120d71a45cfda1edfa8cd6b1732e209eb98b53d8Brian Paul * texture unit. The target should have already been checked for validity. 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. 71835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 71935d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 7203c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 7213c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 72235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 72335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 724f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array || 725f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 726f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul 72735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 72835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7299818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 731fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 73235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7339818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 73435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 735fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 73635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 7379818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 73835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 739fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 74035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 74135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 74235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 74335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 74435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 74535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7465ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 747a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7489818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 74935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 750a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 751fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7538afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7549818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 757fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 758bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 759f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 760bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 761f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 762bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 763f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 764bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 765f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 766874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 767874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return ctx->Extensions.ARB_texture_buffer_object 768874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL; 76935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 77008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 77135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 77235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 77335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 77435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 77535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 777b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 778b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 779b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 780f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 781b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 782b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 783b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 784b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 785b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 786b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 787b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 788c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 789c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 790c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7931eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 797c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 798fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 799fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 8003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 8013c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 8025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 803fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 804c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 8055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 806c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 807c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 808c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 809bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 810c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 811fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 812fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 813fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 818a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 819a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 820f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 8245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 8265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 829a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 830a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 842a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 843a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 847a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 848a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 849a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 850f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 852a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 85380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 855a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 856a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 857a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 858a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 859a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 860a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 861a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 86380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 865a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 866a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 86880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 870a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 871a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 87380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 874a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 875a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 876a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 87880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 879a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 880a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 881a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 88280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 88380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 884bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 885bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 886bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 88780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 88880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 889bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 890bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 891bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 89280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 89380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 894a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 895a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 896a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 89780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 89880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 89980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 90080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 90180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 90280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 90380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 90480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 90680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 90780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 90880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 910a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 911a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 912a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 9136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 9146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 9156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 9176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 9186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 923ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 924ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 925f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 928ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 929ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 930ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 931ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 932ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 933ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 934ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 935ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 936ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 937ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 938ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 941ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 942add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 943ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 944fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 945fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 946ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 947ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 948fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 949fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 950fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 951fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 952fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 953f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 954f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array) 955fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 956874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 957874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 958ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 959ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 960ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 961ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 962ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 963ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 96483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9655e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 96683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 967a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 968a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 96983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 97083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 97183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 97283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 97383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 97483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 97583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 97683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 97783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 97883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 97983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 98083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 98183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 98283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 98383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 98483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 98583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9865e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9875e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 98883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 98983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 99083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9915e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9925e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 99383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 994874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 995874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 99683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 99783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 99883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 99983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 100083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 100183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 100283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1005fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 100662c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 1007f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 1008afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 1009afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 1011afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 10138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 1014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 10158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 10168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 10178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 1018afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1019a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 1020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 1021afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 102665d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1027afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1028afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1029afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1032afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1034afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1035afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1036afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1048afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1049afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1050afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1051afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1052a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10548e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1055afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 105662c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1057afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1058afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1059afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1060738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1061f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10659c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10669c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1067f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1068f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1069f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10709c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10719c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1072f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1075a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1076a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10779c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10789c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10799c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10809c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1081681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1082b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 108332f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 1084b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1085b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 10869c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10879c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10889c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10899c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10909c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10919c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10929c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10931f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10944f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10954f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10969c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10979c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10989c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 11006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 11016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1103b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 11046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 11056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 11066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 11076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 11086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 11096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 111083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 11116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1113887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 11146628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 11153893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1116f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 11173893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 11183893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 111983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 112083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 11216628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 112283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint i, dims; 1123b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11246628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11258bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11268bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11278bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1128b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1129a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1130a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1131a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11326628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11336628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11346628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11356628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1136c813b545ab4726fc5030f123ec6255224d64ad82Brian 11374d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 1138b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->WidthLog2 = _mesa_logbase2(img->Width2); 1139c813b545ab4726fc5030f123ec6255224d64ad82Brian 1140c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1141c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 11426628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1143c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1144c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1145c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1146b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->HeightLog2 = _mesa_logbase2(img->Height2); 1147c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1148c813b545ab4726fc5030f123ec6255224d64ad82Brian 1149c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1150c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 11516628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1152c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1153c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1154c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 1155b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->DepthLog2 = _mesa_logbase2(img->Depth2); 1156c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1157c813b545ab4726fc5030f123ec6255224d64ad82Brian 11586628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1159c813b545ab4726fc5030f123ec6255224d64ad82Brian 1160be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1161be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1162be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1163887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1164887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1165887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1166887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1167b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1168b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1169b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1170b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1171b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1172b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1173a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer if (img->ImageOffsets) 117432f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 117532f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); 1176b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1177b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1178b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1179b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11808afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11818afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11828afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11868afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11878afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11888afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11921a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul 119383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 119483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1195a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie dims = _mesa_get_texture_dimensions(target); 119683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 119783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_set_fetch_functions(img, dims); 11986628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 12006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1201738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 120242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 120342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 120442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 120542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 120642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 120742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 120842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 120942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 121042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 12113c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 12123c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 121342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 12140bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 121542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 121642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 121742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 121842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 121942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1220738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1222738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1226aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1227aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1228aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1229aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1232738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1234738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1235738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1238738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1239738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1240738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1241738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1242738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1243738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1244f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1245738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1246738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1247738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1248738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12499c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1250738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1251738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1252738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1253738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1254738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1255738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1256738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1258738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1259c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1260c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1262c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1263c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1264738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1265738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1267738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1268738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1271c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1274c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1275c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1276c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1278c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1279c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1280738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1281738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1283738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1284738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1285c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1286c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1287c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1288738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1289c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 2 * border || depth > 2 + maxSize) 1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1291c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1292c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1294c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1295c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1296c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1297c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1298c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1299c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1300738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1301738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1302c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1303738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1304c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1305c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1306c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1307c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1308c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1309c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1310738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1311738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1313738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1314738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1315c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1316c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1317c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1318c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1319c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1320738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1321c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1322c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1323c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1324c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1325c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1326738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1327738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1328c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1329bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1330bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1331c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1332bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1333c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1334bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1335c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1336c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1337c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1338c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1339c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1340bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1341bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1342c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1343bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1344bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1345c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1346bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1347c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1348c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1349c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1350bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1351c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1352c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1353c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1354c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1355c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1356c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1357c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1358bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1359bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1360c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1361738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1362738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1363738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1364738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1365738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1366738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1367738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1368738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 13694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 13704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 13714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 13724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 13734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 13744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 13754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 13764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 13774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 13784b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 13794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 13804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 13814b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 13824b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 13834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13844b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13864b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 13877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 13887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1389064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1390064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13917404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13927404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1393064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 13957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1396646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1397646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1398646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 13997404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1400646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1401646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1402646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1403646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1404646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1405646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1406646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1407646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1408646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1409646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1410f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1411684c66bb8b8cdaa7fc18b64a6f739ad70a10cd54Brian Paul ctx->Extensions.EXT_texture_array); 1412646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1413646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1414646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1415064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1416064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1417064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1418064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D: 1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1447d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.NV_texture_rectangle; 1450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1452f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1453f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_3D: 1461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1463d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1464f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1465f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1472d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 147711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 147809a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 147909a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 148009a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 148111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 148211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 148309a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 148411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 148511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 148611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 148711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return target == GL_TEXTURE_1D; 148811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 148911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 149011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 149111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 149211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 149311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 149411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 149511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 149611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 149711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 149811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 149911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 150011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.NV_texture_rectangle; 150111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1502f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1503f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 150411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 150511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 150611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 150709a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 150809a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 150909a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 151009a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 151109a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1512f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1513f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 151409a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 151509a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 151609a5e028a6d254f619132e302a96c8535018603dBrian Paul } 151711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 151809a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 151909a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 152011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 152111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 152211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 152311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 152411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 152511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 15266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 15276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 152985288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 15306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 15316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 15326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 15336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 15346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 15356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 15366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 15376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 15386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 15396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15433c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 15443c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1546c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 154785288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 154885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1549c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1550c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1551c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1552c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 155435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 155535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1556e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1557714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1559738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1560738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1561738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1562738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1563738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 15648afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1565738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1566738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1567738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1568738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1569738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1570738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1571738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1572738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1573738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1574738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1575738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1576738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1577738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1578738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1579973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1580f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1581f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1582973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1583f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1584f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1585f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1586f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 158735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 158835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 158935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1590afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1591d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 159235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 159335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 159435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 159535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 159635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1597e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1598e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1599e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1600738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1601c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 16024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1603738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1604738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1605c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1606afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1608afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1609738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 161089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1611c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 16124e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1613a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1614a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1615c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1617afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1618afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1619738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1620f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1621326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1622326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1623326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1624326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 162538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 162638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1627326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1628326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1629326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 16308a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 16318a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1632c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 163338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1634afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1635afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1636601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 163722e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1638ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul indexFormat = _mesa_is_index_format(format); 163922e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1640ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_index_format(internalFormat) && !indexFormat) || 1641ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1642ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1643ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1644ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1645601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1646601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16478a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 16488a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1649601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1650601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1651601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1652601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1653601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1654c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1655601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1656601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1657c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1658fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16592236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1660c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1661c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1662c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1663d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1664d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1665d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1666d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1667d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1668d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1669d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1670d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1671d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1672d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1673d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1674fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16752236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1676fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1677c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1678d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1679d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1680d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1681c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1682c5b995066020191982b2315fc45d05e068eee761Brian Paul 1683601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1684601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 1685753660780a84187043d0dc4b0e0f449786862182Brian Paul /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */ 1686601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1687601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1688601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16892b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 1690753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_1D_ARRAY && 1691753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_1D_ARRAY && 1692753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_2D_ARRAY && 1693753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_2D_ARRAY && 16942b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16952b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1696601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1697601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1698601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1699601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1700601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1701601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1702601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1703601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1704c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 17057404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 17067404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 17077404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 17087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1709064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 171089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 171289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 171389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17148978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 171589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 171789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1720326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1721326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1722326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1723326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1724326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1725326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1726326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1727326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1728326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1729326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1730326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1731326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1732afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1734afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1735afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1738c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 17396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 17416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 17426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 17436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 17446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 17456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 17466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 17476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 17486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 17496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 17506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 17516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 17526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 17546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 17563c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 17573c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1759c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1760f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1761c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1762c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1763c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1764c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1765afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1766738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1767738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17684e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1769c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1770c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 177245124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1773c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 17744e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17754e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1776c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1777c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 17794e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17804e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1781c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1782c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1783c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1784738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1785738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1787c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1790326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1791326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1792326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1793326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1794326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1795326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 17968a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 17978a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 17985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 17995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 18015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 18025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1803f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1804d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1805d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1806d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1807d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1808d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 18095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1810f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 18115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 18125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 18135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 18145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 18155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 18165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1817c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1818738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1819738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1821c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1823c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1824738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1825738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1826c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1828c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1829738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1830738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1831c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1832c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1833c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1834c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1835738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1836738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1837c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1838afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1839c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1840738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1841738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1842c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1845c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1846c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 184708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1849c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 185038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 185108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1852c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1853c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1854afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1855afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1856b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1857d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1858d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1859d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1860d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1861d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1862d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1863d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1864e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18658978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1866d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1867e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1868e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1869d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1870d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1871e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18728978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1873e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 187489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1875d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 187689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18778978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 187889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 187989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1880e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1881e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1882c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1883c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1884afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1885afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1887c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 18976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 19013c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 19023c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1904c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1905f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1906c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1907c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1908afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 190911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 191011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 1911738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 19120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1913afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 191411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 191509a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 191611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 191711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 191811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 191911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 192011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1921738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1922738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 19235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 19245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 19255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 19265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 19275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 192834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 192934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 1930b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 1931b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 1932b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 193334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 193434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 193534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 193634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 193734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 193834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 193934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1940738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1941738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1942738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1943738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1944738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1945738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1946738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1947738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 19480899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 19490899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19500899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 19510899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19520899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19530899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 195434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 195534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 195634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 195734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 195834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 195934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 196011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 196111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 196211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 1963738318bb75dea8dac4465f53850987f6062a732dBrian Paul 196411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 196511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul internalFormat, format, 196611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 196711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 1968c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1969738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1970738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19714e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1972738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1973c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1974738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1975738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1976738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1977738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1978ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1979c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1980c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1981c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1982c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 19837404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 198489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 19852236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 198689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 198789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 198889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 198989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19908978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 199189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 199289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 199389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1994ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depth_format(internalFormat)) { 19950899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19961a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 19970899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19988978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth)", dimensions); 19990899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20000899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20010899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2002ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depthstencil_format(internalFormat)) { 20030899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 20041a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 20050899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20068978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth/stencil buffer)", dimensions); 20070899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20080899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20090899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 201089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2011c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2012c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2013c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2014c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2015c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 201734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 20189dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 20199dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 20206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 20226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 20236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 20246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 20256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 20276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2028c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 2029f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 20309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 2031c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 203234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 203334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 2034b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 2035b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 2036b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 203734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 203834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 203934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 204034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 204134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 204234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 204334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 20441c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 204509a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 20461c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 20471c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 20481c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 2049c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2050c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2051738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2052738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20534e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20544e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2055c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2056c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2057c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 20595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 20605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 20619dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20629dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 20639dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 20649dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 20659dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 20669dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 20679dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 20689dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 20699dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 20705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2071f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 20725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 20735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 20745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 20755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 20765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 20779dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2078c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 20794e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2080b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2081b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2082c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2083c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2084c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20859dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 20869dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 20879dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 20899dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20909dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20919dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 20929dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20939dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 20949dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20959dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20969dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20979dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2098c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 20994e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21004e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2101c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2102c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 210338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 21044e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21054e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2106c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2107c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2108c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2109c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 21104e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21114e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2112c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2113c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2114c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 211538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 21164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21174e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2118c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2119c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2120c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2121c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21229dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2123c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2124c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 21254e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21264e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2127c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2128c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 212938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 21304e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21314e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2132c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2133c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2134c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2135c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2136b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 213789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 213889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 213989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21408978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2141e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2142e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 214389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2144798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 214589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21468978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2147e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 214889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2149798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 215089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21518978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 215289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 215389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2154e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2155e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2156a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2157d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2158d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2159d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2160d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2161985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2162985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2163803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2164803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2165985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2166985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2167985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2168a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 21691a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 21700899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21718978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth buffer)", 21720899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21730899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21740899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21750899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2176a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 21771a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 21780899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21798978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth/stencil buffer)", 21800899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21810899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21820899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21830899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21840899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2185326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2186326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2187326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2188412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2189326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2190412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2191326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2192326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2193326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2194326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2195326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2196326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2197326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2198c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2199c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2200c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2201c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2202c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22032897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 22042897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 22052897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2206f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 22072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 22082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 22092897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 22102897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2212519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 22132897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2214519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2215519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 22162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2217519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 22182897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 22192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2220f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 22212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 22222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 22232897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22242897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 22252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2226519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 22272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2228519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 22292897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2230519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2231519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2232519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2233519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2234db0f9e701d59dcfcd3b50f4d245897692f27fec9Brian Paul ASSERT(_mesa_get_attachment_teximage(att)); 2235519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2236ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 22372897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 22382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2239519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2240519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2241519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2242519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2243519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2244519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 22452897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 22462897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 22472897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 22482897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 22492897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 22502897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 22512897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2252f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 22532897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 22542897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 22552897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 22562897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 22572897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 22582897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 22592897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 22602897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 22612897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 22622897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 22632897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 22642897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 22652897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22662897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 22682914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 22692914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 22702914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 22712914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 22722914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void 2273f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 22742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 22752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 22762914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2277ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2278ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2279ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 22802914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 22812914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 22822914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 22832914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 22842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 22871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 22881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 22891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 22901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 22911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 22921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 22931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 22941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 22951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 22971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 22981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 22991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 23001826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23011826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 23021826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 23031826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23041826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 23051826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23061826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 23071826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 23081826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23091826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 23101826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23111826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 23121826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 23131826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23141826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 23151826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23161826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 23171826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 23181826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 23191826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23201826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 23211826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 23221826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23231826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23241826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 23251826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23261826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 23271826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 23281826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2329519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2330bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2331bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2332bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2333bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2334bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2335bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2336bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2337bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 233883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2339f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2340bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2341bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2342bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2343bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 234483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 234583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2346bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2347bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2348bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2349bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2350bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2351bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2352bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2353bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2354bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2355bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2356bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 235783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 235883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2359bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2360bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2361bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2362bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 236383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 236483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 236583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2366bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2367bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2368bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2369d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2370d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2371c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2372d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2373d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2374d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2375d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2376d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2377d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2378c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2379d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 2380d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2381cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2382c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2383d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2384d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2385d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2386d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2387d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2388d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2389d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2390d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2391d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2392d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 239311caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2394d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2395d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2396d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2400ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2401d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2402d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2403d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 24042914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2405d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2406d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2407d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2408d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 240962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2411738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2412a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2413a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2414c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 241589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 241689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2417bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2418bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 242183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 242283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 2426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 24284b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24294b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 24304b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 24314b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 243289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2433c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2434c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 24358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 24370293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24380293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2439f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 24418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2442c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2443c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24447ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 24455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2446fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2447b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2456ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 245783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 245883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2459ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 24600bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 2461ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2462ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2463ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 246483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 246583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 246683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 246783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 247211caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 24734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ASSERT(ctx->Driver.TexImage3D); 2475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 2476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 2477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, border, format, 2479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2480d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2481d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 2483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2484d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, border, format, 2485d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2486d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2487d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2488d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 2489d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2490d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, format, 2491d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2492d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2493d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2494d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 2495d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in teximage()", dims); 2496d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2497ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24984b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 24992914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 25004b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2501ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 25024b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 25034b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 25044b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 25054b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 25064b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2507d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 25084b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2509ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2510ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 25115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2513d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2514d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2515d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2516d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2517d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2518d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2519d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2520d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2521d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2522d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2523d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2524d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2525d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2526d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2527d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2528d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2529d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2530d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2531d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2532d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2533d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2534d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2535d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2536d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2537d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2538d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2539afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2541afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2543afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2546c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2547b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2548fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2549fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2550fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2551afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2552fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2553d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2554d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2555afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2558c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 255943911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2560663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2561663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2562663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2563663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 256489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2565663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2566663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2567663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2568663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2569d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2570d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2571d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2572d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2573d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2574d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 257517efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 257617efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2577d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25782002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 25792002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 25802002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 25812002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 25822002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 25832002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2584d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2585d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2586d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2587d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2588d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2589d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25907ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 2591d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2592d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2593d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2594d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2595d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2596d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2597d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2598d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2599d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 2600d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (texImage->Data) 26010bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 2602d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2603d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ASSERT(texImage->Data == NULL); 2604d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2605d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2606d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2607d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2608d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2609d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2610d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2611d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2612d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2613d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2614d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2615d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 261745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 261845124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 261945124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 262045124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 262145124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 262245124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 262345124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 262445124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 262545124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2626afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26270293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2628b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 262945124e043da5a67e1081526d61b99422f4ccde19Brian Paul 263075280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 263175280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2632d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 263345124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 263445124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2635d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 263645124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 263745124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2638d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2639d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 264045124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 264109a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 264245124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 264345124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 264445124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 264545124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 264645124e043da5a67e1081526d61b99422f4ccde19Brian Paul 26477ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 264808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 26492aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 265045124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 265145124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2652f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2655b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266145124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 266245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 266345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2665a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 26665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26674609e80288bacf19af99b0ed7656eef9bb280912Brian Paul else if (width > 0 && height > 0 && depth > 0) { 266845124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 266945124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 267045124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 267145124e043da5a67e1081526d61b99422f4ccde19Brian Paul zoffset += texImage->Border; 267245124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 267345124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 267445124e043da5a67e1081526d61b99422f4ccde19Brian Paul yoffset += texImage->Border; 267545124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 267645124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 267745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2679347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 268145124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 268245124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, 268345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, width, 268445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 268545124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 268645124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 268745124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 268845124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, 268945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, width, height, 269045124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 269145124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 269245124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 269345124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 269445124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 269545124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 269645124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 269745124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 269845124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 269945124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 270045124e043da5a67e1081526d61b99422f4ccde19Brian Paul default: 270145124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_problem(ctx, "unexpected dims in subteximage()"); 270245124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 27032914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 27042914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 27052914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2706ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2707ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 27085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2710afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2711afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2712afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2713c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 271445124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 271545124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 271645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 271745124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 271845124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 271945124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 272045124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 272145124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 272245124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 272345124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 272445124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 272545124e043da5a67e1081526d61b99422f4ccde19Brian Paul 272645124e043da5a67e1081526d61b99422f4ccde19Brian Paul 272745124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2728fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2729fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2730fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2731fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2732fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27342c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 273545124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 273645124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 273745124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 273845124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2739c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2742afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2743c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2744fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2745fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2746fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2747fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2748fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2749afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27502c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 275145124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 275245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 275345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 275445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2756afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 275911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 276011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 276111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 276211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 276311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 276411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 276511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 2766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27672aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 27682aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2769e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 277011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2771cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2773d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 277411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 277511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 2776d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2777d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 277811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2779d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 278063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 278108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2782fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 278311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 278411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 2785ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2786ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2787b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2788a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 27895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 279211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 27935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 279411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2796c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 27975874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* choose actual hw format */ 27985874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 27995874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul target, level, 28005874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul internalFormat, 28015874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GL_NONE, GL_NONE); 28027dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 28035874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 28045874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GLint srcX = x, srcY = y, dstX = 0, dstY = 0; 28057dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 28065874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Free old texture image */ 28070bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 28082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 280911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 28104b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 281111caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 28125874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Allocate texture memory (no pixel data yet) */ 28135874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) { 28145874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 28155874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, border, GL_NONE, GL_NONE, NULL, 28165874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &ctx->Unpack, texObj, texImage); 28175874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28185874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else { 28195874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 28205874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, height, border, GL_NONE, GL_NONE, 28215874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul NULL, &ctx->Unpack, texObj, texImage); 28225874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28235874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 28245874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (_mesa_clip_copytexsubimage(ctx, &dstX, &dstY, &srcX, &srcY, 28255874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &width, &height)) { 28265874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) 28275874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, dstX, 28285874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width); 28295874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 28305874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else 28315874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, dstX, dstY, 28325874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width, height); 28335874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28342aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 28354b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 28362914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28374b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2838519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 28394b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 28404b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 28414b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 28424b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 28434b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 28445874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* probably too large of image */ 284511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 28464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2847c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 28485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2852afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2853afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2854c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 285511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 285611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 285711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 285811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 2859afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2860fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 286111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 286211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 2863c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 28642914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2865c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 286611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 286711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 286811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 286911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 287011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 287111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 287211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 287311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2874afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2875afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2876afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28771c23b860cea93534f726d2a18658444f37f43538Brian Paul 28781c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 28791c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 28801c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 28811c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 28821c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 28831c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 28841c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 2885afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 2887347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 288803bafd1f9fa000abdb794b2ae344a68840c83201Brian 2889cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2890afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2891d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 28921c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 28931c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 2894d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 28951c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 2896d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 289763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 289808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2899fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 29001c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 2901ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2902ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2903b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 29045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 29085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29091c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 29101c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 29111c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 291203bafd1f9fa000abdb794b2ae344a68840c83201Brian } 2913a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 29141c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 29151c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 29161c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 29171c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset += texImage->Border; 29181c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 29191c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 29201c23b860cea93534f726d2a18658444f37f43538Brian Paul yoffset += texImage->Border; 29211c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 29221c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 29231c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 29241c23b860cea93534f726d2a18658444f37f43538Brian Paul } 292503bafd1f9fa000abdb794b2ae344a68840c83201Brian 2926a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 2927a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 29281c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 29291c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 29301c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 29311c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, x, y, width); 29321c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29331c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 29341c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, 29351c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, 29361c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29371c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29381c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 29391c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 29401c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, zoffset, 29411c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29421c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29431c23b860cea93534f726d2a18658444f37f43538Brian Paul default: 29441c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_problem(ctx, "bad dims in copytexsubimage()"); 29451c23b860cea93534f726d2a18658444f37f43538Brian Paul } 29462914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 29472914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 29482914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2949a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 2950a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 2951a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 29525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2954afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2955afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2956afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29571c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 29581c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 29591c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 29601c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 29611c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 29621c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 29631c23b860cea93534f726d2a18658444f37f43538Brian Paul} 29641c23b860cea93534f726d2a18658444f37f43538Brian Paul 29651c23b860cea93534f726d2a18658444f37f43538Brian Paul 2966afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2967c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2968fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2969fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2970fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2971afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2972fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29731c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 29741c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 2975afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2977afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2978afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2979c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2980fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2981fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2982fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2984fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29851c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 29861c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 2987afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 29881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29891207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29901207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 299189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 299289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 299389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 299489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 299589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 299689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 299789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 299854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 299954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 300054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 300154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 300254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 300354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 300454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 300554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 300654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 300754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 300854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 300907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 301007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 301107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 301207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 301307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 301407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 301507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 301607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 301707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 301854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 301954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 302054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 302189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 3022d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch * \param reason returns reason for error, if any 302389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 302489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 302589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3026f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 302789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 302889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 302989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 3030d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch GLsizei imageSize, char **reason) 303189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 30324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 30334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 30344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 303589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3036d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = ""; /* no error */ 3037d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch 30384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check level */ 3039d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (level < 0 || level >= maxLevels) { 3040d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "level"; 30414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul return GL_INVALID_VALUE; 3042d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 304389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30447404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 3045d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "target"; 30467404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 30477404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30487404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 3049c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 3050d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (!_mesa_is_compressed_format(ctx, internalFormat)) { 3051d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 305289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 3053d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 305489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3055c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3056d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 3057d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 3058a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3059d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 3060a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 30614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 3062d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (border != 0) { 3063d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "border != 0"; 306489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3065d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 306689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 306789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 306889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 3069d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) { 3070d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "width != height"; 307189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3072d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 307389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 30757404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 30767404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 30777404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul ctx->Driver.ChooseTextureFormat(ctx, internalFormat, 30787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GL_NONE, GL_NONE); 30797404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 30807404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30817404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 30827404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 30837404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 30847404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 30857404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 30867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 30877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 30887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3089d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width or height for compression format"; 30907404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30917404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30927404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30937404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 30954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 30964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE, 30974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border)) { 30987404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 3099d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width, height or format"; 31007404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 31014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 310289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 31034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 310454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, internalFormat); 31057404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 31067404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 31077404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 31087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 31097404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3110d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "imageSize inconsistant with width/height/format"; 311189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 31127404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 311389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 311589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 311689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 311989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 31202371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 31212371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 31222371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 312389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 312489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 312589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3126f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 312789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 312889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 312989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 313089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 313189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 313289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 313307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3134a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 313589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 313789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 313889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 313989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 314189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 314289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 314389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 314589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 314689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 314889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 314989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 315189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 315389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 315489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 315589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 315789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 315989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 316089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 316389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 316489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 316589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 316789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 316889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3169c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3170c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 317189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 317289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3173887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 317489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3176887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 317789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 317889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 318089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 318189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 318289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 318307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 318407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 31852371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 318607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 318707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 318807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 318989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 319289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 319589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 319889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 319989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 320089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 320289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 320389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3205f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3206f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3207f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3208f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3209f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3210f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3211f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3212f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3213f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3214f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3215f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3216f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3217f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3218f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3219f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3220f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3221f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3222f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3223ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3224ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3225f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3226f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3227f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3228f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3229f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3230f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3231f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3232ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3233ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3234f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3235f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3236f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3237f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3238f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3239f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3240f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3241f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3242ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3243ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3244f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3245f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3246f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3247f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3248f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3249f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3250f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3251f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3252f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3253f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 32544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 32554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 32564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 32574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 32594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 32604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 32614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 32631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 3265d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch char *reason = ""; 32664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3267cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3268aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3269d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 32704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 32714ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 32724ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3273d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3274d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 32754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 32765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 32787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 32794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 32804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3281aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3282aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32831207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 32854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 3286d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch border, imageSize, &reason); 3287d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 32884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 3289ca7510bbf9bdff35f813f970e3120a9c7f728ccaBrian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD(%s)", dims, reason); 32907179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 32917179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 32927179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 3293af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul#if FEATURE_ES 3294af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul /* XXX this is kind of a hack */ 32954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (dims == 2) { 32964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 32974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 32984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 32994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 33004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 33014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 33024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 33034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 33044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 33054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 33064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 33074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 33084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 330989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3310aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3313aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 33144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 33154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 33164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 33172914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 33188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 33194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 33204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 33214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 33224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 33234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 33244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 33254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 33264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3327aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 33294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 33304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 33314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 33324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 33334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 33344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 33364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 33374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 33384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 33394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 33404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 334189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3342aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3343aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 33448c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3345aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3346aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 33474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 334889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 33494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD", dims); 335089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3351aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3352aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3353b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 33549519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 33565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 33575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 33585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 33594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3362c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 336383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 336483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3365c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 33660bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 3367c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3368c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3369c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 337083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 337183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 337283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 337383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 33744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 33754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 33764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 33774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 337811caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 33794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (dims) { 33804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 1: 33814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 33824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 33834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 33854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 2: 33894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 33904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 33914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 33934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 3: 33974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 33984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 33994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 34004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, 34014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 34024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 34034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 34044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul default: 34054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_problem(ctx, "bad dims in compressedteximage"); 34064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3407c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34084b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 34092914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34104b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 34114b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 34124b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 34134b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 34144b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 34154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 34164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 34174b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3418c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3419c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3421aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 34224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34239519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34249519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 34274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 34294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 34334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 34344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 34394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 34414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 34454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 34464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 34514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 34534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 34544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 34574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 34581207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34601207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34616bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 34626bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 34636bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 34646bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 34656bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 34666bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 34676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 34686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 34691207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34709540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 34719540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 347289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3473a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 347475280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 347575280a2c742ee241d392618a3b29548fce1520a9Brian Paul 34766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3477c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 34786bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3479c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 348089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 34816bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 348289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 34839540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3485b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3486c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 34905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 34919540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 34926bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3493f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3494f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3495c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34966bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 34976bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 34986bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 34996bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 35006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 35016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 35026bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35036bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35046bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35066bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 35076bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 35086bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 35096bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 35106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 35116bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35126bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35136bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35146bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35156bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 35166bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 35176bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 35186bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 35196bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 35206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 35256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3526c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 35272914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35282914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 35292914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 35315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 35335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 35341207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35351207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35361207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3537c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35386bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 35396bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 35406bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 35416bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 35426bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 35436bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 35446bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 35456bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35466bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35476bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 35481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 35491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 35501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 35511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35536bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 35546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 35551207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35561207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35571207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3558c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 35601207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 35611207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 35621207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 35631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35646bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 35656bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 35661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3567874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3568874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3569874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** 3570874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * Helper for glTexBuffer(). Check if internalFormat is legal. If so, 3571874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * return the basic data type and number of components for the format. 3572874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise 3573874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 3574874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulstatic GLboolean 3575874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulget_sized_format_info(const struct gl_context *ctx, GLenum internalFormat, 3576874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum *datatype, GLuint *components) 3577874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3578874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul switch (internalFormat) { 3579874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8: 3580874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3581874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3582874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3583874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16: 3584874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3585874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3586874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3587874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16F_ARB: 3588874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3589874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3590874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3591874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32F_ARB: 3592874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3593874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3594874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3595874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8I_EXT: 3596874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3597874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3598874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3599874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16I_EXT: 3600874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3601874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3602874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3603874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32I_EXT: 3604874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3605874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3606874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3607874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8UI_EXT: 3608874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3609874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3610874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3611874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16UI_EXT: 3612874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3613874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3614874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3615874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32UI_EXT: 3616874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3617874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3618874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3619874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8: 3620874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3621874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3622874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3623874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16: 3624874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3625874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3626874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3627874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16F_ARB: 3628874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3629874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3630874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3631874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32F_ARB: 3632874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3633874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3634874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3635874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8I_EXT: 3636874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3637874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3638874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3639874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16I_EXT: 3640874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3641874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3642874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3643874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32I_EXT: 3644874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3645874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3646874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3647874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8UI_EXT: 3648874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3649874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3650874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3651874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16UI_EXT: 3652874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3653874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3654874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3655874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32UI_EXT: 3656874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3657874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3658874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3659874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8_ALPHA8: 3660874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3661874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3662874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3663874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16_ALPHA16: 3664874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3665874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3666874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3667874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 3668874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3669874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3670874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3671874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 3672874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3673874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3674874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3675874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 3676874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3677874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3678874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3679874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 3680874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3681874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3682874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3683874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 3684874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3685874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3686874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3687874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 3688874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3689874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3690874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3691874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 3692874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3693874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3694874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3695874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 3696874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3697874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3698874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3699874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8: 3700874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3701874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3702874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3703874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16: 3704874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3705874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3706874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3707874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16F_ARB: 3708874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3709874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3710874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3711874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32F_ARB: 3712874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3713874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3714874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3715874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8I_EXT: 3716874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3717874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3718874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3719874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16I_EXT: 3720874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3721874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3722874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3723874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32I_EXT: 3724874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3725874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3726874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3727874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8UI_EXT: 3728874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3729874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3730874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3731874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16UI_EXT: 3732874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3733874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3734874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3735874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32UI_EXT: 3736874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3737874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3738874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3739874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8: 3740874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3741874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3742874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3743874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16: 3744874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3745874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3746874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3747874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16F_ARB: 3748874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3749874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3750874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3751874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32F_ARB: 3752874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3753874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3754874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3755874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8I_EXT: 3756874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3757874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3758874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3759874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16I_EXT: 3760874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3761874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3762874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3763874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32I_EXT: 3764874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3765874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3766874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3767874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8UI_EXT: 3768874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3769874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3770874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3771874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16UI_EXT: 3772874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3773874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3774874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3775874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32UI_EXT: 3776874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3777874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3778874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3779874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul default: 3780874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3781874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3782874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3783874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float) 3784874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3785874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3786874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel) 3787874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3788874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3789874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_TRUE; 3790874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3791874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3792874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3793874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** GL_ARB_texture_buffer_object */ 3794874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulvoid GLAPIENTRY 3795874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) 3796874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3797874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_texture_object *texObj; 3798874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_buffer_object *bufObj; 3799874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum dataType; 3800874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLuint comps; 3801874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3802874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GET_CURRENT_CONTEXT(ctx); 3803874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3804874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3805874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!ctx->Extensions.ARB_texture_buffer_object) { 3806874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer"); 3807874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3808874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3809874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3810874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (target != GL_TEXTURE_BUFFER_ARB) { 3811874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)"); 3812874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3813874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3814874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3815874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!get_sized_format_info(ctx, internalFormat, &dataType, &comps)) { 3816874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)", 3817874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul internalFormat); 3818874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3819874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3820874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3821874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul bufObj = _mesa_lookup_bufferobj(ctx, buffer); 3822874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (buffer && !bufObj) { 3823874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer); 3824874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3825874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3826874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3827874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3828874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3829874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_lock_texture(ctx, texObj); 3830874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul { 3831874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj); 3832874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj->BufferObjectFormat = internalFormat; 3833874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3834874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_unlock_texture(ctx, texObj); 3835874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3836