teximage.c revision 638b657f838266e3d4892d06ff53a1c1bee24a9b
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2120d71a45cfda1edfa8cd6b1732e209eb98b53d8Brian Paul * Mesa 3-D graphics library 35e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 49f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 135e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 165e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 26add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/** 27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c 2877ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions. 29add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */ 30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul 32fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 33b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h" 34afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 35d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h" 3634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h" 3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h" 382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h" 39afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h" 403c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 41ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h" 42db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 43fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h" 4489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 45afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h" 46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 477179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 485e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 49afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 50afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 514cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 5263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 5363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 567ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul#define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL) 5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 5863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 611749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 621749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 651749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 6989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 7089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 7189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 7273b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * 7373b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static 74afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 75b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 76f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 77afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 781749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 79afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 80afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 81afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 82afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 83afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 84afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 85afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 86afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 87afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 88afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 89afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 90afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 93afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 94afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 95afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 96afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 97afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 98afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 127f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 128f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 129f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 130f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 13129386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0). 13229386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick */ 13329386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick if (ctx->API != API_OPENGL) { 134f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 13529386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick case GL_BGRA: 136f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 137f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 138f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 139f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 140f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 141f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 1424741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 143f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 144f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 1454741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 1464741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 1474741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 148f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 149f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 150f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 151f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 152f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 15389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 15433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 15533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 15633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 15733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 15833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 15933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 16033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 16133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 16233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 16333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 16433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 16533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 16633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 16733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 16833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 169f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 170f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 171f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 172f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 173f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 17489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 175f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 17689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 177f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 178f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 179f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 180f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 181f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 182f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 183f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 1848f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 1858f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 188f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 18940bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 190f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 191f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 192f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 193f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 194f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 199663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 200f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 202663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 203f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 204f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 20789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 211f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2121749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 213f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 214f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 215f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 216f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 217f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 219f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 220f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 221f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 222f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 223f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 224f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 225f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 226f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 2348f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 236afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 238114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 239114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 240114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 241114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 242114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 243114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 244114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 245114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 246114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 247114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 2480be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák if (ctx->Extensions.EXT_texture_snorm) { 249c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 2500be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RED_SNORM: 2510be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R8_SNORM: 2520be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R16_SNORM: 2530be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RED; 2540be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG_SNORM: 2550be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG8_SNORM: 2560be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG16_SNORM: 2570be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RG; 2580be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB_SNORM: 2590be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB8_SNORM: 2600be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB16_SNORM: 2610be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RGB; 262c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 263c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 2640be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGBA16_SNORM: 265c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 2660be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA_SNORM: 2670be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA8_SNORM: 2680be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA16_SNORM: 2690be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_ALPHA; 2700be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_SNORM: 2710be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_SNORM: 2720be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_SNORM: 2730be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE; 2740be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_ALPHA_SNORM: 2750be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_ALPHA8_SNORM: 2760be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_ALPHA16_SNORM: 2770be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE_ALPHA; 2780be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY_SNORM: 2790be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY8_SNORM: 2800be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY16_SNORM: 2810be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_INTENSITY; 282c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 283c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 284c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 285c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 286114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 2871ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 2881ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 2891ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 2901ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 2911ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 2921ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 2931ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 2941ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 2951ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 2961ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 2970a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 2980a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 2990a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3000a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3010a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3020a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3030a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3040a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3050a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3060a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3070a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3080a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3090a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3100a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3110a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3120a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3130a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3140a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3150a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3160a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3170a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3183488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3190a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3200a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 321abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3220a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3230a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3240a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3250a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 326abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul if (ctx->Extensions.EXT_texture_integer) { 327abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 328abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 329abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 330abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 331abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 332abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 333abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 334abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 335abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 336abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 337abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 338abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 339abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 340abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 341abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 342abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 343abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 344abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 345abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 346abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 347abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 348abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 349abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 350abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 351abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 352abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 353abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 354abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 355abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 356abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 357abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 358abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 359abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 360abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 361abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 362abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 3736988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 3746988f65e43297ae63bbce30bf882f870b370096cBrian Paul 3756988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 3766988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 3776988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 3783ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 3793ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 3803ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 3813ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 3823ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 3836988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 3843ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 3853ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 3863ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 3876988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 3886988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 3896988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 3906988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 3916988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 3926988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 3933ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 3943ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 3953ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 3963ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 3973ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 3983ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 3993ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4003ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4013ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4026988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4033ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4043ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4053ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4063ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4073ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4086988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4093ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4103ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4113ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4136988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4146988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4156988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4166988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4176988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4183ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.EXT_texture_integer) 4193ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4203ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4243ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4256988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4266988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4276988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4286988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4296988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4306988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4316988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4326988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4336988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4346988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4356988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4366988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4376988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4386988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4396988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4406988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4416988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4426988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4436988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4446988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4456988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4466988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4476988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4486988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4496988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4506988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4536988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4556988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4566988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4576988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4586988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4596988f65e43297ae63bbce30bf882f870b370096cBrian Paul 460e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 462e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 463e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 465e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 466e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 471abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 472abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 4737d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák if (ctx->Extensions.EXT_texture_compression_latc) { 4747d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák switch (internalFormat) { 4757d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 4767d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 4777d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE; 4787d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 4797d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 4807d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE_ALPHA; 4817d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák default: 4827d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák ; /* fallthrough */ 4837d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 4847d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 4857d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 48669f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák if (ctx->Extensions.ATI_texture_compression_3dc) { 48769f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák switch (internalFormat) { 48869f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 48969f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák return GL_LUMINANCE_ALPHA; 49069f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák default: 49169f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák ; /* fallthrough */ 49269f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 49369f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 49469f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák 495fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick if (ctx->API == API_OPENGLES) { 496fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick switch (internalFormat) { 497fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGB8_OES: 498fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_R5_G6_B5_OES: 499fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGB8_OES: 500fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_R5_G6_B5_OES: 501fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick return GL_RGB; 502fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGBA8_OES: 503fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGB5_A1_OES: 504fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGBA4_OES: 505fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGB5_A1_OES: 506fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGBA8_OES: 507fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGBA4_OES: 508fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick return GL_RGBA; 509fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick default: 510fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick ; /* fallthrough */ 511fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick } 512fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick } 513fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick 514f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 515afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 516afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 517afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 519e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 520e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 521e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 522e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 523e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 524519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 525519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 526519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) 527519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 528519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 529519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 530519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 531519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 532519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 533519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 5358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure 5368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters. 5376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 5433893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 5443893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj, 5453893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLenum target, GLint level, 5463893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *texImage) 547fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5489c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5499c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 550fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 551fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5529c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0); 5539c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5549c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5559c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 556a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 557a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 558a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Level = level; 559a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Face = face; 560fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 561fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 562fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 563a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 566a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 567a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 5706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 57177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 57277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 573f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 57477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 575a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 57677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 57777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 57877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 57977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 580a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 581146f536b3332b7a2022bb4ba5e2d1d2ec4bedd98Brian Paul * Free a gl_texture_image and associated data. 582146f536b3332b7a2022bb4ba5e2d1d2ec4bedd98Brian Paul * This function is a fallback called via ctx->Driver.DeleteTextureImage(). 5836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5841eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 5856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5863e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 587a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 58877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 5893c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 5903c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 59177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 5925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 5935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 5945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 5950bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ASSERT(ctx->Driver.FreeTextureImageBuffer); 5960bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 59777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 59877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 59977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 606aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 60777ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 60877ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 609aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 610874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* NUM_TEXTURE_TARGETS should match number of terms below, 611874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * except there's no proxy for GL_TEXTURE_BUFFER. 612874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 613874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul assert(NUM_TEXTURE_TARGETS == 8); 6142465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 61827f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 619bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 620bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 621bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 622aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 623aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 624aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 62635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target 62735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 62835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum 62935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target) 63035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{ 63135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul switch (target) { 63235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D: 63335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D: 63435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D; 63535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D: 63635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D: 63735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D; 63835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_3D: 63935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_3D: 64035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_3D; 64135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 64235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 64335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 64435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 64535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 64635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 64735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 64835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 64935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_CUBE_MAP_ARB; 65035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_RECTANGLE_NV: 65135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 65235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_RECTANGLE_NV; 65335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 65435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 65535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D_ARRAY_EXT; 65635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 65735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 65835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D_ARRAY_EXT; 65935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul default: 66035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul _mesa_problem(NULL, "unexpected target in get_proxy_target()"); 66135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return 0; 66235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul } 66335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul} 66435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 66535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 66635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/** 6673c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 668120d71a45cfda1edfa8cd6b1732e209eb98b53d8Brian Paul * texture unit. The target should have already been checked for validity. 6696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 6716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 6726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 67535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 67635d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 6773c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 6783c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 67935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 68035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 681f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array || 682f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 683f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul 68435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 68535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 6869818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 68735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 688fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 68935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 6909818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 69135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 692fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 69335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 6949818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 69535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 696fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 69735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 69835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 69935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 70035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 70135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 70235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7035ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 704a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7059818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 70635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 707a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 708fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7098afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7108afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7119818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7128afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7138afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 714fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 715bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 716f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 717bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 718f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 719bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 720f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 721bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 722f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 723874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 724874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return ctx->Extensions.ARB_texture_buffer_object 725874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL; 72635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 72708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 72835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 72935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 73135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 73235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 734b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 735b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 736b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 737f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 738b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 739b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 740b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 741b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 742b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 743b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 744b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 745c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 746c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 747c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7501eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 754c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 755fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 756fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 7573c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 7583c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 7595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 760fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 761c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 7625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 763c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 764c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 765c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 766bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 767c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 768fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 769fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 770fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 771a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 772a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 773a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 774a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 775a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 776a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 777f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 778a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 779a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 780a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 7815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 7825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 7835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 7845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 7855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 786a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 787a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 788a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 789a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 790a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 791a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 7925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 793a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_set_tex_image(texObj, target, level, texImage); 794a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 7955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 796a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 797a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 798a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 799a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 800a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 801a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 802a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 803a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 804a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 805a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 806a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 807f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 808a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 81080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 811a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 812a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level < 0 ) 813a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 818a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 81980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 82080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 82480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 82580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 827a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 828a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 82980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 83080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 83480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 83580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 838a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 83980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 84080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 841bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 842bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 843bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 84480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 84580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 846bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 847bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 848bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 84980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 85080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 852a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 853a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 85480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 85580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 85680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 85780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 85880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 85980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 86080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 86180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 86280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 86380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 86480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 86580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 86680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 867a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 868a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 8706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 8716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 8726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 8746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 8756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 8776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 8786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 8796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 880ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 881ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 882f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 883ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 884ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 885ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 886ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 887ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 888ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 889ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 890ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 891ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 892ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 893ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 894ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 895ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 896ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 897ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 898ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 899add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 900ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 901fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 902fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 903ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 904ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 905fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 906fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 907fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 908fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 909fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 910f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 911f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array) 912fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 913874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 914874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 915ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 916ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 917ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 918ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 919ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 920ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 92183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9225e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 92383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 924a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 925a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 92683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 92783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 92883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 92983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 93083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 93183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 93283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 93383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 93483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 93583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 93683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 93783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 93883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 93983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 94083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 94183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 94283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9435e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9445e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 94583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 94683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 94783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9485e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9495e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 95083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 951874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 952874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 95383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 95483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 95583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 95683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 95783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 95883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 95983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 96083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 96183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 962fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 96362c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 964f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 965afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 966afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 9678e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 968afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9698e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 9708e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 971afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 9728e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 9738e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 9748e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 975afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 976a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 977afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 978afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 980afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 981afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 9828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 98365d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 984afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 985afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 987afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 988afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 990afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 991afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 992afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 993afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 9948e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 9958e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 9968e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 9978e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 9988e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 9998e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10008e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10018e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1005afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1007afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1008afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1009a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 101362c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1017738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1018f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero. 10196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure. 10216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10229c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the 10239c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero. 1024f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all 1025f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D 1026f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions. 10279c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10289c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1029f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10309c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10319c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1032a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1033a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10349c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10359c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10369c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10379c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 10389c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10399c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10409c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10419c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10429c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10439c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10441f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10459c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10469c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10479c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10496628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1052b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc). 10536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 10546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 10556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 10566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 10576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 10586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 105983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 10606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1062887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 10636628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 10643893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1065f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target, 10663893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 10673893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 106883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 106983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 10706628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 10716628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 10728bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 10738bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 10748bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1075b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1076a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1077a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1078a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 10796628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 10806628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 10816628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 10826628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1083c813b545ab4726fc5030f123ec6255224d64ad82Brian 10844d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 1085b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->WidthLog2 = _mesa_logbase2(img->Width2); 1086c813b545ab4726fc5030f123ec6255224d64ad82Brian 1087c813b545ab4726fc5030f123ec6255224d64ad82Brian if (height == 1) { /* 1-D texture */ 1088c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = 1; 10896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1090c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1091c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1092c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1093b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->HeightLog2 = _mesa_logbase2(img->Height2); 1094c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1095c813b545ab4726fc5030f123ec6255224d64ad82Brian 1096c813b545ab4726fc5030f123ec6255224d64ad82Brian if (depth == 1) { /* 2-D texture */ 1097c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = 1; 10986628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1099c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1100c813b545ab4726fc5030f123ec6255224d64ad82Brian else { 1101c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 1102b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->DepthLog2 = _mesa_logbase2(img->Depth2); 1103c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1104c813b545ab4726fc5030f123ec6255224d64ad82Brian 11056628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 1106c813b545ab4726fc5030f123ec6255224d64ad82Brian 110783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 11086628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11096628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11106628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1111738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 111242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 111342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 111442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 111542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 111642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 111742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 111842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 111942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 112042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 11213c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 11223c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 112342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 11240bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 112542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 112642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 112742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 112842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 112942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1130738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1131738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1132738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1133738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1134738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1135738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1136aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1137aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1138aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1139aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1140738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1141738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1142738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1143738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1144738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1145738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1146738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1147738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1148738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1149738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1150738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1151738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1152738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1153738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1154f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1155738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1156738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1157738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1158738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 11599c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1160738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1161738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1162738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1163738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1164738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1165738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1166738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1167c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1168738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1169c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1170c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1171c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1172c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1173c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1174738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1175738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1176c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1177738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1178738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1179c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1180c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1181c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1182738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1183c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1184c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1185c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1186c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1187c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1188c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1189c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1190738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1191738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1192c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1193738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1194738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1195c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1196c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1197c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1198738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1199c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 2 * border || depth > 2 + maxSize) 1200c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1201c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1202c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1203c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1204c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1205c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1206c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1207c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1208c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1209c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1210738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1211738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1212c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1214c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1215c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1216c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1217c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1218c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1219c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1220738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1222c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1225c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1226c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1227c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1228c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1229c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1231c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1232c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1233c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1234c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1235c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1238c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1239bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1240bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1241c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1242bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1243c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1244bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1245c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1246c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1247c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1248c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1249c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1250bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1251bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1252c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1253bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1254bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1255c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 2 * border || width > 2 + maxSize) 1256bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 2 * border || height > 2 + maxSize) 1258c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1259c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1260bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1262c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1263c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1265c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1267c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1268bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1269bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1271738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1273738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1274738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1277738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 12794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 12804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 12814b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 12824b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 12834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 12844b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 12854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 12864b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 12874b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 12884b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 12894b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 12904b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 12914b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 12924b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 12934b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 12944b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 12954b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 12964b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 12977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 12987404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1299064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1300064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13017404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13027404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1303064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13047404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 13057404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1306646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1307646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1308646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 13097404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1310646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1311646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1312646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1313646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1314646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1315646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1316646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1317646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1318646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1319646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1320f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1321684c66bb8b8cdaa7fc18b64a6f739ad70a10cd54Brian Paul ctx->Extensions.EXT_texture_array); 1322646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1323646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1324646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1325064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1326064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1327064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1328064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1329d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1330d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1331d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1332d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1333d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1334d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1335d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1336d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1337d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1338d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1339d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1340d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1341d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1342d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1343d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1344d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1345d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1346d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1347d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D: 1348d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1349d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1350d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1351d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1352d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1353d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1354d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1355d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1356d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1357d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1358d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1359d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.NV_texture_rectangle; 1360d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1361d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1362f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1363f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1364d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1365d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1366d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1367d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1368d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1369d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1370d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_3D: 1371d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1372d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1373d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1374f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1375f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 1376d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1377d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1378d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1379d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1380d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1381d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1382d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1383d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1384d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1385d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1386d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 138711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 138809a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 138909a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 139009a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 139111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 139211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 139309a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 139411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 139511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 139611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 139711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return target == GL_TEXTURE_1D; 139811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 139911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 140011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 140111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 140211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 140311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 140411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 140511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 140611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 140711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 140811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 140911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 141011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.NV_texture_rectangle; 141111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1412f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1413f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 141411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 141511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 141611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 141709a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 141809a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 141909a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 142009a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 142109a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1422f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1423f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 142409a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 142509a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 142609a5e028a6d254f619132e302a96c8535018603dBrian Paul } 142711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 142809a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 142909a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 143011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 143111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 143211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 143311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 143411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 143511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 14366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 14376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 143985288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 14406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 14416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 14426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 14436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 14446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 14456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 14466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 14476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 14486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 14496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 14516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 14526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 14533c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 14543c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1455afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1456c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 145785288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 145885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1459c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1460c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1461c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1462c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1463afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 146435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 146535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1466e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1467eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick GLboolean colorFormat; 1468eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick 1469eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick /* Even though there are no color-index textures, we still have to support 1470eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick * uploading color-index data and remapping it to RGB via the 1471eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick * GL_PIXEL_MAP_I_TO_[RGBA] tables. 1472eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick */ 1473eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick const GLboolean indexFormat = (format == GL_COLOR_INDEX); 1474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1475738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1476738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1477738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1478738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1479738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 14808afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1481738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1482738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1483738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1484738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1485738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1486738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1487738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1488738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1489738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1490738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1491738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1492738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1493738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1494738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1495973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1496f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1497f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1498973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1499f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1500f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1501f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1502f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 150335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 150435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 150535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1507d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 150835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 150935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 151035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 151135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 151235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1513e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1514e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1515e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1516738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1517c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15184e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1519738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1520738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1521c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1522afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1523afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1525738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 152689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1527c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 15284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1529a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1530a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1531c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1535738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1536f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1537326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* Normally, GL_INVALID_OPERATION is generated by a format/type 1538326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the 1539326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_EXT_texture_integer extension, some combinations should generate 1540326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * GL_INVALID_ENUM instead (grr!). 154138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes */ 154238f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1543326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1544326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_ENUM : GL_INVALID_OPERATION; 1545326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 15468a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 15478a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1548c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 154938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1551afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1552601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 155322e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 155422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1555ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1556ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1557ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1558ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1559601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1560601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 15618a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 15628a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1563601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1564601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1565601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1566601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1567601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1568c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1569601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1570601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1571c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1572fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 15732236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1574c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1575c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1576c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1577d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1578d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1579d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1580d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1581d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1582d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1583d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1584d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1585d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1586d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1587d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1588fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 15892236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1590fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1591c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1592d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1593d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1594d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1595c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1596c5b995066020191982b2315fc45d05e068eee761Brian Paul 1597601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1598601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 1599753660780a84187043d0dc4b0e0f449786862182Brian Paul /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */ 1600601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1601601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1602601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 16032b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 1604753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_1D_ARRAY && 1605753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_1D_ARRAY && 1606753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_2D_ARRAY && 1607753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_2D_ARRAY && 16082b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 16092b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_RECTANGLE_ARB) { 1610601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1611601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1612601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1613601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1614601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1615601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1616601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1617601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1618c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 16197404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 16207404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 16217404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 16227404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1623064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 162489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 162589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 162689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 162789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 16288978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 162989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 163189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 163389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1634326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 1635326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (ctx->Extensions.EXT_texture_integer && 1636326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul (_mesa_is_integer_format(format) != 1637326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_is_integer_format(internalFormat))) { 1638326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1639326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1640326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1641326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1642326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1643326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1644326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1645326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1650afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 16516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1652c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 16536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16546dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 16556dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 16566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 16576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 16586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 16596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 16606dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 16616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 16626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 16636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 16646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 16656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 16666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 16686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 16703c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 16713c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1672afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1673c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1674f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1675c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1676c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1677c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1678c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1680738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1681738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 16824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1683c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1684c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1685afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 168645124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1687c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 16884e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 16894e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1690c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1691c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1692c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 16934e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 16944e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1695c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1696c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1697c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1698738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1699738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1700c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1701c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 17035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!_mesa_is_legal_format_and_type(ctx, format, type)) { 1704326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* As with the glTexImage2D check above, the error code here 1705326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * depends on texture integer. 1706326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 1707326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul GLenum error = _mesa_is_integer_format(format) 1708326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul ? GL_INVALID_OPERATION : GL_INVALID_ENUM; 1709326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, error, 17108a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 17118a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 17125ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 17135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 17145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 17155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 17165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1717f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1718d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1719d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1720d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1721d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1722d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 17235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1724f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 17255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 17265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 17275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 17285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 17295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 17305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1731c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1732738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1733738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1734c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1735c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1737c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1738738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1739738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1740c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1742c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1743738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1744738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1745c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1746c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1747c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 1748c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)destTex->Border)) { 1749738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1750738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1751c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1752afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1753c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { 1754738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1755738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1756c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1759c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 1760c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)destTex->Border)) { 176108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 1762c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1763c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 176438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) { 176508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 1766c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1770b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 1771d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 1772d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1773d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 1774d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 1775d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1776d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 1777d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 1778e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17798978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 1780d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 1781e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 1782e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1783d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 1784d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 1785e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17868978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 1787e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 178889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1789d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 179089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17918978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 179289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 179389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1794e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 1795e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 1796c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1797c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1798afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1801c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 18026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 18086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 18116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18153c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 18163c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1818c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1819f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 1820c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 1821c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 1822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 182311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 182411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 1825738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 1826e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul GLint baseFormat; 1827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 182811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 182909a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 183011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 183111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 183211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 183311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 183411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1835738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1836738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 18375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 18385ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 18395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 18405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 18415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 184234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 184334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 1844b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 1845b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 1846b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 184734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 184834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 184934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 185034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 185134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 185234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 185334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 1854738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1855738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 1856738318bb75dea8dac4465f53850987f6062a732dBrian Paul ((target == GL_TEXTURE_RECTANGLE_NV || 1857738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1858738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1859738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1860738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1861e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul baseFormat = _mesa_base_tex_format(ctx, internalFormat); 1862e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul if (baseFormat < 0) { 18630899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 18640899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 18650899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 18660899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 18670899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 1868e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul if (!_mesa_source_buffer_exists(ctx, baseFormat)) { 186934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 187034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 187134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 187234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 187334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 187411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 187511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 187611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 1877738318bb75dea8dac4465f53850987f6062a732dBrian Paul 187811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1879e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul internalFormat, baseFormat, 188011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 188111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 1882c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1883738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1884738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 18854e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1886738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 1887c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1888738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 1889738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 1890738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1891738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 1892ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 1893c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1894c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1895c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1896c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (_mesa_is_compressed_format(ctx, internalFormat)) { 18977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 189889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 18992236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 190089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 190189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 190289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 190389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 19048978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 19050899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 19060899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 19070899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 190889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1909c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 1910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 1911c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 1912c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1913c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 19146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 191534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 19169dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 19179dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 19186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 19206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 19216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 19226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 19236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 19246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 19256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 1926c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1927f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 19289dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 1929c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 193034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 193134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->Name) { 1932b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 1933b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 1934b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 193534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 193634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 193734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 193834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 193934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 194034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 194134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 19421c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 194309a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 19441c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 19451c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 19461c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 1947c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1948c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 1949738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 1950738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 19514e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19524e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 1953c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1954c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1955c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 19565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 19575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 19585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 19599dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 19609dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 19619dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 19629dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 19639dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 19649dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 19659dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 19669dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 19679dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 19685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1969f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 19705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 19715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 19725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 19735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 19745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 19759dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 1976c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 19774e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1978b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 1979b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 1980c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1981c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1982c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 19839dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 19849dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 19859dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19869dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 19879dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 19889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 19899dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 19909dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19919dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 19929dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 19939dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 19949dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 19959dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 1996c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 19974e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19984e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 1999c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2000c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 200138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 20024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20034e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2004c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2005c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2006c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 2007c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (yoffset < -((GLint)teximage->Border)) { 20084e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20094e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2010c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2011c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2012c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 201338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) { 20144e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20154e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2016c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2017c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2018c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2019c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20209dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2021c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 2022c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (zoffset < -((GLint)teximage->Border)) { 20234e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20244e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2025c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2026c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 202738f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (zoffset > (GLint) (teximage->Depth + teximage->Border)) { 20284e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20294e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2030c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2031c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2032c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2033c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2034b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 203589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 203689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 203789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20388978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2039e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2040e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 204189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2042798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 204389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20448978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2045e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 204689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2047798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 204889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 20498978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 205089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 205189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2052e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2053e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2054a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2055d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2056d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2057d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2058d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2059985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2060985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2061803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2062803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2063985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2064985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2065985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2066326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* If copying into an integer texture, the source buffer must also be 2067326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul * integer-valued. 2068326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2069412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (_mesa_is_format_integer_color(teximage->TexFormat)) { 2070326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2071412b9608838b872bc294569b3ee913343a7e66f6Brian Paul if (!_mesa_is_format_integer_color(rb->Format)) { 2072326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2073326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glCopyTexSubImage%dD(source buffer is not integer format)", 2074326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 2075326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 2076326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2077326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2078326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2079c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2080c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2081c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2082c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2083c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 20842897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 20852897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 20862897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2087f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 20882897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 20892897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 20902897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 20912897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 20928e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2093519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 20942897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2095519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2096519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 20972897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2098519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 20992897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 21002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2101f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 21022897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 21032897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 21042897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21052897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 21062897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (fb->Name) { 2107519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 21082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2109519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 21102897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2111519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2112519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2113519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2114519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2115db0f9e701d59dcfcd3b50f4d245897692f27fec9Brian Paul ASSERT(_mesa_get_attachment_teximage(att)); 2116519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2117ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 21182897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 21192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2120519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2121519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2122519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2123519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2124519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2125519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 21262897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 21272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 21282897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 21292897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 21302897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 21312897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 21322897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void 2133f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj, 21342897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint face, GLuint level) 21352897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 21362897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 21372897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 21382897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 21392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 21402897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 21412897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 21422897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 21432897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 21442897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 21452897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 21462897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21472897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 21482914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 21492914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 21502914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 21512914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 21522914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 21539520f483b8f1e45fa474674b415554988de5d8d3Brian Paulstatic inline void 2154f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 21552914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 21562914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 21572914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2158ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2159ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2160ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 21612914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 21622914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 21632914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 21642914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 21652914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 21662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 21671826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 21681826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 21691826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 21701826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 21711826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 21721826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 21731826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 21741826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 21751826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 21761826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 21771826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 21781826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 21791826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 21801826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 21811826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 21821826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 21831826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 21841826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 21851826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 21861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 21871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 21881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 21891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 21901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 21911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 21921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 21931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 21941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 21951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 21961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 21971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 21981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 21991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 22001826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22011826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 22021826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 22031826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22041826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 22051826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 22061826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 22071826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 22081826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 22091826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2210519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2211bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2212bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2213bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2214bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2215bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2216bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2217bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2218bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 221983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2220f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2221bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2222bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2223bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2224bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 222583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 222683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2227bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2228bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2229bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2230bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2231bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2232bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2233bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2234bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2235bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2236bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2237bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 223883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 223983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2240bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2241bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2242bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2243bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 224483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 224583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 224683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2247bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2248bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 22499c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt/** 22509c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * Adjust pixel unpack params and image dimensions to strip off the 22519c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * texture border. 22529c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * 22539c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * Gallium and intel don't support texture borders. They've seldem been used 22549c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * and seldom been implemented correctly anyway. 22559c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * 22569c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * \param unpackNew returns the new pixel unpack parameters 22579c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt */ 22589c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholtstatic void 22599c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholtstrip_texture_border(GLint *border, 22609c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt GLint *width, GLint *height, GLint *depth, 22619c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt const struct gl_pixelstore_attrib *unpack, 22629c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt struct gl_pixelstore_attrib *unpackNew) 22639c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt{ 22649c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt assert(*border > 0); /* sanity check */ 22659c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 22669c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *unpackNew = *unpack; 22679c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 22689c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (unpackNew->RowLength == 0) 22699c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->RowLength = *width; 22709c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 22719c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (depth && unpackNew->ImageHeight == 0) 22729c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->ImageHeight = *height; 22739c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 22749c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->SkipPixels += *border; 22759c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (height) 22769c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->SkipRows += *border; 22779c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (depth) 22789c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->SkipImages += *border; 22799c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 22809c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt assert(*width >= 3); 22819c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *width = *width - 2 * *border; 22829c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (height && *height >= 3) 22839c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *height = *height - 2 * *border; 22849c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (depth && *depth >= 3) 22859c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *depth = *depth - 2 * *border; 22869c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *border = 0; 22879c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt} 2288bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2289d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2290d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2291c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2292d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2293d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2294d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2295d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2296d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2297d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2298c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2299d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 23009c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt struct gl_pixelstore_attrib unpack_no_border; 23019c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; 2302d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2303cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2304c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2305d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2306d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2307d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2308d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2309d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2310d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2311d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2312d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2313d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2314d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 231511caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2316d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2317d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2318d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2319d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2320d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2321d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2322ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2323d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2324d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2325d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 23262914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2327d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2328d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2329d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2330d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 233162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2332d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2333738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2334a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2335a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2336c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 233789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 233889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2339bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2340bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2341d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2342d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 234383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 234483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2345d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2346d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2347d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 2348d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2349d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 23504b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 23514b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 23524b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 23534b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 235489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2355c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2356c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 23578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2358d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 23590293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 23600293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2361f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2362d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 23638e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2364c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2365c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 23669c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt /* Allow a hardware driver to just strip out the border, to provide 23679c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * reliable but slightly incorrect hardware rendering instead of 23689c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * rarely-tested software fallback rendering. 23699c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt */ 23709c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (border && ctx->Const.StripTextureBorder) { 23719c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt strip_texture_border(&border, &width, &height, &depth, unpack, 23729c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt &unpack_no_border); 23739c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpack = &unpack_no_border; 23749c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt } 23759c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 23767ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 23775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2378fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2379b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2380d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 23815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 23825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 23835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2384d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 23855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2386d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 23875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2388ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 238983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 239083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 239168f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 2392ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 239383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 239483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 239583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 239683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 2399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2400d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 240111caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 24024b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2403d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ASSERT(ctx->Driver.TexImage3D); 2404d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 2405d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 2406d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 2407d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, border, format, 24089c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt type, pixels, unpack, texObj, 2409d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 2412d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 2413d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, border, format, 24149c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt type, pixels, unpack, texObj, 2415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 2418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul ctx->Driver.TexImage3D(ctx, target, level, internalFormat, 2419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, format, 24209c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt type, pixels, unpack, texObj, 2421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texImage); 2422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul break; 2423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 2424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in teximage()", dims); 2425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2426ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24274b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 24282914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 24294b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2430ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 24314b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 24324b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 24334b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 24344b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 24354b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 24374b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2438ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2439ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 24405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2441afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2443d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2444d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2446d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2447d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2453d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2463d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2464d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2468afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2469afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2470afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2471afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2472afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2473afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2474afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2475c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2476b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2477fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2478fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2479fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2481fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2484afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2485afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2486afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2487c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 248843911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2489663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2490663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2491663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2492663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 249389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2494663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2495663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2496663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2497663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2498d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2499d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2500d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2501d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2502d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2503d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 250417efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 250517efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2506d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25072002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu if (!ctx->Extensions.OES_EGL_image) { 25082002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 25092002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu "glEGLImageTargetTexture2DOES(unsupported)"); 25102002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu return; 25112002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu } 25122002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu 2513d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (target != GL_TEXTURE_2D) { 2514d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2515d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2516d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2517d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2518d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 25197ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 2520d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2521d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2522d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2523d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2524d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2525d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2526d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2527d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2528d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 252968f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 2530d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2531d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2532d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2533d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2534d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg /* state update */ 2535d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj->_Complete = GL_FALSE; 2536d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->NewState |= _NEW_TEXTURE; 2537d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2538d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2539d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2540d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2541d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2542d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2543afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 254445124e043da5a67e1081526d61b99422f4ccde19Brian Paul 254545124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 254645124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 254745124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 254845124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 254945124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 255045124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 255145124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 255245124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 25540293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2555b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 255645124e043da5a67e1081526d61b99422f4ccde19Brian Paul 255775280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 255875280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2559d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 256045124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 256145124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2562d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 256345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 256445124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2565d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2566d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 256745124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 256809a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 256945124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 257045124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 257145124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 257245124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 257345124e043da5a67e1081526d61b99422f4ccde19Brian Paul 25747ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 257508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 25762aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 257745124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 257845124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2579f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2580afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2581afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2582b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 25845ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 25855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 25865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2587afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 258845124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 258945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 259045124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 259145124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2592a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 25935ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 25944609e80288bacf19af99b0ed7656eef9bb280912Brian Paul else if (width > 0 && height > 0 && depth > 0) { 259545124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 259645124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 259745124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 259845124e043da5a67e1081526d61b99422f4ccde19Brian Paul zoffset += texImage->Border; 259945124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 260045124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 260145124e043da5a67e1081526d61b99422f4ccde19Brian Paul yoffset += texImage->Border; 260245124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 260345124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 260445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 260545124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2606347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 260745124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 260845124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 260945124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage1D(ctx, target, level, 261045124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, width, 261145124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 261245124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 261345124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 261445124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 261545124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage2D(ctx, target, level, 261645124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, width, height, 261745124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 261845124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 261945124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 262045124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 262145124e043da5a67e1081526d61b99422f4ccde19Brian Paul ctx->Driver.TexSubImage3D(ctx, target, level, 262245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 262345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 262445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels, 262545124e043da5a67e1081526d61b99422f4ccde19Brian Paul &ctx->Unpack, texObj, texImage ); 262645124e043da5a67e1081526d61b99422f4ccde19Brian Paul break; 262745124e043da5a67e1081526d61b99422f4ccde19Brian Paul default: 262845124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_problem(ctx, "unexpected dims in subteximage()"); 262945124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 26302914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 26312914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 26322914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2633ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2634ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 26355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 26365ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2638afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2639afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2640c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 264145124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 264245124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 264345124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 264445124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 264545124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 264645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 264745124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 264845124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 264945124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 265045124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 265145124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 265245124e043da5a67e1081526d61b99422f4ccde19Brian Paul 265345124e043da5a67e1081526d61b99422f4ccde19Brian Paul 265445124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2655fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2656fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2657fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2658fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2659fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26612c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 266245124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 266345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 266545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2666c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2667afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2668afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2669afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2670c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2671fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2672fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2673fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2674fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2675fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26772c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 267945124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 268145124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2682afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2683afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2684afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2685afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 268611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 268711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 268811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 268911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 269011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 269111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 269211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 2693afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 26942aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 26952aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 2696e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 269711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2698cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2700d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 270111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 270211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 2703d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2704d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 270511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2706d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 270763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 270808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2709fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 271011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 271111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 2712ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2713ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2714b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2715a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 2716638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt if (border && ctx->Const.StripTextureBorder) { 2717638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt x += border; 2718638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt width -= border * 2; 2719638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt if (dims == 2) { 2720638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt y += border; 2721638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt height -= border * 2; 2722638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt } 2723638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt border = 0; 2724638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt } 2725638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt 27265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27275ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 272911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 27305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 273111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2733c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 27345874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* choose actual hw format */ 27355874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 27365874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul target, level, 27375874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul internalFormat, 27385874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GL_NONE, GL_NONE); 27397dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 27405874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 27415874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GLint srcX = x, srcY = y, dstX = 0, dstY = 0; 27427dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 27435874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Free old texture image */ 27440bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 27452aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 274611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, 27474b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 274811caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 27495874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Allocate texture memory (no pixel data yet) */ 27505874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) { 27515874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage1D(ctx, target, level, internalFormat, 27525874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, border, GL_NONE, GL_NONE, NULL, 27535874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &ctx->Unpack, texObj, texImage); 27545874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 27555874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else { 27565874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.TexImage2D(ctx, target, level, internalFormat, 27575874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul width, height, border, GL_NONE, GL_NONE, 27585874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul NULL, &ctx->Unpack, texObj, texImage); 27595874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 27605874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 27615874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (_mesa_clip_copytexsubimage(ctx, &dstX, &dstY, &srcX, &srcY, 27625874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &width, &height)) { 27635874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (dims == 1) 27645874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, dstX, 27655874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width); 27665874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 27675874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul else 27685874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, dstX, dstY, 27695874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul srcX, srcY, width, height); 27705874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 27712aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 27724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 27732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 27744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul update_fbo_texture(ctx, texObj, face, level); 2775519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 27764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 27774b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 27784b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 27794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 27804b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 27815874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* probably too large of image */ 278211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 27834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2784c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 27855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 27865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2789afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2790afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2791c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 279211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 279311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 279411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 279511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 2796afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2797fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 279811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 279911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 2800c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 28012914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2802c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 280311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 280411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 280511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 280611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 280711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 280811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 280911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 281011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 2811afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2812afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2813afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28141c23b860cea93534f726d2a18658444f37f43538Brian Paul 28151c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 28161c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 28171c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 28181c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 28191c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 28201c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 28211c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 2822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 2824347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 282503bafd1f9fa000abdb794b2ae344a68840c83201Brian 2826cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2828d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 28291c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 28301c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 2831d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 28321c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 2833d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 283463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 283508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 2836fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 28371c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 2838ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 2839ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 2840b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 28415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 28455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 28461c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 28471c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 28481c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 284903bafd1f9fa000abdb794b2ae344a68840c83201Brian } 2850a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 28511c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 28521c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 28531c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 28541c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset += texImage->Border; 28551c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28561c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 28571c23b860cea93534f726d2a18658444f37f43538Brian Paul yoffset += texImage->Border; 28581c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 28591c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 28601c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 28611c23b860cea93534f726d2a18658444f37f43538Brian Paul } 286203bafd1f9fa000abdb794b2ae344a68840c83201Brian 2863a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 2864a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 28651c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 28661c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 28671c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage1D(ctx, target, level, 28681c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, x, y, width); 28691c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28701c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 28711c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage2D(ctx, target, level, 28721c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, 28731c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 28741c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28751c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 28761c23b860cea93534f726d2a18658444f37f43538Brian Paul ctx->Driver.CopyTexSubImage3D(ctx, target, level, 28771c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset, yoffset, zoffset, 28781c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 28791c23b860cea93534f726d2a18658444f37f43538Brian Paul break; 28801c23b860cea93534f726d2a18658444f37f43538Brian Paul default: 28811c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_problem(ctx, "bad dims in copytexsubimage()"); 28821c23b860cea93534f726d2a18658444f37f43538Brian Paul } 28832914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 28842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 28852914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2886a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 2887a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 2888a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 28895ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 28905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2891afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2892afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2893afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28941c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 28951c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 28961c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 28971c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 28981c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 28991c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 29001c23b860cea93534f726d2a18658444f37f43538Brian Paul} 29011c23b860cea93534f726d2a18658444f37f43538Brian Paul 29021c23b860cea93534f726d2a18658444f37f43538Brian Paul 2903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2904c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2905fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 2906fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2907fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2908afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2909fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29101c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 29111c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 2912afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2913afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2914afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2915afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2916c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2917fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 2918fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2919fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 2920afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2921fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 29221c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 29231c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 2924afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 29251207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29261207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 29271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 292889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 292989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 293089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 293189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 293289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 293389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 293489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 293554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 293654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 293754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 293854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 293954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 294054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 294154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 294254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 294354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 294454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 294554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 294607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 294707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 294807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 294907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 295007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 295107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 295207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 295307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 295407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 295554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 295654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 295754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 295889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 2959d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch * \param reason returns reason for error, if any 296089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 296189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 296289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 2963f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 296489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 296589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 296689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 2967d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch GLsizei imageSize, char **reason) 296889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 29694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 29704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 29714ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 29723ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum choose_format; 29733ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum choose_type; 29743ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum proxy_format; 297589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2976d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = ""; /* no error */ 2977d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch 29787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 2979d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "target"; 29807404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 29817404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 29827404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 2983c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 2984d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (!_mesa_is_compressed_format(ctx, internalFormat)) { 2985d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 298689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 2987d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 298889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 29893ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick switch (internalFormat) { 29903ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick#if FEATURE_ES 29913ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGB8_OES: 29923ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGBA8_OES: 29933ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_R5_G6_B5_OES: 29943ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGBA4_OES: 29953ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGB5_A1_OES: 29963ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGB8_OES: 29973ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGBA8_OES: 29983ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_R5_G6_B5_OES: 29993ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGBA4_OES: 30003ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGB5_A1_OES: 30013ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick _mesa_cpal_compressed_format_type(internalFormat, &choose_format, 30023ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick &choose_type); 30033ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format = choose_format; 30043ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30053ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* check level */ 30063ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (level > 0 || level < -maxLevels) { 30073ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "level"; 30083ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_VALUE; 30093ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 30103ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30113ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (dimensions != 2) { 30123ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "compressed paletted textures must be 2D"; 30133ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_OPERATION; 30143ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 30153ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30163ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* Figure out the expected texture size (in bytes). This will be 30173ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * checked against the actual size later. 30183ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 30193ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick expectedSize = _mesa_cpal_compressed_size(level, internalFormat, 30203ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick width, height); 30213ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30223ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* This is for the benefit of the TestProxyTexImage below. It expects 30233ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * level to be non-negative. OES_compressed_paletted_texture uses a 30243ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * weird mechanism where the level specified to glCompressedTexImage2D 30253ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * is -(n-1) number of levels in the texture, and the data specifies the 30263ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * complete mipmap stack. This is done to ensure the palette is the 30273ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * same for all levels. 30283ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 30293ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick level = -level; 30303ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick break; 30313ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick#endif 30323ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30333ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick default: 30343ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_format = GL_NONE; 30353ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_type = GL_NONE; 30363ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format = internalFormat; 30373ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30383ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* check level */ 30393ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (level < 0 || level >= maxLevels) { 30403ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "level"; 30413ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_VALUE; 30423ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 30433ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 30443ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* Figure out the expected texture size (in bytes). This will be 30453ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * checked against the actual size later. 30463ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 30473ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick expectedSize = compressed_tex_size(width, height, depth, internalFormat); 30483ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick break; 30493ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 30503ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 3051c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3052d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 3053d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 3054a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3055d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 3056a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 30574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 3058d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (border != 0) { 3059d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "border != 0"; 306089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3061d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 306289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 306389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 306489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 3065d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) { 3066d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "width != height"; 306789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3068d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 306989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30707404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 30717404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 30727404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 30733ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick ctx->Driver.ChooseTextureFormat(ctx, proxy_format, 30743ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_format, choose_type); 30757404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 30767404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30777404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 30787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 30797404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 30807404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 30817404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 30827404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 30837404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 30847404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3085d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width or height for compression format"; 30867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 30897404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 30904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 30914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 30923ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format, choose_format, 30933ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_type, 30943ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick width, height, depth, border)) { 30957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 3096d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width, height or format"; 30977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 30984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 309989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 31004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 31017404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 31027404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 31037404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 31047404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 31057404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3106d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "imageSize inconsistant with width/height/format"; 310789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 31087404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 310989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 311189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 311289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 311489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 311589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 31162371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 31172371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 31182371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 311989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 312089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 312189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3122f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 312389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 312489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 312589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 312689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 312789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 312889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 312907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3130a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 313189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 313289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 313389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 313489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 313589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 313689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 313789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 313889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 313989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 314189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 314289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 314489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 314589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 314689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 314789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 314889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 314989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { 315089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 315189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 315389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 315589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 315689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 315889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 315989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 316089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 316189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 316289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 316389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 316489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3165c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3166c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 316789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 316889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3169887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 317089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3172887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 317389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 317489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 317689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 317789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 317889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 317907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 318007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 31812371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 318207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 318307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 318407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 318589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 318689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 318707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 318889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 318989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 319189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 319489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 319589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 319689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 319789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 319889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 319989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 320089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3201f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3202f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3203f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3204f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3205f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3206f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3207f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3208f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3209f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3210f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3211f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3212f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3213f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3214f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3215f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3216f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3217f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3218f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3219ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3220ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3221f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3222f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3223f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3224f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3225f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3226f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3227f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3228ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3229ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3230f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3231f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3232f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3233f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3234f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3235f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3236f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3237f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3238ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3239ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3240f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3241f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3242f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3243f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3244f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3245f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3246f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3247f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3248f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3249f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 32504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 32514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 32524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 32534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 32544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 32554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 32564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 32574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 32591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 32604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 3261d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch char *reason = ""; 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3263cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3264aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3265d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 32664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 32674ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 32684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3269d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3270d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 32714ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 32725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 32734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 32747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 32754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 32764ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3277aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3278aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 32791207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 32814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 3282d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch border, imageSize, &reason); 3283d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 32844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 3285ca7510bbf9bdff35f813f970e3120a9c7f728ccaBrian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD(%s)", dims, reason); 32867179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg return; 32877179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg } 32887179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg 3289af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul#if FEATURE_ES 3290af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul /* XXX this is kind of a hack */ 32914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (dims == 2) { 32924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 32934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 32944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 32954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 32964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 32974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 32984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 32994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 33004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 33014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 33024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 33034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 33044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 330589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3306aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3309aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 33104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 33114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 33124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 33132914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 33148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 33154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 33164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 33174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 33184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 33194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 33204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 33214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 33224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3323aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 33245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 33254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 33264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 33274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 33284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 33294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 33304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 33314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 33324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 33334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_init_teximage_fields(ctx, target, texImage, width, height, 33344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 33354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 33364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 333789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3338aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3339aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 33408c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3341aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3342aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 33434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 334489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 33454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD", dims); 334689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3347aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3348aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3349b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 33509519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 33515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 33525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 33535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 33545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 33554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 33564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 33575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3358c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 335983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 336083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 336168f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 3362c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 336383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 336483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 336583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 336683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 33674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 33684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul _mesa_init_teximage_fields(ctx, target, texImage, 33694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 33704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 337111caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 33724ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (dims) { 33734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 1: 33744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage1D); 33754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage1D(ctx, target, level, 33764ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 33784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 2: 33824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage2D); 33834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage2D(ctx, target, level, 33844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33854ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 33864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case 3: 33904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ASSERT(ctx->Driver.CompressedTexImage3D); 33914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul ctx->Driver.CompressedTexImage3D(ctx, target, level, 33924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, 33934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, 33944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul border, imageSize, data, 33954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texObj, texImage); 33964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul break; 33974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul default: 33984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_problem(ctx, "bad dims in compressedteximage"); 33994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3400c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34014b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 34022914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 34034b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* state update */ 34044b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul texObj->_Complete = GL_FALSE; 34054b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul ctx->NewState |= _NEW_TEXTURE; 34064b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 34074b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 34084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 34094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 34104b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3411c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3412c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3414aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 34154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34169519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34179519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 34184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 34204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 34224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 34264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 34274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 34324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 34344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 34354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 34384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 34394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 34404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 34424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 34434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 34444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 34454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 34464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 34474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 34484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 34494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 34504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 34511207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 34521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34531207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 34546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 34556bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 34566bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 34576bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 34586bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 34596bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 34606bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 34616bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 34621207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 34639540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 34649540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 346589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3466a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 346775280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 346875280a2c742ee241d392618a3b29548fce1520a9Brian Paul 34696bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3470c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 34716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3472c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 347389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 34746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 347589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 34769540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 34779540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3478b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3479c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 34805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 34815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 34825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 34835ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 34849540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 34856bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3486f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3487f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3488c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 34896bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 34906bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul switch (dims) { 34916bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 1: 34926bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage1D) { 34936bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage1D(ctx, target, level, 34946bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, width, 34956bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 34966bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 34976bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 34986bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 34996bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 2: 35006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage2D) { 35016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage2D(ctx, target, level, 35026bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, 35036bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 35046bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35066bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35076bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35086bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul case 3: 35096bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (ctx->Driver.CompressedTexSubImage3D) { 35106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ctx->Driver.CompressedTexSubImage3D(ctx, target, level, 35116bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul xoffset, yoffset, zoffset, 35126bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, 35136bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data, 35146bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul texObj, texImage); 35156bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul } 35166bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul break; 35176bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul default: 35186bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul ; 3519c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 35202914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35212914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 35222914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 35232914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 35245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 35259540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 35265ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 35271207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35281207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35291207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3530c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35316bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 35326bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 35336bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 35346bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 35356bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 35366bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 35376bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 35386bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35396bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 35406bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 35411207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 35421207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 35431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 35441207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 35451207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35466bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 35476bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 35481207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 35491207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35501207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3551c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 35521207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 35531207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 35541207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 35551207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 35561207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35576bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 35586bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 35591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3560874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3561874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3562874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** 3563874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * Helper for glTexBuffer(). Check if internalFormat is legal. If so, 3564874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * return the basic data type and number of components for the format. 3565874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise 3566874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 3567874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulstatic GLboolean 3568874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulget_sized_format_info(const struct gl_context *ctx, GLenum internalFormat, 3569874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum *datatype, GLuint *components) 3570874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3571874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul switch (internalFormat) { 3572874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8: 3573874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3574874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3575874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3576874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16: 3577874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3578874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3579874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3580874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16F_ARB: 3581874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3582874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3583874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3584874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32F_ARB: 3585874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3586874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3587874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3588874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8I_EXT: 3589874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3590874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3591874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3592874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16I_EXT: 3593874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3594874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3595874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3596874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32I_EXT: 3597874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3598874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3599874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3600874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8UI_EXT: 3601874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3602874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3603874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3604874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16UI_EXT: 3605874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3606874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3607874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3608874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32UI_EXT: 3609874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3610874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3611874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3612874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8: 3613874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3614874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3615874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3616874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16: 3617874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3618874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3619874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3620874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16F_ARB: 3621874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3622874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3623874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3624874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32F_ARB: 3625874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3626874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3627874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3628874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8I_EXT: 3629874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3630874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3631874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3632874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16I_EXT: 3633874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3634874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3635874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3636874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32I_EXT: 3637874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3638874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3639874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3640874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8UI_EXT: 3641874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3642874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3643874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3644874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16UI_EXT: 3645874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3646874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3647874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3648874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32UI_EXT: 3649874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3650874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3651874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3652874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8_ALPHA8: 3653874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3654874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3655874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3656874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16_ALPHA16: 3657874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3658874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3659874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3660874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 3661874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3662874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3663874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3664874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 3665874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3666874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3667874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3668874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 3669874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3670874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3671874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3672874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 3673874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3674874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3675874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3676874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 3677874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3678874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3679874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3680874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 3681874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3682874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3683874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3684874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 3685874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3686874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3687874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3688874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 3689874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3690874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 2; 3691874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3692874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8: 3693874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3694874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3695874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3696874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16: 3697874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3698874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3699874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3700874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16F_ARB: 3701874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3702874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3703874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3704874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32F_ARB: 3705874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3706874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3707874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3708874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8I_EXT: 3709874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3710874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3711874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3712874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16I_EXT: 3713874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3714874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3715874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3716874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32I_EXT: 3717874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3718874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3719874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3720874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8UI_EXT: 3721874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3722874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3723874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3724874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16UI_EXT: 3725874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3726874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3727874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3728874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32UI_EXT: 3729874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3730874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 1; 3731874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3732874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8: 3733874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3734874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3735874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3736874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16: 3737874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3738874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3739874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3740874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16F_ARB: 3741874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_HALF_FLOAT; 3742874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3743874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3744874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32F_ARB: 3745874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_FLOAT; 3746874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3747874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3748874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8I_EXT: 3749874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_BYTE; 3750874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3751874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3752874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16I_EXT: 3753874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_SHORT; 3754874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3755874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3756874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32I_EXT: 3757874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_INT; 3758874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3759874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3760874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8UI_EXT: 3761874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_BYTE; 3762874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3763874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3764874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16UI_EXT: 3765874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_SHORT; 3766874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3767874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3768874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32UI_EXT: 3769874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *datatype = GL_UNSIGNED_INT; 3770874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul *components = 4; 3771874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul break; 3772874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul default: 3773874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3774874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3775874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3776874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float) 3777874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3778874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3779874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (*datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel) 3780874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_FALSE; 3781874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3782874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return GL_TRUE; 3783874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3784874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3785874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3786874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** GL_ARB_texture_buffer_object */ 3787874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulvoid GLAPIENTRY 3788874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) 3789874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3790874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_texture_object *texObj; 3791874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_buffer_object *bufObj; 3792874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLenum dataType; 3793874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GLuint comps; 3794874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3795874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GET_CURRENT_CONTEXT(ctx); 3796874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3797874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3798874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!ctx->Extensions.ARB_texture_buffer_object) { 3799874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer"); 3800874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3801874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3802874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3803874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (target != GL_TEXTURE_BUFFER_ARB) { 3804874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)"); 3805874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3806874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3807874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3808874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!get_sized_format_info(ctx, internalFormat, &dataType, &comps)) { 3809874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)", 3810874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul internalFormat); 3811874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3812874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3813874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3814874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul bufObj = _mesa_lookup_bufferobj(ctx, buffer); 3815874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (buffer && !bufObj) { 3816874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer); 3817874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 3818874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3819874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3820874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3821874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3822874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_lock_texture(ctx, texObj); 3823874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul { 3824874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj); 3825874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj->BufferObjectFormat = internalFormat; 3826874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3827874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_unlock_texture(ctx, texObj); 3828874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3829