teximage.c revision 5874890c26f434f54e9218b83fae4eb8175c24e9
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian * mesa 3-D graphics library 325be043940b25a5fe6eb8058070b3e8f12e92039Brian Paul * Version: 7.6 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 59f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 33fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 34b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 36d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h" 3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 3834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h" 40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 413c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 42ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 43db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 44fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 461a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 48afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 497179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 505e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 534cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 587ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul#define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL) 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 634cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE 644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere. 654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid * 674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes) 684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul return _mesa_align_malloc(bytes, 512); 704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory() 754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */ 764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid 774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m) 784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{ 794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_align_free(m); 804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul} 814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 824cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul 836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 841749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 851749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 881749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 9289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 9389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 9489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 9573b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 9673b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 97afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 98b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 99f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1011749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 150f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 151f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 152f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 153f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 154f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke if (ctx->Extensions.EXT_texture_format_BGRA8888) { 155f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 156f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke case GL_BGRA_EXT: 157f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 158f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 159f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 160f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 161f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 162f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 163f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_paletted_texture) { 164f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 165f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX: 166f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX1_EXT: 167f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX2_EXT: 168f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX4_EXT: 169f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX8_EXT: 170f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX12_EXT: 171f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COLOR_INDEX16_EXT: 172e71654961868eac559210ced359c1af114138d8aBrian Paul return GL_COLOR_INDEX; 173f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 174f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 175f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 176f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 177f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 1784741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 179f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 180f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 1814741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 1824741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 1834741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 184f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 188f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 18989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 19033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 19133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 19233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 19333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 19433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 19533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 19633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 19733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 19833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 19933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 20033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 20133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 20233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 20333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 20433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 21089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 211f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 21289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 213f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 214f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 215f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 216f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 217f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 219f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 2208f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2218f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 222f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 223f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 224f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 22540bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 226f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 234f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 235663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 238663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 242f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 24389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2481749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 257f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 260f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 265f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 267f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 269f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 2708f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 271f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 272afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 274114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 275114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 276114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 277114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 278114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 279114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 280114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 281114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 282114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 283114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 2840be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák if (ctx->Extensions.EXT_texture_snorm) { 285c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 2860be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RED_SNORM: 2870be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R8_SNORM: 2880be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R16_SNORM: 2890be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RED; 2900be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG_SNORM: 2910be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG8_SNORM: 2920be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG16_SNORM: 2930be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RG; 2940be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB_SNORM: 2950be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB8_SNORM: 2960be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB16_SNORM: 2970be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RGB; 298c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 299c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 3000be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGBA16_SNORM: 301c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 3020be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA_SNORM: 3030be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA8_SNORM: 3040be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA16_SNORM: 3050be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_ALPHA; 3060be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_SNORM: 3070be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_SNORM: 3080be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_SNORM: 3090be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE; 3100be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_ALPHA_SNORM: 3110be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_ALPHA8_SNORM: 3120be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_ALPHA16_SNORM: 3130be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE_ALPHA; 3140be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY_SNORM: 3150be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY8_SNORM: 3160be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY16_SNORM: 3170be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_INTENSITY; 318c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 319c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 320c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 321c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 322114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3231ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3261ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3271ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3281ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3291ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3301ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3311ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3321ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3330a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3500a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3530a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3543488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3550a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3560a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 357abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3580a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3590a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3600a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3610a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 362abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 402abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 403abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 404abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 405abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 406abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 407abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 408abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 4096988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4106988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4116988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4136988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4143ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4153ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4163ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4173ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4183ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4196988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4203ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4236988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4246988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4256988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4266988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4276988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4286988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4293ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4303ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4313ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4373ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4386988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4393ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4413ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4423ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4433ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4446988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4453ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4463ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4473ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4486988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4496988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4506988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4536988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4543ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4553ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4563ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4573ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4583ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4593ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4603ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4896988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4916988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4926988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4946988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4956988f65e43297ae63bbce30bf882f870b370096cBrian Paul 496e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4976988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 498e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 499e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 5006988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 501e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 502e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 5036988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 5046988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 5056988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 5066988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 507abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 508abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 5097d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák if (ctx->Extensions.EXT_texture_compression_latc) { 5107d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák switch (internalFormat) { 5117d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 5127d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 5137d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE; 5147d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 5157d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 5167d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE_ALPHA; 5177d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák default: 5187d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák ; /* fallthrough */ 5197d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5207d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5217d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 52269f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák if (ctx->Extensions.ATI_texture_compression_3dc) { 52369f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák switch (internalFormat) { 52469f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 52569f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák return GL_LUMINANCE_ALPHA; 52669f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák default: 52769f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák ; /* fallthrough */ 52869f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 52969f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 53069f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák 531f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 536e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 537e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 538e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 539e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 540e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 541519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 542519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 543519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 544519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 545519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 546519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 547519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 548519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 549519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 550519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5538e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 5596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps. 561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5623893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5633893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5653893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 566fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5679c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5689c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 569fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 570fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5719c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5729c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5739c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5749c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 575a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 576a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 577fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 578fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 579fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 580a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 583a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 584a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 58877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 58977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 590f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 59177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 592a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 59377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 59477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 59577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 59677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 597a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5983e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data. 5994cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData(). 6003e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6011eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6023e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * 6033e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data. 6043e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */ 6053e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid 606f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx, 6074cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul struct gl_texture_image *texImage) 6083e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{ 609c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul (void) ctx; 610c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul 6113e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell if (texImage->Data && !texImage->IsClientData) { 6123e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell /* free the old texture data */ 6134cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul _mesa_free_texmemory(texImage->Data); 6143e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell } 6153e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6163e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell texImage->Data = NULL; 6173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell} 6183e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6193e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell 6203e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/** 6216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image. 6226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6231eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6253e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 626a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 62777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6283c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6293c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 63077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ASSERT(ctx->Driver.FreeTexImageData); 6355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell ctx->Driver.FreeTexImageData( ctx, texImage ); 6365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 6373e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell ASSERT(texImage->Data == NULL); 638b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (texImage->ImageOffsets) 63932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage->ImageOffsets); 64032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(texImage); 64177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 64277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 64377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 650aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 65177ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 65277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 653aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 654874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below, 655874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * except there's no proxy for GL_TEXTURE_BUFFER. 656874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 657874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul assert(NUM_TEXTURE_TARGETS == 8); 6582465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 66227f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 663bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 664bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 665bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 666aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 667aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 668aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 67035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target 67135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 67235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum 67335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target) 67435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{ 67535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul switch (target) { 67635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D: 67735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D: 67835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D; 67935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D: 68035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D: 68135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D; 68235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_3D: 68335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_3D: 68435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_3D; 68535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 68635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 68735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 68835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 68935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 69035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 69135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 69235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 69335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_CUBE_MAP_ARB; 69435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_RECTANGLE_NV: 69535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 69635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_RECTANGLE_NV; 69735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 69835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 69935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D_ARRAY_EXT; 70035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 70135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 70235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D_ARRAY_EXT; 70335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul default: 70435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul _mesa_problem(NULL, "unexpected target in get_proxy_target()"); 70535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return 0; 70635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul } 70735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul} 70835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 70935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 71035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/** 7113c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 7123c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * texture unit. 7136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 7166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 7196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit. 72135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 72235d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 7233c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 7243c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 72535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 72635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 727f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array || 728f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 729f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 73135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7329818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 73335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 734fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 73535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7369818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 73735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 738fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 73935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 7409818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 74135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 742fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 74335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 74435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 74535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 74635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 74735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 74835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7495ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 750a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7519818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 75235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 753a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 754fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7579818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7588afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7598afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 760fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 761bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 762f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 763bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 764f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 765bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 766f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 767bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 768f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 769874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 770874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return ctx->Extensions.ARB_texture_buffer_object 771874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL; 77235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 77308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 77435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 77535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 77635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 77735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 77835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 780b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 781b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 782b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 783f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 784b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 785b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 786b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 787b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 788b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 789b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 790b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 791c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 792c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 793c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7961eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 800c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 801fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 802fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 8033c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 8043c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 8055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 806fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 807c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 8085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 809c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 810c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 811c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 812bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 813c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 814fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 815fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 816fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 818a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 819a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 820a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 823f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 8275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 8295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 842a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 843a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 847a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 848a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 849a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 852a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 853f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 855a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 85680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 857a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 858a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 859a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 860a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 861a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 862a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 863a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 86680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 867a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 868a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 87180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 872a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 873a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 874a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 87680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 877a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 878a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 879a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 88080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 88180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 882a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 883a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 884a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 88580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 88680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 887bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 888bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 889bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 89080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 89180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 892bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 893bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 894bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 89580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 89680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 897a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 898a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 899a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 90080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 90180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 90280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 90380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 90480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 90580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 90680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 90780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 90980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 91080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 91180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 91280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 913a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 914a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 915a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 9166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 9176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 9186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 9206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 9216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 928f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 929ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 930ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 931ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 932ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 933ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 934ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 935ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 936ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 937ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 938ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 941ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 942ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 943ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 944ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 945add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 946ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 947fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 948fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 949ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 950ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 951fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 952fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 953fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 954fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 955fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 956f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 957f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array) 958fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 959874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 960874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 961ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 962ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 963ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 964ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 965ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 966ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 96783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9685e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 96983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 970a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 971a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 97283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 97383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 97483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 97583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 97683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 97783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 97883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 97983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 98083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 98183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 98283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 98383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 98483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 98583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 98683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 98783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 98883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9895e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9905e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 99183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 99283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 99383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9945e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9955e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 99683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 997874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 998874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 99983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 100083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 100183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 100283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 100383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 100483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 100583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1008fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 100962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 1010f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 1011afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 1012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 10138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 1014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 10168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 1017afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 10188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 10198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 10208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 1021afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1022a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 1025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 1026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 1027afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 102965d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1032afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1034afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1035afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1036afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1038afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1039afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10468e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10478e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1051afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1052afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1053afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1054afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1055a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10568e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1058afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 105962c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1060afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1061afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1062afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1063738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1064f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10689c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10699c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1070f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1071f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1072f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1075f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10769c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10779c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1078a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1079a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10809c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10819c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10829c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10839c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 1084681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul img->RowStride = 0; 1085b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul if (img->ImageOffsets) { 108632f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 1087b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets = NULL; 1088b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 10899c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10909c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10919c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10929c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10939c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10949c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10959c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Data = NULL; 10961f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10974f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelc = NULL; 10984f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul img->FetchTexelf = NULL; 10999c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 11009c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 11019c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 11026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 11036628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 11046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1106b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 11076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 11086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 11096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 11106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 11116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 11126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 111383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 11146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 11156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1116887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 11176628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 11183893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1119f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 11203893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 11213893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 112283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 112383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 11246628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 112583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint i, dims; 1126b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11276628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11288bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11298bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11308bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1131b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1132a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1133a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1134a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11356628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11366628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11376628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11386628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1139c813b545ab4726fc5030f123ec6255224d64ad82Brian 11404d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 1141b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->WidthLog2 = _mesa_logbase2(img->Width2); 1142c813b545ab4726fc5030f123ec6255224d64ad82Brian 1143c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1144c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 11456628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1146c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1147c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1148c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1149b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->HeightLog2 = _mesa_logbase2(img->Height2); 1150c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1151c813b545ab4726fc5030f123ec6255224d64ad82Brian 1152c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1153c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 11546628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1155c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1156c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1157c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 1158b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->DepthLog2 = _mesa_logbase2(img->Depth2); 1159c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1160c813b545ab4726fc5030f123ec6255224d64ad82Brian 11616628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1162c813b545ab4726fc5030f123ec6255224d64ad82Brian 1163be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian if ((width == 1 || _mesa_is_pow_two(img->Width2)) && 1164be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (height == 1 || _mesa_is_pow_two(img->Height2)) && 1165be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian (depth == 1 || _mesa_is_pow_two(img->Depth2))) 1166887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_TRUE; 1167887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul else 1168887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul img->_IsPowerOfTwo = GL_FALSE; 1169887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul 1170b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ 1171b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->RowStride = width; 1172b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul /* Allocate the ImageOffsets array and initialize to typical values. 1173b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * We allocate the array for 1D/2D textures too in order to avoid special- 1174b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * case code in the texstore routines. 1175b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul */ 1176a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer if (img->ImageOffsets) 117732f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(img->ImageOffsets); 117832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); 1179b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul for (i = 0; i < depth; i++) { 1180b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul img->ImageOffsets[i] = i * width * height; 1181b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul } 1182b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 11838afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* Compute Width/Height/DepthScale for mipmap lod computation */ 11848afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul if (target == GL_TEXTURE_RECTANGLE_NV) { 11858afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul /* scale = 1.0 since texture coords directly map to texels */ 11868afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = 1.0; 11878afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = 1.0; 11888afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = 1.0; 11898afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11908afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul else { 11918afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->WidthScale = (GLfloat) img->Width; 11928afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->HeightScale = (GLfloat) img->Height; 11938afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul img->DepthScale = (GLfloat) img->Depth; 11948afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 11951a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul 119683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 119783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1198a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie dims = _mesa_get_texture_dimensions(target); 119983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 120083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_set_fetch_functions(img, dims); 12016628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 12026628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 12036628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1204738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 120542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 120642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 120742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 120842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 120942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 121042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 121142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 121242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 121342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 12143c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 12153c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 121642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 121742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu ctx->Driver.FreeTexImageData(ctx, texImage); 121842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 121942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 122042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 122142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 122242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1229aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1230aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1231aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1232aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1234738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1235738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1238738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1239738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1240738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1241738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1242738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1243738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1244738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1245738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1246738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1247f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1248738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1249738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1250738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1251738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12529c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1253738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1254738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1255738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1256738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1257738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1258738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1259738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1260c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1261738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1262c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1263c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1265c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1267738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1268738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1270738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1271738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1272c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1274c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1276c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1278c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1279c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1280c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1281c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1283738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1284738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1285c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1286738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1287738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1288c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1289c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1291738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1292c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 2 * border || depth > 2 + maxSize) 1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1294c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1295c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1296c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1297c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1298c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1299c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1300c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1301c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1302c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1303738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1304738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1305c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1306738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1307c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1308c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1309c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1310c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1311c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1313738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1314738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1315c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1316738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1317738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1318c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1319c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1320c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1321c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1322c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1323738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1324c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1325c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1326c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1327c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1328c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1329738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1330738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1331c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1332bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1333bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1334c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1335bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1336c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1337bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1338c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1339c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1340c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1341c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1342c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1343bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1344bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1345c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1346bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1347bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1348c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1349bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1350c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1351c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1352c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1353bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1354c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1355c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1356c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1357c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1358c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1359c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1360c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1361bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1362bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1363c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1364738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1365738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1366738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1367738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1368738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1369738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1370738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1371738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 13724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 13734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 13744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 13754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 13764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 13774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 13784b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 13794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 13804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 13814b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 13824b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 13834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 13844b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 13854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 13864b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13874b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13884b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13894b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 13907404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 13917404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1392064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1393064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1396064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 13987404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1399646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1400646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1401646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 14027404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1403646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1404646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1405646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1406646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1407646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1408646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1409646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1410646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1411646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1412646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1413f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1414684c66bb8b8cdaa7fc18b64a6f739ad70a10cd54Brian Paul ctx->Extensions.EXT_texture_array); 1415646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1416646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1417646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1418064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1419064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1420064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1421064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D: 1441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1447d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.NV_texture_rectangle; 1453d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1455f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1456f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1463d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_3D: 1464d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1467f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1468f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1472d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 148011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 148109a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 148209a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 148309a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 148411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 148511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 148609a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 148711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 148811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 148911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 149011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return target == GL_TEXTURE_1D; 149111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 149211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 149311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 149411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 149511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 149611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 149711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 149811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 149911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 150011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 150111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 150211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 150311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.NV_texture_rectangle; 150411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1505f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1506f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 150711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 150811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 150911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 151009a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 151109a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 151209a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 151309a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 151409a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1515f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1516f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 151709a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 151809a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 151909a5e028a6d254f619132e302a96c8535018603dBrian Paul } 152011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 152109a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 152209a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 152311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 152411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 152511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 152611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 152711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 152811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 15296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 15306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 153285288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 15336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 15346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 15356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 15366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 15376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 15386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 15396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 15406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 15416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 15426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 15446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 15456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 15463c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 15473c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1549c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 155085288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 155185288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1552c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1553c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1554c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1555c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 155735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 155835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1559e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1560714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca GLboolean colorFormat, indexFormat; 1561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1562738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1563738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1564738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1565738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1566738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 15678afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1568738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1569738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1570738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1571738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1572738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1573738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1574738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1575738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1576738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1577738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1578738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1579738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1580738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1581738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1582973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1583f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1584f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1585973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1586f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1587f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1588f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1589f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 159035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 159135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 159235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1594d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 159535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 159635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 159735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 159835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 159935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1600e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1601e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1602e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1603738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1604c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 16054e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1606738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1607738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1608c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1609afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1610afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1611afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1612738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 161389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1614c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 16154e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1616a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1617a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1618c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1619afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1620afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1621afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1622738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1623f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1624326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1625326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1626326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1627326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 162838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 162938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1630326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1631326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1632326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 16338a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 16348a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1635c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 163638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1638afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1639601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 164022e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 1641ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul indexFormat = _mesa_is_index_format(format); 164222e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1643ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_index_format(internalFormat) && !indexFormat) || 1644ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1645ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1646ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1647ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1648601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1649601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16508a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 16518a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1652601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1653601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1654601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1655601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1656601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1657c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1658601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1659601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1660c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1661fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16622236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1663c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1664c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1665c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1666d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1667d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1668d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1669d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1670d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1671d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1672d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1673d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1674d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1675d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1676d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1677fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 16782236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1679fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1680c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1681d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1682d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1683d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1684c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1685c5b995066020191982b2315fc45d05e068eee761Brian Paul 1686601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1687601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 1688753660780a84187043d0dc4b0e0f449786862182Brian Paul /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */ 1689601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1690601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1691601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16922b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 1693753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_1D_ARRAY && 1694753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_1D_ARRAY && 1695753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_2D_ARRAY && 1696753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_2D_ARRAY && 16972b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16982b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1699601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1700601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1701601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1702601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1703601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1704601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1705601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1706601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1707c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 17087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 17097404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 17107404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 17117404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1712064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 171389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 171589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 171689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17178978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 171889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 171989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 172089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 172189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 172289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1723326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1724326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1725326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1726326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1727326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1728326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1729326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1730326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1731326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1732326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1733326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1734326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1735afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1737afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1738afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1739afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1741c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 17426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 17446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 17456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 17466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 17476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 17486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 17496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 17506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 17516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 17526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 17536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 17546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 17556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 17576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 17586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 17593c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 17603c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1761afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1762c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1763f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1764c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1765c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1766c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1769738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1770738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 17714e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1772c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1773c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1774afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 177545124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1776c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 17774e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17784e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1779c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1780c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1781c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 17824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 17834e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1784c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1785c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1787738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1788738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1789c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1791afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1793326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1794326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1795326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1796326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1797326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1798326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 17998a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 18008a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 18015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 18025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 18045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 18055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1806f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1807d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1808d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1809d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1810d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1811d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 18125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1813f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 18145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 18155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 18165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 18175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 18185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 18195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1821738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1822738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1823c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1824c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1825afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1826c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1827738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1828738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1829c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1830afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1831c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1832738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1833738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1834c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1835c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1836c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1837c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1838738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1839738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1840c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1841afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1842c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1843738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1844738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1845c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1846afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1847afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1849c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 185008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1851c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1852c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 185338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 185408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1855c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1856c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1857afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1858afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1859b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1860d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1861d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1862d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1863d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1864d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1865d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1866d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1867e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18688978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1869d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1870e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1871e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1872d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1873d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1874e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18758978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1876e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 187789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1878d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 187989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18808978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 188189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 188289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1883e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1884e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1885c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1886c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1887afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1888afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1890c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 19006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 19026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 19043c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 19053c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1906afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1907c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1908f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1909c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1911afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 191211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 191311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 1914738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 19150899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul GLint format; 1916afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 191711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 191809a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 191911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 192011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 192111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 192211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 192311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1924738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1925738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 19265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 19275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 19285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 19295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 19305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 193134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 193234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 1933b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 1934b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 1935b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 193634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 193734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 193834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 193934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 194034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 194134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 194234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1943738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1944738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1945738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1946738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1947738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1948738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1949738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1950738318bb75dea8dac4465f53850987f6062a732dBrian Paul format = _mesa_base_tex_format(ctx, internalFormat); 19510899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul if (format < 0) { 19520899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19530899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 19540899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19550899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19560899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 195734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (!_mesa_source_buffer_exists(ctx, format)) { 195834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 195934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 196034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 196134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 196234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 196311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 196411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 196511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 1966738318bb75dea8dac4465f53850987f6062a732dBrian Paul 196711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 196811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul internalFormat, format, 196911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 197011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 1971c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1972738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1973738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 19744e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1975738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1976c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1977738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1978738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1979738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1980738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1981ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1982c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1983c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1984c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1985c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 19867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 198789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 19882236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 198989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 199089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 199189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 199289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19938978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 199489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 199589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 199689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1997ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depth_format(internalFormat)) { 19980899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 19991a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 20000899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20018978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth)", dimensions); 20020899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20030899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20040899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2005ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul else if (_mesa_is_depthstencil_format(internalFormat)) { 20060899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul /* make sure we have depth/stencil buffers */ 20071a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 20080899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20098978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(no depth/stencil buffer)", dimensions); 20100899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 20110899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 20120899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 201389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2014c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2015c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2016c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2017c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2018c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 202034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 20219dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 20229dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 20236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 20256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 20266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 20276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 20286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 20306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2031c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 2032f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 20339dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 2034c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 203534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 203634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 2037b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 2038b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 2039b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 204034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 204134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 204234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 204334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 204434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 204534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 204634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 20471c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 204809a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 20491c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 20501c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 20511c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 2052c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2053c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2054738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2055738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20564e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2058c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2059c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2060c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 20625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 20635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 20649dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 20659dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 20669dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 20679dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 20689dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 20699dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 20709dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 20719dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 20729dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 20735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2074f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 20755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 20765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 20775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 20785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 20795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 20809dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2081c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 20824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2083b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2084b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2085c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2086c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2087c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 20899dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 20909dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20919dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 20929dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20939dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20949dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 20959dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20969dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 20979dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 20989dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 20999dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 21009dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2101c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 21024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21034e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2104c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2105c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 210638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 21074e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21084e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2109c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2110c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2111c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2112c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 21134e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21144e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2115c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2116c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2117c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 211838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 21194e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2121c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2122c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2123c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2124c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 21259dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2126c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2127c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 21284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21294e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2130c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2131c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 213238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 21334e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21344e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2135c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2136c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2137c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2138c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2139b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 214089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 214189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 214289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21438978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2144e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2145e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 214689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2147798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 214889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21498978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2150e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 215189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2152798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 215389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21548978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 215589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 215689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2157e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2158e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2159a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2160d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2161d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2162d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2163d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2164985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2165985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2166803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2167803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2168985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2169985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2170985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2171a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) { 21721a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer) { 21730899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21748978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth buffer)", 21750899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21760899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21770899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21780899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 2179a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) { 21801a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) { 21810899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21828978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(no depth/stencil buffer)", 21830899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul dimensions); 21840899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21850899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21860899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21870899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2188326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2189326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2190326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2191412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2192326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2193412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2194326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2195326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2196326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2197326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2198326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2199326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2200326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2201c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2202c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2203c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2204c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2205c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22062897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 22072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 22082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2209f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 22102897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 22112897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 22122897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 22132897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2215519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 22162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2217519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2218519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 22192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2220519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 22212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 22222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2223f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 22242897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 22252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 22262897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 22282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2229519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 22302897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2231519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 22322897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2233519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2234519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2235519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2236519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2237db0f9e701d59dcfcd3b50f4d245897692f27fec9Brian Paul ASSERT(_mesa_get_attachment_teximage(att)); 2238519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2239ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 22402897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 22412897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2242519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2243519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2244519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2245519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2246519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2247519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 22482897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 22492897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 22502897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 22512897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 22522897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 22532897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 22542897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2255f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 22562897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 22572897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 22582897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 22592897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 22602897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 22612897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 22622897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 22632897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 22642897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 22652897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 22662897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 22672897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 22682897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22692897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 22702914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 22712914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 22722914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 22732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 22742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 22752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void 2276f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 22772914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 22782914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 22792914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2280ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2281ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2282ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 22832914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 22842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 22852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 22862914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 22872914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22882914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 22891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 22901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 22911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 22921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 22931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 22941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 22951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 22961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 22971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 22981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 23001826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 23011826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 23021826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 23031826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23041826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 23051826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 23061826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23071826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 23081826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23091826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 23101826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 23111826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23121826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 23131826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23141826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 23151826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 23161826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 23171826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 23181826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23191826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 23201826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 23211826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 23221826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23231826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 23241826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 23251826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23261826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 23271826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 23281826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 23291826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 23301826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 23311826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2332519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2333bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2334bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2335bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2336bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2337bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2338bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2339bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2340bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 234183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2342f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2343bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2344bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2345bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2346bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 234783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 234883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2349bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2350bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2351bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2352bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2353bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2354bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2355bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2356bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2357bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2358bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2359bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 236083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 236183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2362bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2363bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2364bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2365bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 236683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 236783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 236883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2369bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2370bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2371bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2372d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2373d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2374c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2375d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2376d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2377d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2378d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2379d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2380d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2381c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2382d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 2383d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2384cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2385c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2386d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2387d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2388d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2389d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2390d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2391d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2392d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2393d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2394d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2395d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 239611caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2400d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2401d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2402d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2403ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2404d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2405d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2406d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 24072914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2408d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2409d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 241262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2413d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2414738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2415a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2416a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2417c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 241889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 241989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2420bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2421bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 242483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 242583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 2429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 24314b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24324b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 24334b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 24344b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 243589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2436c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2437c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 24388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 24400293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 24410293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2442f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 24448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2445c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2446c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24477ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 24485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2449fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2450b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 24535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 24545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 24565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2459ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 246083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 246183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2462ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul if (texImage->Data) { 2463ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 2464ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2465ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2466ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ASSERT(texImage->Data == NULL); 246783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 246883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 246983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 247083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2472d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 247511caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 24764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ASSERT(ctx->Driver.TexImage3D); 2478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 2479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 2480d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2481d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, border, format, 2482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2484d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2485d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 2486d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2487d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, border, format, 2488d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2489d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2490d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2491d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 2492d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2493d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, format, 2494d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul type, pixels, &ctx->Unpack, texObj, 2495d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2496d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2497d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 2498d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in teximage()", dims); 2499d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2500ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 25014b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 25022914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 25034b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2504ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 25054b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 25064b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 25074b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 25084b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 25094b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2510d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 25114b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2512ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2513ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 25145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2516d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2517d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2518d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2519d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2520d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2521d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2522d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2523d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2524d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2525d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2526d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2527d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2528d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2529d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2530d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2531d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2532d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2533d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2534d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2535d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2536d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2537d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2538d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2539d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2540d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2541d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2543afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2549c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2550b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2551fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2552fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2553fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2554afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2555fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2556d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2557d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2561c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 256243911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2563663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2564663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2565663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2566663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 256789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2568663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2569663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2570663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2571663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2572d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2573d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2574d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2575d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2576d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2577d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 257817efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 257917efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2580d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25812002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 25822002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 25832002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 25842002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 25852002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 25862002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2587d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2588d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2589d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2590d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2591d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2592d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25937ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 2594d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2595d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2596d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2597d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2598d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2599d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2600d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2601d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2602d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 2603d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (texImage->Data) 2604d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.FreeTexImageData( ctx, texImage ); 2605d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2606d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ASSERT(texImage->Data == NULL); 2607d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2608d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2609d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2610d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2611d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2612d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2613d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2614d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2615d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2616d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2617d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2618d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2619afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 262045124e043da5a67e1081526d61b99422f4ccde19Brian Paul 262145124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 262245124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 262345124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 262445124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 262545124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 262645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 262745124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 262845124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2629afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26300293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2631b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 263245124e043da5a67e1081526d61b99422f4ccde19Brian Paul 263375280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 263475280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2635d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 263645124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 263745124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2638d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 263945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 264045124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2641d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2642d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 264345124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 264409a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 264545124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 264645124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 264745124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 264845124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 264945124e043da5a67e1081526d61b99422f4ccde19Brian Paul 26507ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 265108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 26522aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 265345124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 265445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2655f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2657afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2658b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2659afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 26615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 26625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 266545124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 266645124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 266745124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2668a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 26695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26704609e80288bacf19af99b0ed7656eef9bb280912Brian Paul else if (width > 0 && height > 0 && depth > 0) { 267145124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 267245124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 267345124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 267445124e043da5a67e1081526d61b99422f4ccde19Brian Paul zoffset += texImage->Border; 267545124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 267645124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 267745124e043da5a67e1081526d61b99422f4ccde19Brian Paul yoffset += texImage->Border; 267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 267945124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 268145124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2682347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 268345124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 268445124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 268545124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, 268645124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, width, 268745124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 268845124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 268945124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 269045124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 269145124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, 269245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, width, height, 269345124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 269445124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 269545124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 269645124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 269745124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 269845124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 269945124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 270045124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 270145124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 270245124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 270345124e043da5a67e1081526d61b99422f4ccde19Brian Paul default: 270445124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_problem(ctx, "unexpected dims in subteximage()"); 270545124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 27062914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 27072914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 27082914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2709ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2710ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 27115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2713afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2716c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 271745124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 271845124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 271945124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 272045124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 272145124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 272245124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 272345124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 272445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 272545124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 272645124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 272745124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 272845124e043da5a67e1081526d61b99422f4ccde19Brian Paul 272945124e043da5a67e1081526d61b99422f4ccde19Brian Paul 273045124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2731fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2732fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2733fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2734fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2735fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27372c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 273845124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 273945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 274045124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 274145124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2742c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2743afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2744afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2745afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2746c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2747fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2748fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2749fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2750fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2751fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2752afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27532c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 275445124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 275545124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 275645124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 275745124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2759afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2760afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2761afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 276211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 276311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 276411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 276511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 276611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 276711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 276811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 2769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 27702aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 27712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2772e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 277311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2774cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2775afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2776d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 277711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 277811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 2779d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2780d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 278111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2782d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 278363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 278408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2785fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 278611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 278711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 2788ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2789ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2790b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2791a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 27925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 279511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 27965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 279711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2799c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 28005874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* choose actual hw format */ 28015874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 28025874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul target, level, 28035874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul internalFormat, 28045874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GL_NONE, GL_NONE); 28057dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 28065874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 28075874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GLint srcX = x, srcY = y, dstX = 0, dstY = 0; 28087dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 28095874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Free old texture image */ 28105874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.FreeTexImageData(ctx, texImage); 28112aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 281211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 28134b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 281411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 28155874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Allocate texture memory (no pixel data yet) */ 28165874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) { 28175874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 28185874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, border, GL_NONE, GL_NONE, NULL, 28195874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &ctx->Unpack, texObj, texImage); 28205874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28215874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else { 28225874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 28235874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, height, border, GL_NONE, GL_NONE, 28245874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul NULL, &ctx->Unpack, texObj, texImage); 28255874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28265874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 28275874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (_mesa_clip_copytexsubimage(ctx, &dstX, &dstY, &srcX, &srcY, 28285874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &width, &height)) { 28295874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) 28305874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, dstX, 28315874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width); 28325874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 28335874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else 28345874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, dstX, dstY, 28355874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width, height); 28365874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 28372aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 28384b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 28392914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28404b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2841519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 28424b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 28434b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 28444b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 28454b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 28464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 28475874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* probably too large of image */ 284811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 28494b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2850c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 28515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2853afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2854afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2855afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2856afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2857c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 285811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 285911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 286011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 286111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 2862afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2863fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 286411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 286511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 2866c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 28672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2868c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 286911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 287011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 287111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 287211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 287311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 287411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 287511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 287611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2877afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2878afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2879afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28801c23b860cea93534f726d2a18658444f37f43538Brian Paul 28811c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 28821c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 28831c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 28841c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 28851c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 28861c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 28871c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 2888afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 2890347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 289103bafd1f9fa000abdb794b2ae344a68840c83201Brian 2892cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2893afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2894d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 28951c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 28961c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 2897d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 28981c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 2899d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 290063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 290108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2902fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 29031c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 2904ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2905ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2906b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 29075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 29095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 29105ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 29115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 29121c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 29131c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 29141c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 291503bafd1f9fa000abdb794b2ae344a68840c83201Brian } 2916a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 29171c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 29181c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 29191c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 29201c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset += texImage->Border; 29211c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 29221c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 29231c23b860cea93534f726d2a18658444f37f43538Brian Paul yoffset += texImage->Border; 29241c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 29251c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 29261c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 29271c23b860cea93534f726d2a18658444f37f43538Brian Paul } 292803bafd1f9fa000abdb794b2ae344a68840c83201Brian 2929a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 2930a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 29311c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 29321c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 29331c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 29341c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, x, y, width); 29351c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29361c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 29371c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, 29381c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, 29391c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29401c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29411c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 29421c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 29431c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, zoffset, 29441c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 29451c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 29461c23b860cea93534f726d2a18658444f37f43538Brian Paul default: 29471c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_problem(ctx, "bad dims in copytexsubimage()"); 29481c23b860cea93534f726d2a18658444f37f43538Brian Paul } 29492914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 29502914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 29512914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2952a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 2953a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 2954a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 29555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2957afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2958afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2959afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 29601c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 29611c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 29621c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 29631c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 29641c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 29651c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 29661c23b860cea93534f726d2a18658444f37f43538Brian Paul} 29671c23b860cea93534f726d2a18658444f37f43538Brian Paul 29681c23b860cea93534f726d2a18658444f37f43538Brian Paul 2969afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2970c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2971fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2972fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2973fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2974afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2975fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29761c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 29771c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 2978afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2980afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2981afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2982c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2983fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2984fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2985fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2987fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29881c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 29891c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 2990afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 29911207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 299489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 299589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 299689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 299789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 299889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 299989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 300089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 300154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 300254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 300354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 300454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 300554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 300654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 300754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 300854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 300954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 301054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 301154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 301207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 301307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 301407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 301507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 301607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 301707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 301807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 301907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 302007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 302154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 302254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 302354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 302489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 3025d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch * \param reason returns reason for error, if any 302689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 302789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 302889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3029f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 303089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 303189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 303289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 3033d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch GLsizei imageSize, char **reason) 303489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 30354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 30364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 30374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 303889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3039d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = ""; /* no error */ 3040d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch 30414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check level */ 3042d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (level < 0 || level >= maxLevels) { 3043d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "level"; 30444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul return GL_INVALID_VALUE; 3045d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 304689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30477404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 3048d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "target"; 30497404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 30507404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30517404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 3052c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 3053d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (!_mesa_is_compressed_format(ctx, internalFormat)) { 3054d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 305589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 3056d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 305789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3058c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3059d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 3060d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 3061a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3062d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 3063a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 30644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 3065d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (border != 0) { 3066d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "border != 0"; 306789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3068d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 306989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 307089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 307189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 3072d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) { 3073d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "width != height"; 307489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3075d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 307689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30777404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 30787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 30797404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 30807404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul ctx->Driver.ChooseTextureFormat(ctx, internalFormat, 30817404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GL_NONE, GL_NONE); 30827404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 30837404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30847404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 30857404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 30867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 30877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 30887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 30897404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 30907404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 30917404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3092d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width or height for compression format"; 30937404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30967404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 30984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 30994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE, 31004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border)) { 31017404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 3102d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width, height or format"; 31037404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 31044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 310589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 31064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 310754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, internalFormat); 31087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 31097404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 31107404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 31117404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 31127404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3113d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "imageSize inconsistant with width/height/format"; 311489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 31157404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 311689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 311889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 311989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 312189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 312289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 31232371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 31242371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 31252371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 312689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 312789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 312889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3129f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 313089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 313189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 313289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 313389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 313489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 313589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 313607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3137a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 313889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 314089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 314189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 314289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 314489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 314589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 314689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 314889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 314989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 315189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 315289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 315489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 315689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 315789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 315889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 316089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 316289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 316389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 316689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 316789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 316889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 317089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 317189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3172c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3173c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 317489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 317589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3176887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 317789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3179887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 318089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 318189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 318289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 318389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 318489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 318589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 318607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 318707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 31882371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 318907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 319007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 319107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 319289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 319589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 319889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 320189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 320289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 320389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 320589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 320689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3208f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3209f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3210f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3211f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3212f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3213f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3214f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3215f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3216f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3217f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3218f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3219f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3220f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3221f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3222f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3223f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3224f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3225f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3226ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3227ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3228f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3229f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3230f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3231f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3232f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3233f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3234f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3235ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3236ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3237f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3238f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3239f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3240f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3241f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3242f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3243f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3244f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3245ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3246ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3247f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3248f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3249f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3250f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3251f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3252f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3253f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3254f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3255f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3256f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 32574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 32594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 32604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 32614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 32634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 32644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 32654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 32661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32674ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 3268d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch char *reason = ""; 32694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3270cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3271aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3272d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 32734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 32744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 32754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3276d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3277d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 32784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 32795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 32817404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 32824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 32834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3284aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3285aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32861207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 32884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 3289d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch border, imageSize, &reason); 3290d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 32914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 3292ca7510bbf9bdff35f813f970e3120a9c7f728ccaBrian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD(%s)", dims, reason); 32937179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 32947179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 32957179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 3296af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul#if FEATURE_ES 3297af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul /* XXX this is kind of a hack */ 32984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (dims == 2) { 32994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 33004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 33014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 33024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 33034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 33044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 33054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 33064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 33074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 33084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 33094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 33104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 33114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 331289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3313aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3316aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 33174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 33184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 33194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 33202914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 33218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 33224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 33234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 33244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 33254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 33264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 33274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 33284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 33294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3330aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 33324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 33334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 33344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 33354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 33364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 33374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 33394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 33404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 33414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 33424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 33434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 334489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3345aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3346aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 33478c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3348aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3349aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 33504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 335189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 33524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD", dims); 335389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3354aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3355aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3356b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 33579519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 33595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 33605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 33615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 33624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3365c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 336683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 336783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 3368c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul if (texImage->Data) { 3369c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ctx->Driver.FreeTexImageData( ctx, texImage ); 3370c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3371c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul ASSERT(texImage->Data == NULL); 3372c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 337383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 337483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 337583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 337683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 33774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 33784b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 33794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 33804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 338111caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 33824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (dims) { 33834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 1: 33844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 33854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 33864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 33884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 2: 33924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 33934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 33944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 33964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 3: 34004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 34014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 34024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 34034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, 34044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 34054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 34064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 34074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul default: 34084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_problem(ctx, "bad dims in compressedteximage"); 34094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3410c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34114b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 34122914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34134b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 34144b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 34154b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 34164b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 34174b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 34184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 34194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 34204b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3421c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3422c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3424aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 34254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34269519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34279519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 34304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 34324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 34364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 34374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 34424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 34444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 34484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 34494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 34544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 34564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 34574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 34604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 34611207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34621207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34646bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 34656bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 34666bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 34676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 34686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 34696bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 34706bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 34716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 34721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34739540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 34749540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 347589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3476a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 347775280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 347875280a2c742ee241d392618a3b29548fce1520a9Brian Paul 34796bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3480c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 34816bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3482c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 348389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 34846bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 348589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 34869540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34879540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3488b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3489c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 34935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 34949540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 34956bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3496f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3497f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3498c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34996bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 35006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 35016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 35026bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 35036bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 35046bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 35056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35066bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35076bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35086bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35096bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 35106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 35116bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 35126bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 35136bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 35146bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35156bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35166bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35176bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35186bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 35196bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 35206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 35216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 35226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 35236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35266bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35276bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 35286bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3529c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 35302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35312914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 35322914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35332914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 35345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35359540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 35365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 35371207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35381207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35391207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3540c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35416bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 35426bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 35436bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 35446bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 35456bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 35466bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 35476bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 35486bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35496bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35506bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 35511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 35521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 35531207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 35541207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35551207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35566bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 35576bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 35581207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35601207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3561c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35621207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 35631207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 35641207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 35651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 35661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35676bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 35686bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 35691207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3570874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3571874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3572874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** 3573874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * Helper for glTexBuffer(). Check if internalFormat is legal. If so, 3574874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * return the basic data type and number of components for the format. 3575874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise 3576874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 3577874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulstatic GLboolean 3578874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulget_sized_format_info(const struct gl_context *ctx, GLenum internalFormat, 3579874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum *datatype, GLuint *components) 3580874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3581874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul switch (internalFormat) { 3582874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8: 3583874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3584874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3585874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3586874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16: 3587874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3588874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3589874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3590874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16F_ARB: 3591874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3592874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3593874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3594874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32F_ARB: 3595874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3596874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3597874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3598874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8I_EXT: 3599874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3600874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3601874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3602874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16I_EXT: 3603874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3604874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3605874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3606874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32I_EXT: 3607874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3608874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3609874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3610874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8UI_EXT: 3611874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3612874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3613874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3614874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16UI_EXT: 3615874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3616874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3617874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3618874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32UI_EXT: 3619874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3620874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3621874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3622874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8: 3623874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3624874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3625874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3626874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16: 3627874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3628874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3629874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3630874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16F_ARB: 3631874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3632874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3633874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3634874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32F_ARB: 3635874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3636874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3637874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3638874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8I_EXT: 3639874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3640874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3641874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3642874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16I_EXT: 3643874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3644874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3645874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3646874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32I_EXT: 3647874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3648874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3649874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3650874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8UI_EXT: 3651874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3652874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3653874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3654874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16UI_EXT: 3655874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3656874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3657874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3658874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32UI_EXT: 3659874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3660874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3661874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3662874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8_ALPHA8: 3663874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3664874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3665874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3666874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16_ALPHA16: 3667874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3668874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3669874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3670874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 3671874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3672874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3673874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3674874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 3675874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3676874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3677874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3678874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 3679874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3680874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3681874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3682874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 3683874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3684874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3685874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3686874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 3687874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3688874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3689874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3690874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 3691874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3692874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3693874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3694874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 3695874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3696874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3697874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3698874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 3699874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3700874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3701874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3702874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8: 3703874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3704874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3705874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3706874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16: 3707874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3708874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3709874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3710874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16F_ARB: 3711874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3712874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3713874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3714874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32F_ARB: 3715874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3716874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3717874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3718874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8I_EXT: 3719874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3720874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3721874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3722874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16I_EXT: 3723874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3724874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3725874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3726874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32I_EXT: 3727874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3728874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3729874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3730874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8UI_EXT: 3731874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3732874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3733874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3734874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16UI_EXT: 3735874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3736874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3737874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3738874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32UI_EXT: 3739874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3740874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3741874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3742874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8: 3743874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3744874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3745874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3746874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16: 3747874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3748874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3749874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3750874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16F_ARB: 3751874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3752874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3753874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3754874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32F_ARB: 3755874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3756874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3757874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3758874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8I_EXT: 3759874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3760874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3761874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3762874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16I_EXT: 3763874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3764874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3765874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3766874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32I_EXT: 3767874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3768874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3769874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3770874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8UI_EXT: 3771874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3772874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3773874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3774874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16UI_EXT: 3775874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3776874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3777874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3778874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32UI_EXT: 3779874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3780874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3781874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3782874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul default: 3783874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3784874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3785874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3786874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float) 3787874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3788874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3789874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel) 3790874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3791874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3792874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_TRUE; 3793874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3794874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3795874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3796874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** GL_ARB_texture_buffer_object */ 3797874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulvoid GLAPIENTRY 3798874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) 3799874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3800874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_texture_object *texObj; 3801874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_buffer_object *bufObj; 3802874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum dataType; 3803874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLuint comps; 3804874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3805874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GET_CURRENT_CONTEXT(ctx); 3806874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3807874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3808874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!ctx->Extensions.ARB_texture_buffer_object) { 3809874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer"); 3810874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3811874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3812874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3813874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (target != GL_TEXTURE_BUFFER_ARB) { 3814874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)"); 3815874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3816874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3817874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3818874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!get_sized_format_info(ctx, internalFormat, &dataType, &comps)) { 3819874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)", 3820874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul internalFormat); 3821874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3822874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3823874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3824874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul bufObj = _mesa_lookup_bufferobj(ctx, buffer); 3825874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (buffer && !bufObj) { 3826874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer); 3827874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3828874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3829874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3830874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3831874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3832874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_lock_texture(ctx, texObj); 3833874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul { 3834874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj); 3835874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj->BufferObjectFormat = internalFormat; 3836874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3837874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_unlock_texture(ctx, texObj); 3838874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3839