teximage.c revision 9848e86af0c937a6f7609289ab2705c3535f378f
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 31ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick#include <stdbool.h> 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" 46878c69fe540a73011b676ead33ac8d9b8c9e63aaBrian Paul#include "texobj.h" 47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h" 487179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h" 495e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 509ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen#include "glformats.h" 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 53409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick/* Inexplicably, GL_HALF_FLOAT_OES has a different value than GL_HALF_FLOAT. 54409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick */ 55409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick#ifndef GL_HALF_FLOAT_OES 56409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick#define GL_HALF_FLOAT_OES 0x8D61 57409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick#endif 58409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 594cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/** 6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls. 6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state 6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer). 6363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */ 647ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul#define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL) 6563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul 6863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/** 691749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format. 701749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 731749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 7789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 7889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the 7989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used. 80afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 81b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint 82f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) 83afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 841749a25ca889d514889b34cf6311c8014d97bf66Brian Paul switch (internalFormat) { 85afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA: 86afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA4: 87afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA8: 88afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA12: 89afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_ALPHA16: 90afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_ALPHA; 91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 1: 92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE: 93afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4: 94afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8: 95afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12: 96afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16: 97afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE; 98afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 2: 99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE_ALPHA: 100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE4_ALPHA4: 101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE6_ALPHA2: 102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE8_ALPHA8: 103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA4: 104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE12_ALPHA12: 105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_LUMINANCE16_ALPHA16: 106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_LUMINANCE_ALPHA; 107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY: 108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY4: 109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY8: 110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY12: 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_INTENSITY16: 112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_INTENSITY; 113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 3: 114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB: 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_R3_G3_B2: 116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB4: 117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5: 118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB8: 119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10: 120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB12: 121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB16: 122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGB; 123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case 4: 124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA: 125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA2: 126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA4: 127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB5_A1: 128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA8: 129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGB10_A2: 130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA12: 131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg case GL_RGBA16: 132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_RGBA; 133f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 134f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 135f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 136f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 13729386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0). 13829386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick */ 13909714c09a40501d82823e42f7461d7b8d7bf11c0Jordan Justen if (_mesa_is_gles(ctx)) { 140f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke switch (internalFormat) { 14129386d1f2d60e905d63f4c5f045ff3794b2ff99cIan Romanick case GL_BGRA: 142f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke return GL_RGBA; 143f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke default: 144f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke ; /* fallthrough */ 1451a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák } 1461a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák } 1471a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák 1481a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák if (ctx->Extensions.ARB_ES2_compatibility) { 1491a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák switch (internalFormat) { 1501a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák case GL_RGB565: 1511a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák return GL_RGB; 1521a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák default: 1531a06e8454ec714e950bc88882cd985534a18bf1fMarek Olšák ; /* fallthrough */ 154f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 155f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke } 156f1452844fe2522387bbc6633f22aec09b8a06204Benjamin Franzke 1574741dbcbbc2514de370a760f4b78a17491014555Ian Romanick if (ctx->Extensions.ARB_depth_texture) { 158f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 159f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_DEPTH_COMPONENT: 1604741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT16: 1614741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT24: 1624741dbcbbc2514de370a760f4b78a17491014555Ian Romanick case GL_DEPTH_COMPONENT32: 163f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul return GL_DEPTH_COMPONENT; 164f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 165f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 166f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 167f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 16889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 16933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick switch (internalFormat) { 17033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_ALPHA: 17133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_ALPHA; 17233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE: 17333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE; 17433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 17533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_LUMINANCE_ALPHA; 17633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_INTENSITY: 17733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_INTENSITY; 17833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGB: 17933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGB; 18033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick case GL_COMPRESSED_RGBA: 18133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick return GL_RGBA; 18233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick default: 18333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick ; /* fallthrough */ 184f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.TDFX_texture_compression_FXT1) { 187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 188f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 18989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGB; 190f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 19189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_RGBA; 192f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 193f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 194f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.EXT_texture_compression_s3tc) { 198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 1998f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 2008f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul return GL_RGB; 201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 202f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 203f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 20440bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca return GL_RGBA; 205f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 206f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.S3_s3tc) { 211f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 212f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB_S3TC: 213f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB4_S3TC: 214663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGB; 215f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA_S3TC: 216f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA4_S3TC: 217663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca return GL_RGBA; 218f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 219f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul ; /* fallthrough */ 220f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 221f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 22289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 223f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.MESA_ycbcr_texture) { 224f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (internalFormat == GL_YCBCR_MESA) 225f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_YCBCR_MESA; 226f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 2271749a25ca889d514889b34cf6311c8014d97bf66Brian Paul 228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul if (ctx->Extensions.ARB_texture_float) { 229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul switch (internalFormat) { 230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA16F_ARB: 231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_ALPHA32F_ARB: 232f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_ALPHA; 233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA16F_ARB: 234f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGBA32F_ARB: 235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGBA; 236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB16F_ARB: 237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_RGB32F_ARB: 238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_RGB; 239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY16F_ARB: 240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_INTENSITY32F_ARB: 241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_INTENSITY; 242f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE16F_ARB: 243f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE32F_ARB: 244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE; 245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 247f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return GL_LUMINANCE_ALPHA; 248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul default: 2498f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul ; /* fallthrough */ 250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul } 251afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul 253114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Extensions.ATI_envmap_bumpmap) { 254114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger switch (internalFormat) { 255114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DUDV_ATI: 256114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_DU8DV8_ATI: 257114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return GL_DUDV_ATI; 258114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger default: 259114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ; /* fallthrough */ 260114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 261114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 262114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 2630be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák if (ctx->Extensions.EXT_texture_snorm) { 264c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger switch (internalFormat) { 2650be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RED_SNORM: 2660be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R8_SNORM: 2670be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_R16_SNORM: 2680be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RED; 2690be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG_SNORM: 2700be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG8_SNORM: 2710be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RG16_SNORM: 2720be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RG; 2730be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB_SNORM: 2740be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB8_SNORM: 2750be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGB16_SNORM: 2760be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_RGB; 277c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA_SNORM: 278c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger case GL_RGBA8_SNORM: 2790be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_RGBA16_SNORM: 280c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger return GL_RGBA; 2810be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA_SNORM: 2820be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA8_SNORM: 2830be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_ALPHA16_SNORM: 2840be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_ALPHA; 2850be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_SNORM: 2860be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_SNORM: 2870be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_SNORM: 2880be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE; 2890be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE_ALPHA_SNORM: 2900be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE8_ALPHA8_SNORM: 2910be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_LUMINANCE16_ALPHA16_SNORM: 2920be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_LUMINANCE_ALPHA; 2930be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY_SNORM: 2940be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY8_SNORM: 2950be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák case GL_INTENSITY16_SNORM: 2960be369975fdfa79bcb702d0c13aa0a221055f61bMarek Olšák return GL_INTENSITY; 297c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger default: 298c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger ; /* fallthrough */ 299c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 300c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger } 301114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 3021ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul if (ctx->Extensions.EXT_packed_depth_stencil) { 3031ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul switch (internalFormat) { 3041ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH_STENCIL_EXT: 3051ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul case GL_DEPTH24_STENCIL8_EXT: 3061ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul return GL_DEPTH_STENCIL_EXT; 3071ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul default: 3081ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul ; /* fallthrough */ 3091ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3101ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul } 3111ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul 3120a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB 3130a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul if (ctx->Extensions.EXT_texture_sRGB) { 3140a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul switch (internalFormat) { 3150a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_EXT: 3160a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_EXT: 3170a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_EXT: 3180a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 3190a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGB; 3200a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB_ALPHA_EXT: 3210a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SRGB8_ALPHA8_EXT: 3220a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_EXT: 3230a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 3240a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 3250a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 3260a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_RGBA; 3270a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_ALPHA_EXT: 3280a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_ALPHA8_EXT: 3290a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 3300a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE_ALPHA; 3310a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE_EXT: 3320a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul case GL_SLUMINANCE8_EXT: 3333488b14a047bf1f05831b3bbdc374a0da482212cEric Anholt case GL_COMPRESSED_SLUMINANCE_EXT: 3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul return GL_LUMINANCE; 3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul default: 336abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul } 3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */ 3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul 3419c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if (ctx->Version >= 30 || 3423363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák ctx->Extensions.EXT_texture_integer) { 343abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul switch (internalFormat) { 344abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8UI_EXT: 345abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16UI_EXT: 346abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32UI_EXT: 347abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA8I_EXT: 348abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA16I_EXT: 349abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGBA32I_EXT: 350f449be660e70aac2aefd2ce84581e137de25520bDave Airlie case GL_RGB10_A2UI: 351abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGBA; 352abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8UI_EXT: 353abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16UI_EXT: 354abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32UI_EXT: 355abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB8I_EXT: 356abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB16I_EXT: 357abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_RGB32I_EXT: 358abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_RGB; 3593363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák } 3603363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák } 3613363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák 3623363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák if (ctx->Extensions.EXT_texture_integer) { 3633363e87d7d5b3f19294fc770dc7c506c26646010Marek Olšák switch (internalFormat) { 364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8UI_EXT: 365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16UI_EXT: 366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32UI_EXT: 367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA8I_EXT: 368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA16I_EXT: 369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_ALPHA32I_EXT: 370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_ALPHA; 371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8UI_EXT: 372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16UI_EXT: 373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32UI_EXT: 374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY8I_EXT: 375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY16I_EXT: 376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_INTENSITY32I_EXT: 377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_INTENSITY; 378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8UI_EXT: 379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16UI_EXT: 380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32UI_EXT: 381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE8I_EXT: 382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE16I_EXT: 383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE32I_EXT: 384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE; 385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul return GL_LUMINANCE_ALPHA; 392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul default: 393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul ; /* fallthrough */ 394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 3956988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 3966988f65e43297ae63bbce30bf882f870b370096cBrian Paul 3976988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_texture_rg) { 3986988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 3996988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16F: 4003ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* R16F depends on both ARB_half_float_pixel and ARB_texture_float. 4013ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4023ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4033ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4043ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4056988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32F: 4063ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4073ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4083ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4096988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8I: 4106988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R8UI: 4116988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16I: 4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R16UI: 4136988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32I: 4146988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R32UI: 4159c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if (ctx->Version < 30 && !ctx->Extensions.EXT_texture_integer) 4163ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4173ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4183ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R8: 4193ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_R16: 4203ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RED: 4213ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RED: 4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RED; 4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick 4246988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16F: 4253ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float. 4263ebbc176f9200ac954d461758937e755220ac551Ian Romanick */ 4273ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_half_float_pixel) 4283ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4293ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4306988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32F: 4313ebbc176f9200ac954d461758937e755220ac551Ian Romanick if (!ctx->Extensions.ARB_texture_float) 4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick return GL_RG; 4346988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8I: 4356988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG8UI: 4366988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16I: 4376988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG16UI: 4386988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32I: 4396988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RG32UI: 4409c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if (ctx->Version < 30 && !ctx->Extensions.EXT_texture_integer) 4413ebbc176f9200ac954d461758937e755220ac551Ian Romanick break; 4423ebbc176f9200ac954d461758937e755220ac551Ian Romanick /* FALLTHROUGH */ 4433ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG: 4443ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG8: 4453ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_RG16: 4463ebbc176f9200ac954d461758937e755220ac551Ian Romanick case GL_COMPRESSED_RG: 4476988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4486988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4496988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4506988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4516988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4526988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4536988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_texture_shared_exponent) { 4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4556988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_RGB9_E5_EXT: 4566988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4576988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4586988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4596988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4606988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.EXT_packed_float) { 4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_R11F_G11F_B10F_EXT: 4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RGB; 4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul 4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul if (ctx->Extensions.ARB_depth_buffer_float) { 4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH_COMPONENT32F: 4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_COMPONENT; 4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul case GL_DEPTH32F_STENCIL8: 4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_DEPTH_STENCIL; 4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul 482e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick if (ctx->Extensions.ARB_texture_compression_rgtc) { 4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul switch (internalFormat) { 484e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RED_RGTC1: 485e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RED; 487e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_RG_RGTC2: 488e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 4896988f65e43297ae63bbce30bf882f870b370096cBrian Paul return GL_RG; 4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul default: 4916988f65e43297ae63bbce30bf882f870b370096cBrian Paul ; /* fallthrough */ 4926988f65e43297ae63bbce30bf882f870b370096cBrian Paul } 493abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul } 494abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul 4957d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák if (ctx->Extensions.EXT_texture_compression_latc) { 4967d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák switch (internalFormat) { 4977d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 4987d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 4997d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE; 5007d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 5017d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 5027d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_LUMINANCE_ALPHA; 5037d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák default: 5047d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák ; /* fallthrough */ 5057d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5067d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák } 5077d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 50869f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák if (ctx->Extensions.ATI_texture_compression_3dc) { 50969f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák switch (internalFormat) { 51069f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 51169f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák return GL_LUMINANCE_ALPHA; 51269f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák default: 51369f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák ; /* fallthrough */ 51469f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 51569f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák } 51669f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák 517d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) { 518d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu switch (internalFormat) { 519d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case GL_ETC1_RGB8_OES: 520d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_RGB; 521d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu default: 522d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu ; /* fallthrough */ 523d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 524d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 525d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 526fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick if (ctx->API == API_OPENGLES) { 527fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick switch (internalFormat) { 528fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGB8_OES: 529fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_R5_G6_B5_OES: 530fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGB8_OES: 531fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_R5_G6_B5_OES: 532fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick return GL_RGB; 533fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGBA8_OES: 534fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGB5_A1_OES: 535fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGBA4_OES: 536fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE4_RGB5_A1_OES: 537fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGBA8_OES: 538fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick case GL_PALETTE8_RGBA4_OES: 539fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick return GL_RGBA; 540fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick default: 541fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick ; /* fallthrough */ 542fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick } 543fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick } 544fc0fa16be3792bdabad0993fc4026bf621d6092fIan Romanick 545f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul return -1; /* error */ 546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 5496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 550e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5]. 551e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0; 552e93243f8b7d43695654a36334c8cc5cea140d23cBrian */ 553e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint 554e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target) 555519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 5562efa3d4f9fd1e1683c5366d402d8740ecfb688e5Brian Paul if (_mesa_is_cube_face(target)) 557519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; 558519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul else 559519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul return 0; 560519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 561519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 562519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 563519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 5646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 565009ac0618ccb8c1347c353b576442ed70592c20eBrian Paul * Install gl_texture_image in a gl_texture_object according to the target 566009ac0618ccb8c1347c353b576442ed70592c20eBrian Paul * and level parameters. 5676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 5686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object. 5696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 5706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 5716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image. 572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 573009ac0618ccb8c1347c353b576442ed70592c20eBrian Paulstatic void 574009ac0618ccb8c1347c353b576442ed70592c20eBrian Paulset_tex_image(struct gl_texture_object *tObj, 575009ac0618ccb8c1347c353b576442ed70592c20eBrian Paul GLenum target, GLint level, 576009ac0618ccb8c1347c353b576442ed70592c20eBrian Paul struct gl_texture_image *texImage) 577fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 5789c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul const GLuint face = _mesa_tex_target_to_face(target); 5799c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 580fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(tObj); 581fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul ASSERT(texImage); 5820c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu if (target == GL_TEXTURE_RECTANGLE_NV || target == GL_TEXTURE_EXTERNAL_OES) 5830c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu assert(level == 0); 5849c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 5859c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul tObj->Image[face][level] = texImage; 5869c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul 587a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul /* Set the 'back' pointer */ 588a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul texImage->TexObject = tObj; 589a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Level = level; 590a231d245514b43cf547ccb996b68efc0186e6821Brian Paul texImage->Face = face; 591fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 592fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 593fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 594a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 5956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure. 5966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 597a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device 598a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver. 5996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to 6016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero. 60277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */ 60377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image * 604f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx ) 60577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 606a3f137094cd965d27e1b088499dd609b81a91906Brian Paul (void) ctx; 60777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul return CALLOC_STRUCT(gl_texture_image); 60877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 60977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 61077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 611a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 612146f536b3332b7a2022bb4ba5e2d1d2ec4bedd98Brian Paul * Free a gl_texture_image and associated data. 613146f536b3332b7a2022bb4ba5e2d1d2ec4bedd98Brian Paul * This function is a fallback called via ctx->Driver.DeleteTextureImage(). 6146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6151eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image. 6166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6173e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data. 618a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 61977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid 6203c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx, 6213c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 62277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{ 6235ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell /* Free texImage->Data and/or any other driver-specific texture 6245ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell * image storage. 6255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell */ 6260bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ASSERT(ctx->Driver.FreeTextureImageBuffer); 6270bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); 628dae2fca70521909cfdd8d217d5e42fc6b33b05f6Pekka Paalanen free(texImage); 62977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul} 63077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 63177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul 6326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 6336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target. 6346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 6366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 6376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise. 638aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */ 63977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean 64077ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target) 641aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{ 6420c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu /* 6430c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu * NUM_TEXTURE_TARGETS should match number of terms below, except there's no 6440c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES. 645874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul */ 6460c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu assert(NUM_TEXTURE_TARGETS == 7 + 2); 6472465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul 6488e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return (target == GL_PROXY_TEXTURE_1D || 6498e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_2D || 6508e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul target == GL_PROXY_TEXTURE_3D || 65127f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul target == GL_PROXY_TEXTURE_CUBE_MAP_ARB || 652bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_RECTANGLE_NV || 653bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_1D_ARRAY_EXT || 654bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick target == GL_PROXY_TEXTURE_2D_ARRAY_EXT); 655aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul} 656aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 657aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 6586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 65935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target 66035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 66135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum 66235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target) 66335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{ 66435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul switch (target) { 66535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D: 66635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D: 66735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D; 66835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D: 66935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D: 67035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D; 67135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_3D: 67235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_3D: 67335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_3D; 67435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 67535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 67635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 67735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 67835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 67935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 68035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 68135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 68235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_CUBE_MAP_ARB; 68335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_RECTANGLE_NV: 68435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 68535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_RECTANGLE_NV; 68635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 68735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 68835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_1D_ARRAY_EXT; 68935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 69035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 69135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return GL_PROXY_TEXTURE_2D_ARRAY_EXT; 69235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul default: 69335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul _mesa_problem(NULL, "unexpected target in get_proxy_target()"); 69435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul return 0; 69535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul } 69635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul} 69735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 69835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul 69935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/** 7003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given 701120d71a45cfda1edfa8cd6b1732e209eb98b53d8Brian Paul * texture unit. The target should have already been checked for validity. 7026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit. 7056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure. 70835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */ 70935d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object * 7103c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx, 7113c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_unit *texUnit, 71235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul GLenum target) 71335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{ 714f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array || 715f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array); 716f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul 71735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul switch (target) { 71835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_1D: 7199818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_1D_INDEX]; 72035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_1D: 721fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; 72235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_2D: 7239818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_2D_INDEX]; 72435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_2D: 725fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; 72635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_3D: 7279818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul return texUnit->CurrentTex[TEXTURE_3D_INDEX]; 72835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_3D: 729fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; 73035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 73135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 73235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 73335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 73435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 73535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 7365ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul case GL_TEXTURE_CUBE_MAP_ARB: 737a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 7389818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL; 73935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 740a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell return ctx->Extensions.ARB_texture_cube_map 741fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; 7428afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_TEXTURE_RECTANGLE_NV: 7438afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 7449818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL; 7458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 7468afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul return ctx->Extensions.NV_texture_rectangle 747fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; 748bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_1D_ARRAY_EXT: 749f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 750bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 751f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; 752bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_TEXTURE_2D_ARRAY_EXT: 753f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 754bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 755f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; 756874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 757874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return ctx->Extensions.ARB_texture_buffer_object 758874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL; 7590c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu case GL_TEXTURE_EXTERNAL_OES: 7600c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu return ctx->Extensions.OES_EGL_image_external 7610c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu ? texUnit->CurrentTex[TEXTURE_EXTERNAL_INDEX] : NULL; 76235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul default: 76308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); 76435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul return NULL; 76535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul } 76635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul} 76735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 76835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul 7696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 770b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit. 771b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */ 772b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object * 773f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target) 774b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{ 775b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 776b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul return _mesa_select_tex_object(ctx, texUnit, target); 777b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul} 778b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 779b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul 780b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/** 781c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture 782c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level. The target and level parameters should 783c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked. 7846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 7856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 7861eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit. 7876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 7886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level. 7896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 790c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure. 791fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */ 792fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image * 7933c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx, 7943c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul const struct gl_texture_object *texObj, 7955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level) 796fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{ 797c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 7985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 799c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(texObj); 800c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level >= 0); 801c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul ASSERT(level < MAX_TEXTURE_LEVELS); 802bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick 803c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul return texObj->Image[face][level]; 804fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul} 805fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 806fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 807a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 808a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate 809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it. Only return NULL if passed a bad parameter or run 810a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory. 811a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 812a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 813f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj, 814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul GLenum target, GLint level) 815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 8175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8185ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texObj) 8195ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return NULL; 8205ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 8215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 823a3f137094cd965d27e1b088499dd609b81a91906Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (!texImage) { 825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation"); 826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 827a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8285ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 829009ac0618ccb8c1347c353b576442ed70592c20eBrian Paul set_tex_image(texObj, target, level, texImage); 830a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 8315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 832a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return texImage; 833a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/** 837a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image. 838a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit. 839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid 840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * level, or out of memory. 841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */ 842a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image * 843f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level) 844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{ 845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul struct gl_texture_image *texImage; 84680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul GLuint texIndex; 847a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 84815357947226c5630bf546b0deec86f7e994de76aBrian Paul if (level < 0) 849a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul switch (target) { 852a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_1D: 853a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 854a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 85580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_INDEX; 85680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 857a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_2D: 858a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxTextureLevels) 859a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_INDEX; 86180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 862a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_3D: 863a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.Max3DTextureLevels) 864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 86580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_3D_INDEX; 86680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 867a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 868a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 869a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_CUBE_INDEX; 87180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 872a3f137094cd965d27e1b088499dd609b81a91906Brian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 873a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (level > 0) 874a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 87580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_RECT_INDEX; 87680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 877bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 878bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 879bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 88080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_1D_ARRAY_INDEX; 88180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 882bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 883bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick if (level >= ctx->Const.MaxTextureLevels) 884bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return NULL; 88580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texIndex = TEXTURE_2D_ARRAY_INDEX; 88680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul break; 887a3f137094cd965d27e1b088499dd609b81a91906Brian Paul default: 888a3f137094cd965d27e1b088499dd609b81a91906Brian Paul return NULL; 889a3f137094cd965d27e1b088499dd609b81a91906Brian Paul } 89080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul 89180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level]; 89280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 89380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage = ctx->Driver.NewTextureImage(ctx); 89480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul if (!texImage) { 89580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); 89680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return NULL; 89780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 89880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage; 89980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul /* Set the 'back' pointer */ 90080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul texImage->TexObject = ctx->Texture.ProxyTex[texIndex]; 90180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul } 90280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul return texImage; 903a3f137094cd965d27e1b088499dd609b81a91906Brian Paul} 904a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 905a3f137094cd965d27e1b088499dd609b81a91906Brian Paul 9066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 9076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels. 9086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 9106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target. 9116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given 9136dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target. 9146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 9156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants. 916ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */ 917ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint 918f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target) 919ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{ 920ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul switch (target) { 921ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_1D: 922ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_1D: 923ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_2D: 924ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_2D: 925ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.MaxTextureLevels; 926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_3D: 927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_3D: 928ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return ctx->Const.Max3DTextureLevels; 92958d11524dace34f6e9e513b23eaeb098d1eafd0bKenneth Graunke case GL_TEXTURE_CUBE_MAP: 930ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 931ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 932ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 933ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 934ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 935ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 936ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 937fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.ARB_texture_cube_map 938fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxCubeTextureLevels : 0; 939ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_TEXTURE_RECTANGLE_NV: 940ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 941fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul return ctx->Extensions.NV_texture_rectangle ? 1 : 0; 942fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 943fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 944fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_TEXTURE_2D_ARRAY_EXT: 945fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 946f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 947f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul ctx->Extensions.EXT_texture_array) 948fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul ? ctx->Const.MaxTextureLevels : 0; 949874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 9503df13b32e56dbc76bdc72b75ea1462f79b44dce9Kenneth Graunke return _mesa_is_desktop_gl(ctx) && 9513df13b32e56dbc76bdc72b75ea1462f79b44dce9Kenneth Graunke (ctx->Extensions.ARB_texture_buffer_object || 9523df13b32e56dbc76bdc72b75ea1462f79b44dce9Kenneth Graunke (ctx->Version >= 31)) ? 1 : 0; 9530c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu case GL_TEXTURE_EXTERNAL_OES: 954874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 955ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul default: 956ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul return 0; /* bad target */ 957ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul } 958ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul} 959ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 960ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul 96183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/** 9625e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target. 96383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */ 964a988ddf3798e0ec568704e4a72b46030079c7e45Dave AirlieGLint 965a988ddf3798e0ec568704e4a72b46030079c7e45Dave Airlie_mesa_get_texture_dimensions(GLenum target) 96683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{ 96783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul switch (target) { 96883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_1D: 96983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_1D: 97083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 1; 97183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_2D: 97283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_RECTANGLE: 97383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP: 97483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_2D: 97583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_RECTANGLE: 97683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 97783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 97883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 97983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 98083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 98183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 98283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 9835e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_1D_ARRAY: 9845e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY: 9850c87f16817ff0bf1f05e0d634944fd47b097faeeChia-I Wu case GL_TEXTURE_EXTERNAL_OES: 98683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 98783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_TEXTURE_3D: 98883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul case GL_PROXY_TEXTURE_3D: 9895e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_TEXTURE_2D_ARRAY: 9905e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY: 99183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 3; 992874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_TEXTURE_BUFFER: 993874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul /* fall-through */ 99483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul default: 99583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", 99683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul target); 99783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return 2; 99883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul } 99983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul} 100083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 100283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 1003fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul 100462c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */ 1005f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/* 1006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer. In this case we 1007afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL 10088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec. 1009afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte * 10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format) 1012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 10138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint components = _mesa_components_in_format(format); 10148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GLint numPixels = width * height * depth; 10158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); 1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1017a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG 1018afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* 1019afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Let's see if anyone finds this. If glTexImage2D() is called with 1020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * a NULL image pointer then load the texture image with something 1021afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * interesting instead of leaving it indeterminate. 1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 10238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (data) { 102465d54604c387dca986c876e811362d8e8517dcacBrian Paul static const char message[8][32] = { 1025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X ", 1026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " XX XX X X X X X ", 1027afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1028afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXX XXX XXXXX ", 1029afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X ", 1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X X X X X X ", 1031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " X X XXXXX XXX X X ", 1032afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg " " 1033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg }; 1034afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 10358e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte *imgPtr = data; 10368e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint h, i, j, k; 10378e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (h = 0; h < depth; h++) { 10388e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (i = 0; i < height; i++) { 10398e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcRow = 7 - (i % 8); 10408e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (j = 0; j < width; j++) { 10418e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLint srcCol = j % 32; 10428e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; 10438e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul for (k = 0; k < components; k++) { 10448e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul *imgPtr++ = texel; 10458e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul } 1046afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1047afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1048afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1049afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1050a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif 10518e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 10528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return data; 1053afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 105462c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif 1055afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1056afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1057afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1058738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 1059fc144728c7e33e53f7a4a4486eb81fddff156758Brian Paul * Set the size and format-related fields of a gl_texture_image struct 1060fc144728c7e33e53f7a4a4486eb81fddff156758Brian Paul * to zero. This is used when a proxy texture test fails. 10619c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */ 10629c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void 1063f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img) 10649c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{ 10659c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul ASSERT(img); 1066a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = 0; 1067a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = 0; 10689c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Border = 0; 10699c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width = 0; 10709c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height = 0; 10719c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth = 0; 10729c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Width2 = 0; 10739c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Height2 = 0; 10749c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->Depth2 = 0; 10759c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->WidthLog2 = 0; 10769c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->HeightLog2 = 0; 10779c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul img->DepthLog2 = 0; 10781f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul img->TexFormat = MESA_FORMAT_NONE; 10799c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul} 10809c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10819c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 10826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 10836628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct. 10846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 10866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized. 10876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width. 10886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height. 10896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth. 10906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border. 10916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format. 109283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format the actual hardware format (one of MESA_FORMAT_*) 10936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 10946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information. 1095887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border. 10966628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */ 10973893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid 1098892a2542a3f0753a7064c710b96f077dd5490624Brian Paul_mesa_init_teximage_fields(struct gl_context *ctx, 10993893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul struct gl_texture_image *img, 11003893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul GLsizei width, GLsizei height, GLsizei depth, 110183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GLint border, GLenum internalFormat, 110283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format format) 11036628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{ 1104b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat GLenum target; 11056628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul ASSERT(img); 11068bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(width >= 0); 11078bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(height >= 0); 11088bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul ASSERT(depth >= 0); 1109b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul 1110b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat target = img->TexObject->Target; 1111a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat ); 1112a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul ASSERT(img->_BaseFormat > 0); 1113a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul img->InternalFormat = internalFormat; 11146628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Border = border; 11156628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Width = width; 11166628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Height = height; 11176628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->Depth = depth; 1118c813b545ab4726fc5030f123ec6255224d64ad82Brian 11194d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */ 1120b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->WidthLog2 = _mesa_logbase2(img->Width2); 1121c813b545ab4726fc5030f123ec6255224d64ad82Brian 1122b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat switch(target) { 1123b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_1D: 1124b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_BUFFER: 1125b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_1D: 1126b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat if (height == 0) 1127b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Height2 = 0; 1128b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat else 1129b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Height2 = 1; 11306628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->HeightLog2 = 0; 1131b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat if (depth == 0) 1132b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 0; 1133b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat else 1134b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 1; 1135b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->DepthLog2 = 0; 1136b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat break; 1137b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_1D_ARRAY: 1138b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_1D_ARRAY: 1139b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Height2 = height; /* no border */ 1140b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->HeightLog2 = 0; /* not used */ 1141b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat if (depth == 0) 1142b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 0; 1143b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat else 1144b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 1; 1145b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->DepthLog2 = 0; 1146b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat break; 1147b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_2D: 1148b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_RECTANGLE: 1149b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP: 1150b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1151b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1152b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1153b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1154b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1155b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1156b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_EXTERNAL_OES: 1157b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_2D: 1158b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_RECTANGLE: 1159b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_CUBE_MAP: 1160c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1161b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->HeightLog2 = _mesa_logbase2(img->Height2); 1162b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat if (depth == 0) 1163b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 0; 1164b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat else 1165b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = 1; 11666628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->DepthLog2 = 0; 1167b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat break; 1168b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_2D_ARRAY: 1169b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_2D_ARRAY: 1170b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1171b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->HeightLog2 = _mesa_logbase2(img->Height2); 1172b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Depth2 = depth; /* no border */ 1173b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->DepthLog2 = 0; /* not used */ 1174b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat break; 1175b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_TEXTURE_3D: 1176b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat case GL_PROXY_TEXTURE_3D: 1177b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */ 1178b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat img->HeightLog2 = _mesa_logbase2(img->Height2); 1179c813b545ab4726fc5030f123ec6255224d64ad82Brian img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */ 1180b537f54b3a2bd47ec861f5c432c49529684eef21Roland Scheidegger img->DepthLog2 = _mesa_logbase2(img->Depth2); 1181b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat break; 1182b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat default: 1183b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat _mesa_problem(NULL, "invalid target 0x%x in _mesa_init_teximage_fields()", 1184b5c409363cfd144b1caad50b77ccc7591de42af2Anuj Phogat target); 1185c813b545ab4726fc5030f123ec6255224d64ad82Brian } 1186c813b545ab4726fc5030f123ec6255224d64ad82Brian 11876628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 118883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul img->TexFormat = format; 11896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul} 11906628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 11916628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul 1192738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 119342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct. 119442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 119542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context. 119642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared. 119742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * 119842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it. Its 119942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete. 120042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */ 120142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid 12023c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx, 12033c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul struct gl_texture_image *texImage) 120442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{ 12050bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 120642b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu clear_teximage_fields(texImage); 120742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu} 120842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 120942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu 121042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/** 1211738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage(). Test the texture 1212738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures. 1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1214738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the 1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube). 1216738318bb75dea8dac4465f53850987f6062a732dBrian Paul * 1217aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error. However, a 1218aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete" 1219aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled. 1220aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * 1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, 1222738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, 1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul * GL_PROXY_TEXTURE_CUBE_MAP_ARB. 1224738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level as passed to glTexImage 1225738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat as passed to glTexImage 1226738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format as passed to glTexImage 1227738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type as passed to glTexImage 1228738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width as passed to glTexImage 1229738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height as passed to glTexImage 1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth as passed to glTexImage 1231738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border as passed to glTexImage 1232738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable. 1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul */ 1234738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean 1235f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, 1236738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint internalFormat, GLenum format, GLenum type, 1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint width, GLint height, GLint depth, GLint border) 1238738318bb75dea8dac4465f53850987f6062a732dBrian Paul{ 1239738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLint maxSize; 12409c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul 1241738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) internalFormat; 1242738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) format; 1243738318bb75dea8dac4465f53850987f6062a732dBrian Paul (void) type; 1244738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1245738318bb75dea8dac4465f53850987f6062a732dBrian Paul switch (target) { 1246738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_1D: 1247738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1248ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1249738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1250c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1251c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1252c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1253c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1254c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1255738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1256738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1258738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_2D: 1259738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1260ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1262ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (height < 2 * border || height > 2 * border + maxSize) 1263738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1265c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1266c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1267c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1268c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1271738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1272738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1274738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_3D: 1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); 1276ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1278ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (height < 2 * border || height > 2 * border + maxSize) 1279738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1280ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (depth < 2 * border || depth > 2 * border + maxSize) 1281c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.Max3DTextureLevels) 1283c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1284c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1285c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1286c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1287c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1288c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1289c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) 1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1291738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1292738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1294738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1295c64447f47de168e82086bc2fb483817b82e59cabBrian Paul maxSize = ctx->Const.MaxTextureRectSize; 1296c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width < 0 || width > maxSize) 1297c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1298c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 0 || height > maxSize) 1299c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1300c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level != 0) 1301738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1302738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1303c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1304738318bb75dea8dac4465f53850987f6062a732dBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1305738318bb75dea8dac4465f53850987f6062a732dBrian Paul maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); 1306ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1307c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1308ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (height < 2 * border || height > 2 * border + maxSize) 1309c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1310c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxCubeTextureLevels) 1311738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1313c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1314c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1315c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1316c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1317738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1318738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1319c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1320bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1321bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1322ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1323bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1324c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) 1325bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1326c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1327c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1328c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1329c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1330c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1331bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1332bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1333c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1334bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1335bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); 1336ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (width < 2 * border || width > 2 * border + maxSize) 1337bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1338ea228d97f811092b9ffcb90565184a7a8f089477Anuj Phogat if (height < 2 * border || height > 2 * border + maxSize) 1339c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1340c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) 1341bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_FALSE; 1342c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (level >= ctx->Const.MaxTextureLevels) 1343c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1344c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (!ctx->Extensions.ARB_texture_non_power_of_two) { 1345c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (width > 0 && !_mesa_is_pow_two(width - 2 * border)) 1346c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1347c64447f47de168e82086bc2fb483817b82e59cabBrian Paul if (height > 0 && !_mesa_is_pow_two(height - 2 * border)) 1348c64447f47de168e82086bc2fb483817b82e59cabBrian Paul return GL_FALSE; 1349bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick } 1350bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick return GL_TRUE; 1351c64447f47de168e82086bc2fb483817b82e59cabBrian Paul 1352738318bb75dea8dac4465f53850987f6062a732dBrian Paul default: 1353738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage"); 1354738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_FALSE; 1355738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1356738318bb75dea8dac4465f53850987f6062a732dBrian Paul} 1357738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1358738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1359738318bb75dea8dac4465f53850987f6062a732dBrian Paul/** 13604b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit. 13614b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but 13624b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture. 13634b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but 13644b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point. 13654b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */ 13664b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean 13674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format, 13684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul GLint width, GLint height, GLint depth) 13694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{ 13704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t bytes = _mesa_format_image_size64(format, width, height, depth); 13714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */ 13724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes; 13734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul} 13744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 1376d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu/** 1377d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu * Return true if the format is only valid for glCompressedTexImage. 1378d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu */ 1379d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wustatic GLboolean 1380d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wucompressedteximage_only_format(const struct gl_context *ctx, GLenum format) 1381d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu{ 1382d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu switch (format) { 1383d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case GL_ETC1_RGB8_OES: 1384d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 1385d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu default: 1386d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_FALSE; 1387d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 1388d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu} 1389d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 13904b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul 13914b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/** 13927404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression 13937404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported. 1394064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */ 1395064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean 13967404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target, 13977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLenum intFormat) 1398064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{ 13997404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (void) intFormat; /* not used yet */ 14007404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 1401646afcc34045cd482e79ded241aac23082e65f6cBrian Paul switch (target) { 1402646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D: 1403646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D: 14047404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_TRUE; /* true for any compressed format so far */ 1405646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1406646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1407646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1408646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1409646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1410646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1411646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1412646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1413646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1414646afcc34045cd482e79ded241aac23082e65f6cBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1415f2dd11817a66b6254e1533398dc53f1bc51953beBrian Paul return (ctx->Extensions.MESA_texture_array || 1416684c66bb8b8cdaa7fc18b64a6f739ad70a10cd54Brian Paul ctx->Extensions.EXT_texture_array); 1417646afcc34045cd482e79ded241aac23082e65f6cBrian Paul default: 1418646afcc34045cd482e79ded241aac23082e65f6cBrian Paul return GL_FALSE; 1419646afcc34045cd482e79ded241aac23082e65f6cBrian Paul } 1420064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick} 1421064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1422064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick 1423064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/** 1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a 1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call. 1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean 1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target) 1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (dims) { 1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 1: 1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D: 1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D: 1435530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx); 1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1439d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 2: 1440d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1441d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D: 1442d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1443530c9d764b84035728a28ee2db996fffe49125ceIan Romanick case GL_PROXY_TEXTURE_2D: 1444530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx); 1445d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_CUBE_MAP: 1446530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1447530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && ctx->Extensions.ARB_texture_cube_map; 1448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1449d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1450d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1451d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1452d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1453d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return ctx->Extensions.ARB_texture_cube_map; 1455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_RECTANGLE_NV: 1456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_RECTANGLE_NV: 1457530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1458530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && ctx->Extensions.NV_texture_rectangle; 1459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_1D_ARRAY_EXT: 1461530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1462530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && (ctx->Extensions.MESA_texture_array || 1463530c9d764b84035728a28ee2db996fffe49125ceIan Romanick ctx->Extensions.EXT_texture_array); 1464d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case 3: 1468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul switch (target) { 1469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_3D: 1470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_TRUE; 1471530c9d764b84035728a28ee2db996fffe49125ceIan Romanick case GL_PROXY_TEXTURE_3D: 1472530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx); 1473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1474530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return (_mesa_is_desktop_gl(ctx) 1475530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && (ctx->Extensions.MESA_texture_array || 1476530c9d764b84035728a28ee2db996fffe49125ceIan Romanick ctx->Extensions.EXT_texture_array)) 1477530c9d764b84035728a28ee2db996fffe49125ceIan Romanick || _mesa_is_gles3(ctx); 1478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul case GL_PROXY_TEXTURE_2D_ARRAY_EXT: 1479530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1480530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && (ctx->Extensions.MESA_texture_array || 1481530c9d764b84035728a28ee2db996fffe49125ceIan Romanick ctx->Extensions.EXT_texture_array); 1482d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1483d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1484d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1485d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul default: 1486d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims); 1487d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return GL_FALSE; 1488d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 1489d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 1490d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1491d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 1492d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 149311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a 149409a5e028a6d254f619132e302a96c8535018603dBrian Paul * glTexSubImage, glCopyTexSubImage or glCopyTexImage call. 149509a5e028a6d254f619132e302a96c8535018603dBrian Paul * The difference compared to legal_teximage_target() above is that 149609a5e028a6d254f619132e302a96c8535018603dBrian Paul * proxy targets are not supported. 149711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 149811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean 149909a5e028a6d254f619132e302a96c8535018603dBrian Paullegal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target) 150011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 150111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (dims) { 150211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 1: 1503530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) && target == GL_TEXTURE_1D; 150411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case 2: 150511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul switch (target) { 150611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_2D: 150711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 150811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 150911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 151011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 151111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 151211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 151311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 151411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return ctx->Extensions.ARB_texture_cube_map; 151511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_RECTANGLE_NV: 1516530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1517530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && ctx->Extensions.NV_texture_rectangle; 151811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul case GL_TEXTURE_1D_ARRAY_EXT: 1519530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return _mesa_is_desktop_gl(ctx) 1520530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && (ctx->Extensions.MESA_texture_array || 1521530c9d764b84035728a28ee2db996fffe49125ceIan Romanick ctx->Extensions.EXT_texture_array); 152211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 152311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 152411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 152509a5e028a6d254f619132e302a96c8535018603dBrian Paul case 3: 152609a5e028a6d254f619132e302a96c8535018603dBrian Paul switch (target) { 152709a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_3D: 152809a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_TRUE; 152909a5e028a6d254f619132e302a96c8535018603dBrian Paul case GL_TEXTURE_2D_ARRAY_EXT: 1530530c9d764b84035728a28ee2db996fffe49125ceIan Romanick return (_mesa_is_desktop_gl(ctx) 1531530c9d764b84035728a28ee2db996fffe49125ceIan Romanick && (ctx->Extensions.MESA_texture_array || 1532530c9d764b84035728a28ee2db996fffe49125ceIan Romanick ctx->Extensions.EXT_texture_array)) 1533530c9d764b84035728a28ee2db996fffe49125ceIan Romanick || _mesa_is_gles3(ctx); 153409a5e028a6d254f619132e302a96c8535018603dBrian Paul default: 153509a5e028a6d254f619132e302a96c8535018603dBrian Paul return GL_FALSE; 153609a5e028a6d254f619132e302a96c8535018603dBrian Paul } 153711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul default: 153809a5e028a6d254f619132e302a96c8535018603dBrian Paul _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()", 153909a5e028a6d254f619132e302a96c8535018603dBrian Paul dims); 154011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_FALSE; 154111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 154211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 154311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 154411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 154511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 1546a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul * Helper function to determine if a texture object is mutable (in terms 1547a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul * of GL_ARB_texture_storage). 1548a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul */ 1549a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paulstatic GLboolean 1550a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paulmutable_tex_object(struct gl_context *ctx, GLenum target) 1551a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul{ 1552a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul if (ctx->Extensions.ARB_texture_storage) { 1553a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul struct gl_texture_object *texObj = 1554a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul _mesa_get_current_tex_object(ctx, target); 1555a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul return !texObj->Immutable; 1556a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul } 1557a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul return GL_TRUE; 1558a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul} 1559a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 1560a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 1561409620e47748479aaef593dc9bec0d6dd520e14aIan RomanickGLenum 1562409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick_mesa_es_error_check_format_and_type(GLenum format, GLenum type, 1563409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick unsigned dimensions) 1564409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick{ 1565409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick bool type_valid = true; 1566409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1567409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick switch (format) { 1568409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_ALPHA: 1569409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_LUMINANCE: 1570409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_LUMINANCE_ALPHA: 1571409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_BYTE 1572409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_FLOAT 1573409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_HALF_FLOAT_OES); 1574409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1575409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1576409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_RGB: 1577409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_BYTE 1578409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_UNSIGNED_SHORT_5_6_5 1579409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_FLOAT 1580409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_HALF_FLOAT_OES); 1581409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1582409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1583409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_RGBA: 1584409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_BYTE 1585409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_UNSIGNED_SHORT_4_4_4_4 1586409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_UNSIGNED_SHORT_5_5_5_1 1587409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_FLOAT 1588409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_HALF_FLOAT_OES 1589409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_UNSIGNED_INT_2_10_10_10_REV); 1590409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1591409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1592409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_DEPTH_COMPONENT: 1593409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick /* This format is filtered against invalid dimensionalities elsewhere. 1594409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick */ 1595409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_SHORT 1596409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick || type == GL_UNSIGNED_INT); 1597409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1598409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1599409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_DEPTH_STENCIL: 1600409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick /* This format is filtered against invalid dimensionalities elsewhere. 1601409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick */ 1602409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_INT_24_8); 1603409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1604409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1605409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick case GL_BGRA_EXT: 1606409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick type_valid = (type == GL_UNSIGNED_BYTE); 1607409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1608409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but 1609409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick * the format does not appear to be allowed for 3D textures in OpenGL 1610409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick * ES. 1611409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick */ 1612409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick if (dimensions != 2) 1613409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick return GL_INVALID_VALUE; 1614409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1615409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick break; 1616409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1617409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick default: 1618409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick return GL_INVALID_VALUE; 1619409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick } 1620409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1621409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION; 1622409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick} 1623a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 1624a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul/** 16256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors. 16266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 162885288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3). 16296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 16306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 16316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 16326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 16336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 16346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 16356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 16366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 16376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user. 16386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 16406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 16416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 16423c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 16433c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1645c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 164685288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx, 164785288ad722aa0ad378004c523a0e1a4984e15316Brian Paul GLuint dimensions, GLenum target, 1648c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint level, GLint internalFormat, 1649c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type, 1650c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, 1651c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint depth, GLint border ) 1652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 165335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLenum proxyTarget = get_proxy_target(target); 165435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul const GLboolean isProxy = target == proxyTarget; 1655e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick GLboolean sizeOK = GL_TRUE; 1656eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick GLboolean colorFormat; 1657627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul GLenum err; 1658eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick 1659eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick /* Even though there are no color-index textures, we still have to support 1660eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick * uploading color-index data and remapping it to RGB via the 1661eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick * GL_PIXEL_MAP_I_TO_[RGBA] tables. 1662eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick */ 1663eba527bf9ffc2fd67c44fb77104107556f509b49Ian Romanick const GLboolean indexFormat = (format == GL_COLOR_INDEX); 1664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1665738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 1666738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 1667738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1668738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1669738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d)", dimensions, level); 16708afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul } 1671738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1672738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1673738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1674738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 1675738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 16760686ccac950bac1a650400b29c47ddaafea22fa9Ian Romanick ((ctx->API != API_OPENGL || 16770686ccac950bac1a650400b29c47ddaafea22fa9Ian Romanick target == GL_TEXTURE_RECTANGLE_NV || 1678738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 1679738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!isProxy) { 1680738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1681738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(border=%d)", dimensions, border); 1682738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1683738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 1684738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 1685738318bb75dea8dac4465f53850987f6062a732dBrian Paul 1686973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul if (width < 0 || height < 0 || depth < 0) { 1687f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul if (!isProxy) { 1688f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1689973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul "glTexImage%dD(width, height or depth < 0)", dimensions); 1690f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1691f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul return GL_TRUE; 1692f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul } 1693f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul 1694409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the 1695409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick * combinations of format, internalFormat, and type that can be used. 1696409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick * Formats and types that require additional extensions (e.g., GL_FLOAT 1697409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick * requires GL_OES_texture_float) are filtered elsewhere. 1698409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick */ 1699409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick if (_mesa_is_gles(ctx) && !_mesa_is_gles3(ctx)) { 1700409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick if (format != internalFormat) { 1701409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_error(ctx, GL_INVALID_OPERATION, 1702409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick "glTexImage%dD(format = %s, internalFormat = %s)", 1703409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick dimensions, 1704409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_lookup_enum_by_nr(format), 1705409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_lookup_enum_by_nr(internalFormat)); 1706409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick return GL_TRUE; 1707409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick } 1708409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 1709409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick err = _mesa_es_error_check_format_and_type(format, type, dimensions); 1710409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick if (err != GL_NO_ERROR) { 1711409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_error(ctx, err, 1712409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick "glTexImage%dD(format = %s, type = %s)", 1713409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick dimensions, 1714409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_lookup_enum_by_nr(format), 1715409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick _mesa_lookup_enum_by_nr(type)); 1716409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick return GL_TRUE; 1717409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick } 1718409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick } 1719409620e47748479aaef593dc9bec0d6dd520e14aIan Romanick 172035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* Do this simple check before calling the TestProxyTexImage() function */ 172135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 172235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = (width == height); 1723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1724d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 172535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul /* 172635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Use the proxy texture driver hook to see if the size/level/etc are 172735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * legal. 172835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */ 172935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 1730e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick internalFormat, format, 1731e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick type, width, height, 1732e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick depth, border); 1733738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 1734c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 17354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1736738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)", 1737738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions, level, width, height, depth); 1738c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1739afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1742738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check internalFormat */ 174389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 1744c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!isProxy) { 17454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1746a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul "glTexImage%dD(internalFormat=%s)", 1747a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul dimensions, _mesa_lookup_enum_by_nr(internalFormat)); 1748c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1749afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_TRUE; 1750afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1751afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1752738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check incoming image format and type */ 1753627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul err = _mesa_error_check_format_and_type(ctx, format, type); 1754627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul if (err != GL_NO_ERROR) { 175538f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (!isProxy) { 1756627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul _mesa_error(ctx, err, 17578a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible format 0x%x, type 0x%x)", 17588a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 1759c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 176038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes return GL_TRUE; 1761afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1763601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* make sure internal format and format basically agree */ 176422e442544bc451f114288f07cf9cc1584ca357a1Brian Paul colorFormat = _mesa_is_color_format(format); 176522e442544bc451f114288f07cf9cc1584ca357a1Brian Paul if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) || 1766ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) || 1767ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) || 1768ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) || 1769ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) { 1770601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1771601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 17728a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)", 17738a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, internalFormat, format); 1774601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1775601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1776601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1777601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for ycbcr textures */ 1778601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (internalFormat == GL_YCBCR_MESA) { 1779c5b995066020191982b2315fc45d05e068eee761Brian Paul ASSERT(ctx->Extensions.MESA_ycbcr_texture); 1780601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (type != GL_UNSIGNED_SHORT_8_8_MESA && 1781601df9c742939c1f77de489561fe3e1d02f49618Brian Paul type != GL_UNSIGNED_SHORT_8_8_REV_MESA) { 1782c5b995066020191982b2315fc45d05e068eee761Brian Paul char message[100]; 1783fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 17842236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format/type YCBCR mismatch", dimensions); 1785c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_ENUM, "%s", message); 1786c5b995066020191982b2315fc45d05e068eee761Brian Paul return GL_TRUE; /* error */ 1787c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1788d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (target != GL_TEXTURE_2D && 1789d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_2D && 1790d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_TEXTURE_RECTANGLE_NV && 1791d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul target != GL_PROXY_TEXTURE_RECTANGLE_NV) { 1792d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) 1793d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)"); 1794d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1795d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1796d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (border != 0) { 1797d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul if (!isProxy) { 1798d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul char message[100]; 1799fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee _mesa_snprintf(message, sizeof(message), 18002236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)", 1801fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee dimensions, border); 1802c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee _mesa_error(ctx, GL_INVALID_VALUE, "%s", message); 1803d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1804d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 1805d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 1806c5b995066020191982b2315fc45d05e068eee761Brian Paul } 1807c5b995066020191982b2315fc45d05e068eee761Brian Paul 1808601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for depth textures */ 1809601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) { 181029a7d7784def4f37d3fe38a123a17836dd7fafc0Anuj Phogat /* Only 1D, 2D, rect, array and cube textures supported, not 3D 181129a7d7784def4f37d3fe38a123a17836dd7fafc0Anuj Phogat * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */ 1812601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (target != GL_TEXTURE_1D && 1813601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_PROXY_TEXTURE_1D && 1814601df9c742939c1f77de489561fe3e1d02f49618Brian Paul target != GL_TEXTURE_2D && 18152b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_PROXY_TEXTURE_2D && 1816753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_1D_ARRAY && 1817753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_1D_ARRAY && 1818753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_TEXTURE_2D_ARRAY && 1819753660780a84187043d0dc4b0e0f449786862182Brian Paul target != GL_PROXY_TEXTURE_2D_ARRAY && 18202b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul target != GL_TEXTURE_RECTANGLE_ARB && 182129a7d7784def4f37d3fe38a123a17836dd7fafc0Anuj Phogat target != GL_PROXY_TEXTURE_RECTANGLE_ARB && 182229a7d7784def4f37d3fe38a123a17836dd7fafc0Anuj Phogat !((_mesa_is_cube_face(target) || target == GL_PROXY_TEXTURE_CUBE_MAP) && 18239c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))) { 1824601df9c742939c1f77de489561fe3e1d02f49618Brian Paul if (!isProxy) 1825601df9c742939c1f77de489561fe3e1d02f49618Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 1826601df9c742939c1f77de489561fe3e1d02f49618Brian Paul "glTexImage(target/internalFormat)"); 1827601df9c742939c1f77de489561fe3e1d02f49618Brian Paul return GL_TRUE; 1828601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1829601df9c742939c1f77de489561fe3e1d02f49618Brian Paul } 1830601df9c742939c1f77de489561fe3e1d02f49618Brian Paul 1831601df9c742939c1f77de489561fe3e1d02f49618Brian Paul /* additional checks for compressed textures */ 1832df2c4cbcedb2dcf2aa44adaa6462d9becccbea49Anuj Phogat if (_mesa_is_compressed_format(ctx, internalFormat)) { 18337404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 18347404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!isProxy) 18357404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, 18367404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul "glTexImage%dD(target)", dimensions); 1837064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick return GL_TRUE; 183889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 1839d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (compressedteximage_only_format(ctx, internalFormat)) { 1840d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 1841d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu "glTexImage%dD(no compression for format)", dimensions); 1842d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 1843d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 184489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 184589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!isProxy) { 184689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 18478978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexImage%dD(border!=0)", dimensions); 184889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 184989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 185089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 185189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 185289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 1853326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul /* additional checks for integer textures */ 18549c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if ((ctx->Version >= 30 || ctx->Extensions.EXT_texture_integer) && 18559ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen (_mesa_is_enum_format_integer(format) != 18569ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen _mesa_is_enum_format_integer(internalFormat))) { 1857326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul if (!isProxy) { 1858326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1859326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul "glTexImage%dD(integer/non-integer format mismatch)", 1860326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul dimensions); 1861326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1862326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul return GL_TRUE; 1863326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 1864326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 1865a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul if (!mutable_tex_object(ctx, target)) { 1866a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 1867a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul "glTexImage%dD(immutable texture)", dimensions); 1868a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul return GL_TRUE; 1869a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul } 1870a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 1871afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg /* if we get here, the parameters are OK */ 1872afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return GL_FALSE; 1873afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1874afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1875afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 18766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1877c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors. 18786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 18806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 18816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 18826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 18836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user. 18846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user. 18856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user. 18866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user. 18876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user. 18886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 18896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 18906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user. 18916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 18936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 18946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 18953c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 18963c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 1897afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 1898c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 1899f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions, 1900c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, 1901c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 1902c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint depth, 1903c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum format, GLenum type ) 1904afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 1905627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul GLenum err; 1906627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul 1907738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check */ 1908738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 19094e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level); 1910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1911c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1912afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 191345124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* Check for negative sizes */ 1914c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (width < 0) { 19154e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(width=%d)", dimensions, width); 1917c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1918c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1919c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (height < 0 && dimensions > 1) { 19204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 19214e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glTexSubImage%dD(height=%d)", dimensions, height); 1922c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1923c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1924c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (depth < 0 && dimensions > 2) { 1925738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 1926738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glTexSubImage%dD(depth=%d)", dimensions, depth); 1927c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1928c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1929afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 19309848e86af0c937a6f7609289ab2705c3535f378fIan Romanick /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the 19319848e86af0c937a6f7609289ab2705c3535f378fIan Romanick * combinations of format and type that can be used. Formats and types 19329848e86af0c937a6f7609289ab2705c3535f378fIan Romanick * that require additional extensions (e.g., GL_FLOAT requires 19339848e86af0c937a6f7609289ab2705c3535f378fIan Romanick * GL_OES_texture_float) are filtered elsewhere. 19349848e86af0c937a6f7609289ab2705c3535f378fIan Romanick */ 19359848e86af0c937a6f7609289ab2705c3535f378fIan Romanick if (_mesa_is_gles(ctx) && !_mesa_is_gles3(ctx)) { 19369848e86af0c937a6f7609289ab2705c3535f378fIan Romanick err = _mesa_es_error_check_format_and_type(format, type, dimensions); 19379848e86af0c937a6f7609289ab2705c3535f378fIan Romanick if (err != GL_NO_ERROR) { 19389848e86af0c937a6f7609289ab2705c3535f378fIan Romanick _mesa_error(ctx, err, 19399848e86af0c937a6f7609289ab2705c3535f378fIan Romanick "glTexSubImage%dD(format = %s, type = %s)", 19409848e86af0c937a6f7609289ab2705c3535f378fIan Romanick dimensions, 19419848e86af0c937a6f7609289ab2705c3535f378fIan Romanick _mesa_lookup_enum_by_nr(format), 19429848e86af0c937a6f7609289ab2705c3535f378fIan Romanick _mesa_lookup_enum_by_nr(type)); 19439848e86af0c937a6f7609289ab2705c3535f378fIan Romanick return GL_TRUE; 19449848e86af0c937a6f7609289ab2705c3535f378fIan Romanick } 19459848e86af0c937a6f7609289ab2705c3535f378fIan Romanick } 19469848e86af0c937a6f7609289ab2705c3535f378fIan Romanick 1947627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul err = _mesa_error_check_format_and_type(ctx, format, type); 1948627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul if (err != GL_NO_ERROR) { 1949627b435dfe17698a1c69e9a259838fc6f2e6bd4eBrian Paul _mesa_error(ctx, err, 19508a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)", 19518a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul dimensions, format, type); 19525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 19535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 19545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 19555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 19565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 1957f2718b0966f54049056e16e7cca08718341557b2Brian Paul 1958d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 1959d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/** 1960d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture. 1961d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise 1962d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */ 19635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 1964f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions, 19655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 19665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 19675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint width, GLint height, GLint depth, 19685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum format, GLenum type, 19695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *destTex ) 19705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 1971c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!destTex) { 1972738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* undefined image level */ 1973738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions); 1974c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1975c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 1977c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)destTex->Border)) { 1978738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)", 1979738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1980c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1981afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1982c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { 1983738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)", 1984738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1985c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1986c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 1987c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 19886eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul GLint yBorder = (target == GL_TEXTURE_1D_ARRAY) ? 0 : destTex->Border; 19896eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (yoffset < -yBorder) { 1990738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)", 1991738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1992c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1993afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 19946eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (yoffset + height > (GLint) destTex->Height + yBorder) { 1995738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)", 1996738318bb75dea8dac4465f53850987f6062a732dBrian Paul dimensions); 1997c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 1998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 1999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2000c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 20016eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul GLint zBorder = (target == GL_TEXTURE_2D_ARRAY) ? 0 : destTex->Border; 20026eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (zoffset < -zBorder) { 200308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); 2004c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2005c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 20066eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (zoffset + depth > (GLint) destTex->Depth + zBorder) { 200708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); 2008c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2009c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2010afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2011afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2012b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(destTex->TexFormat)) { 2013d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul GLuint bw, bh; 2014d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 2015d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (compressedteximage_only_format(ctx, destTex->InternalFormat)) { 2016d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 2017d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu "glTexSubImage%dD(no compression for format)", dimensions); 2018d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 2019d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 2020d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 2021d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* do tests which depend on compression block size */ 2022d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); 2023d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul 2024d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* offset must be multiple of block size */ 2025d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) { 2026e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20278978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(xoffset = %d, yoffset = %d)", 2028d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul dimensions, xoffset, yoffset); 2029e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2030e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2031d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul /* size must be multiple of bw by bh or equal to whole texture size */ 2032d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((width % bw != 0) && (GLuint) width != destTex->Width) { 2033e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20348978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(width = %d)", dimensions, width); 2035e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 203689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2037d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul if ((height % bh != 0) && (GLuint) height != destTex->Height) { 203889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20398978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glTexSubImage%dD(height = %d)", dimensions, height); 204089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 204189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2042e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2043e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 20449c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if (ctx->Version >= 30 || ctx->Extensions.EXT_texture_integer) { 20456f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul /* both source and dest must be integer-valued, or neither */ 20466f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul if (_mesa_is_format_integer_color(destTex->TexFormat) != 20479ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen _mesa_is_enum_format_integer(format)) { 20486f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 20496f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul "glTexSubImage%dD(integer/non-integer format mismatch)", 20506f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul dimensions); 20516f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul return GL_TRUE; 20526f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul } 20536f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul } 20546f3d91840945fbd9221a247e4f95b32c4051f202Brian Paul 2055c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2056c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2057afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2058afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 20596dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 2060c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors. 20616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 20636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 20646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 20656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 20666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user. 20676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user. 20686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user. 20696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border. 20706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 20726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 20736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in 20743c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according 20753c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification. 2076afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2077c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 2078f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions, 2079c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLenum target, GLint level, GLint internalFormat, 2080c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul GLint width, GLint height, GLint border ) 2081afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 208211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum proxyTarget = get_proxy_target(target); 208311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul const GLenum type = GL_FLOAT; 2084738318bb75dea8dac4465f53850987f6062a732dBrian Paul GLboolean sizeOK; 2085e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul GLint baseFormat; 2086afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 208711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* check target */ 208809a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 208911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)", 209011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 209111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul return GL_TRUE; 209211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul } 209311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 2094738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */ 2095738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 20965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_error(ctx, GL_INVALID_VALUE, 20975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell "glCopyTexImage%dD(level=%d)", dimensions, level); 20985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_TRUE; 20995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 21005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 210134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 210236ede89687fe2de213f2637ab7acfb80cfd856cdBrian Paul if (_mesa_is_user_fbo(ctx->ReadBuffer)) { 2103b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 2104b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 2105b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 210634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 210734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 210834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 210934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 211034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 21116950a4faf650fe119ee97aa18b006eed099038beEric Anholt 21126950a4faf650fe119ee97aa18b006eed099038beEric Anholt if (ctx->ReadBuffer->Visual.samples > 0) { 2113e9b908b014be57cd2d3f0432adf16ac5b9631325Paul Berry _mesa_error(ctx, GL_INVALID_OPERATION, 21146950a4faf650fe119ee97aa18b006eed099038beEric Anholt "glCopyTexImage%dD(multisample FBO)", 21156950a4faf650fe119ee97aa18b006eed099038beEric Anholt dimensions); 21166950a4faf650fe119ee97aa18b006eed099038beEric Anholt return GL_TRUE; 21176950a4faf650fe119ee97aa18b006eed099038beEric Anholt } 211834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 211934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 2120738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check border */ 2121738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (border < 0 || border > 1 || 21220686ccac950bac1a650400b29c47ddaafea22fa9Ian Romanick ((ctx->API != API_OPENGL || 21230686ccac950bac1a650400b29c47ddaafea22fa9Ian Romanick target == GL_TEXTURE_RECTANGLE_NV || 2124738318bb75dea8dac4465f53850987f6062a732dBrian Paul target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) { 212559d965333c05534475b60042571366656b97ab9dIan Romanick _mesa_error(ctx, GL_INVALID_VALUE, 212659d965333c05534475b60042571366656b97ab9dIan Romanick "glCopyTexImage%dD(border=%d)", dimensions, border); 2127738318bb75dea8dac4465f53850987f6062a732dBrian Paul return GL_TRUE; 2128738318bb75dea8dac4465f53850987f6062a732dBrian Paul } 2129738318bb75dea8dac4465f53850987f6062a732dBrian Paul 2130e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul baseFormat = _mesa_base_tex_format(ctx, internalFormat); 2131e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul if (baseFormat < 0) { 21320899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 21330899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul "glCopyTexImage%dD(internalFormat)", dimensions); 21340899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21350899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21360899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul 2137e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul if (!_mesa_source_buffer_exists(ctx, baseFormat)) { 213834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 213934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(missing readbuffer)", dimensions); 214034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 214134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 214234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 2143422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt /* From the EXT_texture_integer spec: 2144422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * 2145422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage* 2146422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * if the texture internalformat is an integer format and the read color 2147422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * buffer is not an integer format, or if the internalformat is not an 2148422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * integer format and the read color buffer is an integer format." 2149422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt */ 2150422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt if (_mesa_is_color_format(internalFormat)) { 2151422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2152422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt 21539ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen if (_mesa_is_enum_format_integer(rb->InternalFormat) != 21549ad8f431b2a47060bf05517246ab0fa8d249c800Jordan Justen _mesa_is_enum_format_integer(internalFormat)) { 2155422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt _mesa_error(ctx, GL_INVALID_OPERATION, 2156422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt "glCopyTexImage%dD(integer vs non-integer)", dimensions); 2157422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt return GL_TRUE; 2158422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt } 2159422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt } 2160422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt 216111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul /* Do size, level checking */ 216211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) 216311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul ? (width == height) : 1; 2164738318bb75dea8dac4465f53850987f6062a732dBrian Paul 216511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 2166e06277bd886a9a79f0bf9b175ec26fbe187689c2Brian Paul internalFormat, baseFormat, 216711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul type, width, height, 216811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 1, border); 2169c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2170738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (!sizeOK) { 2171738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (dimensions == 1) { 21724e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 2173738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage1D(width=%d)", width); 2174c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2175738318bb75dea8dac4465f53850987f6062a732dBrian Paul else { 2176738318bb75dea8dac4465f53850987f6062a732dBrian Paul ASSERT(dimensions == 2); 2177738318bb75dea8dac4465f53850987f6062a732dBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 2178738318bb75dea8dac4465f53850987f6062a732dBrian Paul "glCopyTexImage2D(width=%d, height=%d)", width, height); 2179ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul } 2180c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2181c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2182c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2183df2c4cbcedb2dcf2aa44adaa6462d9becccbea49Anuj Phogat if (_mesa_is_compressed_format(ctx, internalFormat)) { 21847404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 218589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, 21862236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul "glCopyTexImage%dD(target)", dimensions); 218789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 218889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2189d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (compressedteximage_only_format(ctx, internalFormat)) { 2190d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 2191d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu "glCopyTexImage%dD(no compression for format)", dimensions); 2192d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 2193d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 219489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (border != 0) { 219589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 21968978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexImage%dD(border!=0)", dimensions); 21970899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul return GL_TRUE; 21980899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 21990899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul } 220089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2201a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul if (!mutable_tex_object(ctx, target)) { 2202a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2203a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul "glCopyTexImage%dD(immutable texture)", dimensions); 2204a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul return GL_TRUE; 2205a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul } 2206a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 2207c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2208c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2209c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2210c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2211c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 221334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors. 22149dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking. 22159dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part. 22166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 22176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 22186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3). 22196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user. 22206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user. 22216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 22226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. 22236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 2224c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean 2225f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, 22269dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul GLenum target, GLint level) 2227c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 222834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul /* Check that the source buffer is complete */ 222936ede89687fe2de213f2637ab7acfb80cfd856cdBrian Paul if (_mesa_is_user_fbo(ctx->ReadBuffer)) { 2230b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul if (ctx->ReadBuffer->_Status == 0) { 2231b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); 2232b0fceae22f008f3963a392ebd57d7d2a095a5e05Brian Paul } 223334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 223434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 223534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul "glCopyTexImage%dD(invalid readbuffer)", dimensions); 223634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul return GL_TRUE; 223734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 22386950a4faf650fe119ee97aa18b006eed099038beEric Anholt 22396950a4faf650fe119ee97aa18b006eed099038beEric Anholt if (ctx->ReadBuffer->Visual.samples > 0) { 2240e9b908b014be57cd2d3f0432adf16ac5b9631325Paul Berry _mesa_error(ctx, GL_INVALID_OPERATION, 22416950a4faf650fe119ee97aa18b006eed099038beEric Anholt "glCopyTexSubImage%dD(multisample FBO)", 22426950a4faf650fe119ee97aa18b006eed099038beEric Anholt dimensions); 22436950a4faf650fe119ee97aa18b006eed099038beEric Anholt return GL_TRUE; 22446950a4faf650fe119ee97aa18b006eed099038beEric Anholt } 224534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul } 224634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul 22471c23b860cea93534f726d2a18658444f37f43538Brian Paul /* check target (proxies not allowed) */ 224809a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dimensions, target)) { 22491c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)", 22501c23b860cea93534f726d2a18658444f37f43538Brian Paul dimensions, _mesa_lookup_enum_by_nr(target)); 22511c23b860cea93534f726d2a18658444f37f43538Brian Paul return GL_TRUE; 2252c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2253c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2254738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* Check level */ 2255738318bb75dea8dac4465f53850987f6062a732dBrian Paul if (level < 0 || level >= MAX_TEXTURE_LEVELS) { 22564e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 22574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(level=%d)", dimensions, level); 2258c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2259c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2260c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22615ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell return GL_FALSE; 22625ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell} 22635ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 22649dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 22659dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/** 22669dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D(). 22679dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user. 22689dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user. 22699dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user. 22709dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user. 22719dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user. 22729dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */ 22735ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean 2274f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions, 22755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLenum target, GLint level, 22765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLint xoffset, GLint yoffset, GLint zoffset, 22775ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell GLsizei width, GLsizei height, 22785ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell const struct gl_texture_image *teximage ) 22795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{ 22809dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check that dest tex image exists */ 2281c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (!teximage) { 22824e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 2283b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul "glCopyTexSubImage%dD(undefined texture level: %d)", 2284b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul dimensions, level); 2285c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2286c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2287c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 22889dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* Check size */ 22899dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (width < 0) { 22909dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 22919dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(width=%d)", dimensions, width); 22929dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 22939dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 22949dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul if (dimensions > 1 && height < 0) { 22959dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 22969dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul "glCopyTexSubImage%dD(height=%d)", dimensions, height); 22979dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul return GL_TRUE; 22989dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul } 22999dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul 23009dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check x/y offsets */ 2301c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (xoffset < -((GLint)teximage->Border)) { 23024e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23034e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); 2304c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2305c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 230638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) { 23074e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23084e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(xoffset+width)", dimensions); 2309c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2310c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2311c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 1) { 23126eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul GLint yBorder = (target == GL_TEXTURE_1D_ARRAY) ? 0 : teximage->Border; 23136eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (yoffset < -yBorder) { 23144e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23154e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); 2316c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2317c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2318c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* NOTE: we're adding the border here, not subtracting! */ 23196eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (yoffset + height > (GLint) teximage->Height + yBorder) { 23204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23214e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(yoffset+height)", dimensions); 2322c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2323c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2324c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2325c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 23269dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul /* check z offset */ 2327c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul if (dimensions > 2) { 23286eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul GLint zBorder = (target == GL_TEXTURE_2D_ARRAY) ? 0 : teximage->Border; 23296eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (zoffset < -zBorder) { 23304e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23314e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset)", dimensions); 2332c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2333c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 23346eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (zoffset > (GLint) teximage->Depth + zBorder) { 23354e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23364e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul "glCopyTexSubImage%dD(zoffset+depth)", dimensions); 2337c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_TRUE; 2338c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2339c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2340c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2341b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul if (_mesa_is_format_compressed(teximage->TexFormat)) { 2342d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (compressedteximage_only_format(ctx, teximage->InternalFormat)) { 2343d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 2344d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu "glCopyTexSubImage%dD(no compression for format)", dimensions); 2345d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 2346d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 234789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* offset must be multiple of 4 */ 234889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if ((xoffset & 3) || (yoffset & 3)) { 234989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23508978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions); 2351e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 2352e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 235389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* size must be multiple of 4 */ 2354798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((width & 3) != 0 && (GLuint) width != teximage->Width) { 235589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23568978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(width)", dimensions); 2357e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul return GL_TRUE; 235889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2359798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz if ((height & 3) != 0 && (GLuint) height != teximage->Height) { 236089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_error(ctx, GL_INVALID_VALUE, 23618978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee "glCopyTexSubImage%dD(height)", dimensions); 236289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_TRUE; 236389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2364e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul } 2365e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul 2366a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul if (teximage->InternalFormat == GL_YCBCR_MESA) { 2367d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D"); 2368d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul return GL_TRUE; 2369d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul } 2370d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul 2371985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) { 2372985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane _mesa_error(ctx, GL_INVALID_OPERATION, 2373803504e69fbd85713fc6d93af21f5245852cecabBrian Paul "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)", 2374803504e69fbd85713fc6d93af21f5245852cecabBrian Paul dimensions, teximage->_BaseFormat); 2375985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane return GL_TRUE; 2376985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane } 2377985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane 2378422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt /* From the EXT_texture_integer spec: 2379422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * 2380422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage* 2381422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * if the texture internalformat is an integer format and the read color 2382422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * buffer is not an integer format, or if the internalformat is not an 2383422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt * integer format and the read color buffer is an integer format." 2384326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul */ 2385422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt if (_mesa_is_color_format(teximage->InternalFormat)) { 2386326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; 2387422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt 2388422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt if (_mesa_is_format_integer_color(rb->Format) != 2389422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt _mesa_is_format_integer_color(teximage->TexFormat)) { 2390422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt _mesa_error(ctx, GL_INVALID_OPERATION, 2391422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt "glCopyTexImage%dD(integer vs non-integer)", dimensions); 2392422b18794eacc8f0be5b4e9611e2726f4e0d86b6Eric Anholt return GL_TRUE; 2393326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2394326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul } 2395326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul 2396c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul /* if we get here, the parameters are OK */ 2397c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul return GL_FALSE; 2398c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2399c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2400c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 24012897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */ 24022897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info 24032897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 2404f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx; 24052897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_texture_object *texObj; 24062897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul GLuint level, face; 24072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}; 24082897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 2410519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/** 24112897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback. Called from _mesa_HashWalk(). 2412519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */ 2413519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void 24142897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData) 2415519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{ 24162897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_framebuffer *fb = (struct gl_framebuffer *) data; 24172897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct cb_info *info = (struct cb_info *) userData; 2418f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = info->ctx; 24192897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const struct gl_texture_object *texObj = info->texObj; 24202897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul const GLuint level = info->level, face = info->face; 24212897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24222897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* If this is a user-created FBO */ 242336ede89687fe2de213f2637ab7acfb80cfd856cdBrian Paul if (_mesa_is_user_fbo(fb)) { 2424519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul GLuint i; 24252897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* check if any of the FBO's attachments point to 'texObj' */ 2426519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul for (i = 0; i < BUFFER_COUNT; i++) { 24272897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct gl_renderbuffer_attachment *att = fb->Attachment + i; 2428519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul if (att->Type == GL_TEXTURE && 2429519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->Texture == texObj && 2430519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->TextureLevel == level && 2431519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul att->CubeMapFace == face) { 2432db0f9e701d59dcfcd3b50f4d245897692f27fec9Brian Paul ASSERT(_mesa_get_attachment_teximage(att)); 2433519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul /* Tell driver about the new renderbuffer texture */ 2434ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att); 24352897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Mark fb status as indeterminate to force re-validation */ 24362897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul fb->_Status = 0; 2437519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2438519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2439519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul } 2440519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul} 2441519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2442519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 24432897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** 24442897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to 24452897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes 24462897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness. 24472897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated. 24482897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */ 2449d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paulvoid 2450d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paul_mesa_update_fbo_texture(struct gl_context *ctx, 2451d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paul struct gl_texture_object *texObj, 2452d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paul GLuint face, GLuint level) 24532897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{ 24542897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul /* Only check this texture if it's been marked as RenderToTexture */ 24552897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul if (texObj->_RenderToTexture) { 24562897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul struct cb_info info; 24572897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.ctx = ctx; 24582897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.texObj = texObj; 24592897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.level = level; 24602897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul info.face = face; 24612897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info); 24622897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul } 24632897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul} 24642897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24652897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul 24662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/** 24672914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've 24682914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the 24692914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now. 24702914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */ 24719520f483b8f1e45fa474674b415554988de5d8d3Brian Paulstatic inline void 2472f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target, 24732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul struct gl_texture_object *texObj, GLint level) 24742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{ 24752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(target != GL_TEXTURE_CUBE_MAP); 2476ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul if (texObj->GenerateMipmap && 2477ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level == texObj->BaseLevel && 2478ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul level < texObj->MaxLevel) { 24792914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ASSERT(ctx->Driver.GenerateMipmap); 24802914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->Driver.GenerateMipmap(ctx, target, texObj); 24812914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul } 24822914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul} 24832914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 24842914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 24851826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */ 24861826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum 24871826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height) 24881826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{ 24891826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0 24901826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul if (internalFormat == GL_RGBA16F_ARB || 24911826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGBA32F_ARB) { 24921826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgba float tex to int %d x %d\n", width, height); 24931826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGBA; 24941826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 24951826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_RGB16F_ARB || 24961826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_RGB32F_ARB) { 24971826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert rgb float tex to int %d x %d\n", width, height); 24981826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_RGB; 24991826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25001826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB || 25011826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE_ALPHA32F_ARB) { 25021826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 25031826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE_ALPHA; 25041826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25051826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_LUMINANCE16F_ARB || 25061826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_LUMINANCE32F_ARB) { 25071826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 25081826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_LUMINANCE; 25091826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25101826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_ALPHA16F_ARB || 25111826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat == GL_ALPHA32F_ARB) { 25121826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul printf("Convert luminance float tex to int %d x %d\n", width, height); 25131826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return GL_ALPHA; 25141826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25151826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul /* 25161826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { 25171826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul internalFormat = GL_RGBA; 25181826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25191826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul */ 25201826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul else { 25211826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 25221826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul } 25231826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else 25241826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul return internalFormat; 25251826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif 25261826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul} 25271826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul 2528519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 2529bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/** 2530bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image. 2531bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible. 2532bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format. 2533bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels 2534bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation. In particular, this 2535bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation. 2536bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 253783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format 2538f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx, 2539bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj, 2540bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum target, GLint level, 2541bab484a59b21fff84579a492d079d46e27d486ddBrian Paul GLenum internalFormat, GLenum format, GLenum type) 2542bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{ 254383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format f; 254483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2545bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* see if we've already chosen a format for the previous level */ 2546bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (level > 0) { 2547bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_image *prevImage = 2548bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_select_tex_image(ctx, texObj, target, level - 1); 2549bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* See if the prev level is defined and has an internal format which 2550bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * matches the new internal format. 2551bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */ 2552bab484a59b21fff84579a492d079d46e27d486ddBrian Paul if (prevImage && 2553bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->Width > 0 && 2554bab484a59b21fff84579a492d079d46e27d486ddBrian Paul prevImage->InternalFormat == internalFormat) { 2555bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* use the same format */ 255683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE); 255783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return prevImage->TexFormat; 2558bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2559bab484a59b21fff84579a492d079d46e27d486ddBrian Paul } 2560bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2561bab484a59b21fff84579a492d079d46e27d486ddBrian Paul /* choose format from scratch */ 256283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type); 256383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul ASSERT(f != MESA_FORMAT_NONE); 256483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul return f; 2565bab484a59b21fff84579a492d079d46e27d486ddBrian Paul} 2566bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 25679c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt/** 25689c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * Adjust pixel unpack params and image dimensions to strip off the 25696c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul * one-pixel texture border. 25709c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * 25719c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * Gallium and intel don't support texture borders. They've seldem been used 25729c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * and seldom been implemented correctly anyway. 25739c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * 25749c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * \param unpackNew returns the new pixel unpack parameters 25759c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt */ 25769c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholtstatic void 25776c1dea54457c1d19b67794f188c40c74c23ba762Brian Paulstrip_texture_border(GLenum target, 25789c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt GLint *width, GLint *height, GLint *depth, 25799c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt const struct gl_pixelstore_attrib *unpack, 25809c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt struct gl_pixelstore_attrib *unpackNew) 25819c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt{ 25826c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul assert(width); 25836c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul assert(height); 25846c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul assert(depth); 25859c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 25869c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt *unpackNew = *unpack; 25879c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 25889c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (unpackNew->RowLength == 0) 25899c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->RowLength = *width; 25909c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 25916c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul if (unpackNew->ImageHeight == 0) 25929c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpackNew->ImageHeight = *height; 25939c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 25949c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt assert(*width >= 3); 25956c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul unpackNew->SkipPixels++; /* skip the border */ 25966c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul *width = *width - 2; /* reduce the width by two border pixels */ 25976c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul 25986c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul /* The min height of a texture with a border is 3 */ 25996c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul if (*height >= 3 && target != GL_TEXTURE_1D_ARRAY) { 26006c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul unpackNew->SkipRows++; /* skip the border */ 26016c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul *height = *height - 2; /* reduce the height by two border pixels */ 26026c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul } 26036c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul 26046c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul if (*depth >= 3 && target != GL_TEXTURE_2D_ARRAY) { 26056c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul unpackNew->SkipImages++; /* skip the border */ 26066c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul *depth = *depth - 2; /* reduce the depth by two border pixels */ 26076c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul } 26089c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt} 2609bab484a59b21fff84579a492d079d46e27d486ddBrian Paul 2610d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/** 2611d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions. 2612c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */ 2613d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void 2614d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims, 2615d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum target, GLint level, GLint internalFormat, 2616d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLsizei depth, 2617d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLint border, GLenum format, GLenum type, 2618d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels) 2619c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{ 2620d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLboolean error; 26219c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt struct gl_pixelstore_attrib unpack_no_border; 26229c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; 2623d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2624cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2625c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 2626d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 2627d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n", 2628d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, 2629d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 2630d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_lookup_enum_by_nr(internalFormat), 2631d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, border, 2632d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(format), 2633d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2634d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 2635d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul internalFormat = override_internal_format(internalFormat, width, height); 263611caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 2637d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* target error checking */ 2638d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 2639d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)", 2640d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul dims, _mesa_lookup_enum_by_nr(target)); 2641d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul return; 2642d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul } 2643ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2644d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* general error checking */ 2645d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul error = texture_error_check(ctx, dims, target, level, internalFormat, 2646d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul format, type, width, height, depth, border); 26472914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2648d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (_mesa_is_proxy_texture(target)) { 2649d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul /* Proxy texture: just clear or set state depending on error checking */ 2650d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul struct gl_texture_image *texImage = 2651d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_get_proxy_tex_image(ctx, target, level); 265262c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul 2653d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 2654738318bb75dea8dac4465f53850987f6062a732dBrian Paul /* when error, clear all proxy texture image parameters */ 2655a3f137094cd965d27e1b088499dd609b81a91906Brian Paul if (texImage) 2656a3f137094cd965d27e1b088499dd609b81a91906Brian Paul clear_teximage_fields(texImage); 2657c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 265889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 265989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* no error, set the tex image parameters */ 2660bab484a59b21fff84579a492d079d46e27d486ddBrian Paul struct gl_texture_object *texObj = 2661bab484a59b21fff84579a492d079d46e27d486ddBrian Paul _mesa_get_current_tex_object(ctx, target); 2662d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 2663d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul target, level, 266483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, 266583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul format, type); 2666d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2667d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2668892a2542a3f0753a7064c710b96f077dd5490624Brian Paul _mesa_init_teximage_fields(ctx, texImage, width, height, 2669d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul depth, border, internalFormat, 2670d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul texFormat); 26714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 26724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else if (texImage) { 26734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul clear_teximage_fields(texImage); 26744b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 267589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 2676c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2677c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul else { 26788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* non-proxy target */ 2679d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLuint face = _mesa_tex_target_to_face(target); 26800293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 26810293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_image *texImage; 2682f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul 2683d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (error) { 26848e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; /* error was recorded */ 2685c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul } 2686c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul 26879c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt /* Allow a hardware driver to just strip out the border, to provide 26889c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * reliable but slightly incorrect hardware rendering instead of 26899c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt * rarely-tested software fallback rendering. 26909c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt */ 26919c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt if (border && ctx->Const.StripTextureBorder) { 26926c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul strip_texture_border(target, &width, &height, &depth, unpack, 26939c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt &unpack_no_border); 26946c1dea54457c1d19b67794f188c40c74c23ba762Brian Paul border = 0; 26959c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt unpack = &unpack_no_border; 26969c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt } 26979c4b02528752eb6392009e41025202fc9f9ca5b3Eric Anholt 26987ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 26995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_update_state(ctx); 2700fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 2701b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2702d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 27035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 27045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 27055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 2706d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 27075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 2708d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 27095ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 2710ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul else { 271183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 271283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 271368f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 2714ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 271583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 271683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, format, 271783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul type); 271883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 2719d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 2720892a2542a3f0753a7064c710b96f077dd5490624Brian Paul _mesa_init_teximage_fields(ctx, texImage, 2721d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul width, height, depth, 2722d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, internalFormat, texFormat); 272311caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 27244b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul /* Give the texture to the driver. <pixels> may be null. */ 2725c5af8891805fc4f590c1371c098cdbc704c44e00Pauli Nieminen ctx->Driver.TexImage(ctx, dims, texImage, format, 27268f5fffe75d2f8ae7c7ee706b53379a25bc673ae4Brian Paul type, pixels, unpack); 2727ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 27284b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 27292914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2730d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paul _mesa_update_fbo_texture(ctx, texObj, face, level); 2731ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul 2732878c69fe540a73011b676ead33ac8d9b8c9e63aaBrian Paul _mesa_dirty_texobj(ctx, texObj, GL_TRUE); 27334b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 27344b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 2735d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims); 27364b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 2737ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 2738ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 27395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2741d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2742d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2743d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2744d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/* 2745d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API. Note that width includes the border. 2746d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */ 2747d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2748d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 2749d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLint border, GLenum format, 2750d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum type, const GLvoid *pixels ) 2751d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2752d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2753d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 1, target, level, internalFormat, width, 1, 1, 2754d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2755d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul} 2756d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2757d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul 2758d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY 2759d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 2760d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLsizei width, GLsizei height, GLint border, 2761d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GLenum format, GLenum type, 2762d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul const GLvoid *pixels ) 2763d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{ 2764d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul GET_CURRENT_CONTEXT(ctx); 2765d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 2, target, level, internalFormat, width, height, 1, 2766d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2767afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2770afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor. 2772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border. 2773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 2774c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2775b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 2776fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2777fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint border, GLenum format, GLenum type, 2778fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 2780fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 2781d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul teximage(ctx, 3, target, level, internalFormat, width, height, depth, 2782d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul border, format, type, pixels); 2783afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2784afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2785afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2786c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 278743911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 2788663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2789663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul GLint border, GLenum format, GLenum type, 2790663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul const GLvoid *pixels ) 2791663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{ 279289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 2793663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul depth, border, format, type, pixels); 2794663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul} 2795663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2796663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul 2797d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image 2798d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY 2799d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) 2800d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{ 2801d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_object *texObj; 2802d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg struct gl_texture_image *texImage; 2803ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick bool valid_target; 280417efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee GET_CURRENT_CONTEXT(ctx); 280517efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2806d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2807ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick switch (target) { 2808ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick case GL_TEXTURE_2D: 2809ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick valid_target = ctx->Extensions.OES_EGL_image; 2810ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick break; 2811ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick case GL_TEXTURE_EXTERNAL_OES: 2812ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick valid_target = ctx->Extensions.OES_EGL_image_external; 2813ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick break; 2814ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick default: 2815ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick valid_target = false; 2816ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick break; 2817ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick } 2818ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick 2819ea9b212fca78eada7cc7c4449de3f31d2ceea1c3Ian Romanick if (!valid_target) { 2820d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_INVALID_ENUM, 2821d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg "glEGLImageTargetTexture2D(target=%d)", target); 2822d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg return; 2823d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2824d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 28257ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 2826d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_update_state(ctx); 2827d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2828d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj = _mesa_get_current_tex_object(ctx, target); 2829d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_lock_texture(ctx, texObj); 2830d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 283118bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith if (texObj->Immutable) { 283218bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith _mesa_error(ctx, GL_INVALID_OPERATION, 283318bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith "glEGLImageTargetTexture2D(texture is immutable)"); 283418bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith _mesa_unlock_texture(ctx, texObj); 283518bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith return; 283618bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith } 283718bb6852b234a69530a4a6f3ff4e9d33b8e8c7fbDylan Noblesmith 2838d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texImage = _mesa_get_tex_image(ctx, texObj, target, 0); 2839d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg if (!texImage) { 2840d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D"); 2841d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } else { 284268f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 2843d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2844d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg ctx->Driver.EGLImageTargetTexture2D(ctx, target, 2845d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg texObj, texImage, image); 2846d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2847878c69fe540a73011b676ead33ac8d9b8c9e63aaBrian Paul _mesa_dirty_texobj(ctx, texObj, GL_TRUE); 2848d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg } 2849d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg _mesa_unlock_texture(ctx, texObj); 2850d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2851d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg} 2852d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif 2853d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg 2854afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 285545124e043da5a67e1081526d61b99422f4ccde19Brian Paul 285645124e043da5a67e1081526d61b99422f4ccde19Brian Paul/** 285745124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions. 285845124e043da5a67e1081526d61b99422f4ccde19Brian Paul */ 285945124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void 286045124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 286145124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 286245124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLsizei width, GLsizei height, GLsizei depth, 286345124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, const GLvoid *pixels ) 2864afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 28650293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul struct gl_texture_object *texObj; 2866b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul struct gl_texture_image *texImage; 286745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 286875280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 286975280a2c742ee241d392618a3b29548fce1520a9Brian Paul 2870d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 287145124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n", 287245124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, 2873d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 287445124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, width, height, depth, 287545124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_lookup_enum_by_nr(format), 2876d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(type), pixels); 2877d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 287845124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* check target (proxies not allowed) */ 287909a5e028a6d254f619132e302a96c8535018603dBrian Paul if (!legal_texsubimage_target(ctx, dims, target)) { 288045124e043da5a67e1081526d61b99422f4ccde19Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)", 288145124e043da5a67e1081526d61b99422f4ccde19Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 288245124e043da5a67e1081526d61b99422f4ccde19Brian Paul return; 288345124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 288445124e043da5a67e1081526d61b99422f4ccde19Brian Paul 28857ecb61c30c4984a8513b306b640f9d274d8ecf61Brian Paul if (ctx->NewState & _NEW_PIXEL) 288608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 28872aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 288845124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset, 288945124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, format, type)) { 2890f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul return; /* error was detected */ 2891afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 2892afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2893b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 2894afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 28955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 28965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 28975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 2898afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 289945124e043da5a67e1081526d61b99422f4ccde19Brian Paul if (subtexture_error_check2(ctx, dims, target, level, 290045124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 290145124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 290245124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, texImage)) { 2903a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul /* error was recorded */ 29045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29054609e80288bacf19af99b0ed7656eef9bb280912Brian Paul else if (width > 0 && height > 0 && depth > 0) { 290645124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 290745124e043da5a67e1081526d61b99422f4ccde19Brian Paul switch (dims) { 290845124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 3: 29096eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (target != GL_TEXTURE_2D_ARRAY) 29106eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul zoffset += texImage->Border; 291145124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 291245124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 2: 29136eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (target != GL_TEXTURE_1D_ARRAY) 29146eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul yoffset += texImage->Border; 291545124e043da5a67e1081526d61b99422f4ccde19Brian Paul /* fall-through */ 291645124e043da5a67e1081526d61b99422f4ccde19Brian Paul case 1: 291745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset += texImage->Border; 291845124e043da5a67e1081526d61b99422f4ccde19Brian Paul } 2919347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul 2920e42d00b3f4503a0840575c8e5f4517a66c8af613Brian Paul ctx->Driver.TexSubImage(ctx, dims, texImage, 2921e42d00b3f4503a0840575c8e5f4517a66c8af613Brian Paul xoffset, yoffset, zoffset, 2922e42d00b3f4503a0840575c8e5f4517a66c8af613Brian Paul width, height, depth, 2923e42d00b3f4503a0840575c8e5f4517a66c8af613Brian Paul format, type, pixels, &ctx->Unpack); 29242914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 29252914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 29262914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 2927ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul ctx->NewState |= _NEW_TEXTURE; 2928ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul } 29295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 29305ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 2931afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2932afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2933afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2934c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 293545124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level, 293645124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLint xoffset, GLsizei width, 293745124e043da5a67e1081526d61b99422f4ccde19Brian Paul GLenum format, GLenum type, 293845124e043da5a67e1081526d61b99422f4ccde19Brian Paul const GLvoid *pixels ) 293945124e043da5a67e1081526d61b99422f4ccde19Brian Paul{ 294045124e043da5a67e1081526d61b99422f4ccde19Brian Paul GET_CURRENT_CONTEXT(ctx); 294145124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 1, target, level, 294245124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, 0, 0, 294345124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, 1, 1, 294445124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 294545124e043da5a67e1081526d61b99422f4ccde19Brian Paul} 294645124e043da5a67e1081526d61b99422f4ccde19Brian Paul 294745124e043da5a67e1081526d61b99422f4ccde19Brian Paul 294845124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY 2949fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level, 2950fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 2951fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, 2952fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2953fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2954afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 29552c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 295645124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 2, target, level, 295745124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, 0, 295845124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, 1, 295945124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2960c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul} 2961afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2962afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2963afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2964c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 2965fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level, 2966fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 2967fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLsizei width, GLsizei height, GLsizei depth, 2968fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLenum format, GLenum type, 2969fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul const GLvoid *pixels ) 2970afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 29712c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes GET_CURRENT_CONTEXT(ctx); 297245124e043da5a67e1081526d61b99422f4ccde19Brian Paul texsubimage(ctx, 3, target, level, 297345124e043da5a67e1081526d61b99422f4ccde19Brian Paul xoffset, yoffset, zoffset, 297445124e043da5a67e1081526d61b99422f4ccde19Brian Paul width, height, depth, 297545124e043da5a67e1081526d61b99422f4ccde19Brian Paul format, type, pixels); 2976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 2977afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2978afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 2979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 298011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/** 298156b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul * For glCopyTexSubImage, return the source renderbuffer to copy texel data 298256b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul * from. This depends on whether the texture contains color or depth values. 298356b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul */ 298456b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paulstatic struct gl_renderbuffer * 298556b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paulget_copy_tex_image_source(struct gl_context *ctx, gl_format texFormat) 298656b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul{ 298756b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul if (_mesa_get_format_bits(texFormat, GL_DEPTH_BITS) > 0) { 298856b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul /* reading from depth/stencil buffer */ 298956b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul return ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; 299056b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul } 299156b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul else { 299256b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul /* copying from color buffer */ 299356b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul return ctx->ReadBuffer->_ColorReadBuffer; 299456b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul } 299556b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul} 299656b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul 299756b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul 299856b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul 299956b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul/** 300011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions. 300111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */ 300211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void 300311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims, 300411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum target, GLint level, GLenum internalFormat, 300511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) 3006afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 30072aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_object *texObj; 30082aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul struct gl_texture_image *texImage; 3009e93243f8b7d43695654a36334c8cc5cea140d23cBrian const GLuint face = _mesa_tex_target_to_face(target); 301011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 3011cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3013d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 301411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n", 301511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul dims, 3016d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3017d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 301811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 3019d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 302063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 302108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3022fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 302311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul if (copytexture_error_check(ctx, dims, target, level, internalFormat, 302411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul width, height, border)) 3025ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3026ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3027b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3028a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul 3029638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt if (border && ctx->Const.StripTextureBorder) { 3030638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt x += border; 3031638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt width -= border * 2; 3032638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt if (dims == 2) { 3033638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt y += border; 3034638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt height -= border * 2; 3035638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt } 3036638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt border = 0; 3037638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt } 3038638b657f838266e3d4892d06ff53a1c1bee24a9bEric Anholt 30395ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 30405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 30415ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 304211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul 30435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 304411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 30455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3046c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 30475874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* choose actual hw format */ 30485874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, 30495874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul target, level, 30505874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul internalFormat, 30515874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul GL_NONE, GL_NONE); 30527dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 30535874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (legal_texture_size(ctx, texFormat, width, height, 1)) { 3054cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul GLint srcX = x, srcY = y, dstX = 0, dstY = 0, dstZ = 0; 30557dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul 30565874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Free old texture image */ 30570bb29949ba8a9e5a15dc0640dbb0a4e7990a1d57Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 30582aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 3059892a2542a3f0753a7064c710b96f077dd5490624Brian Paul _mesa_init_teximage_fields(ctx, texImage, width, height, 1, 30604b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 306111caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 30625874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* Allocate texture memory (no pixel data yet) */ 3063c5af8891805fc4f590c1371c098cdbc704c44e00Pauli Nieminen ctx->Driver.TexImage(ctx, dims, texImage, 3064c5af8891805fc4f590c1371c098cdbc704c44e00Pauli Nieminen GL_NONE, GL_NONE, 30658f5fffe75d2f8ae7c7ee706b53379a25bc673ae4Brian Paul NULL, &ctx->Unpack); 30665874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul 30675874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul if (_mesa_clip_copytexsubimage(ctx, &dstX, &dstY, &srcX, &srcY, 30685874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul &width, &height)) { 306956b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul struct gl_renderbuffer *srcRb = 307056b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul get_copy_tex_image_source(ctx, texImage->TexFormat); 307156b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul 3072cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul ctx->Driver.CopyTexSubImage(ctx, dims, texImage, dstX, dstY, dstZ, 3073cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul srcRb, srcX, srcY, width, height); 30745874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul } 30752aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul 30764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 30772914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3078d842a118b26a56c9c5e4310f30f70199c42ea90eBrian Paul _mesa_update_fbo_texture(ctx, texObj, face, level); 3079519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul 3080878c69fe540a73011b676ead33ac8d9b8c9e63aaBrian Paul _mesa_dirty_texobj(ctx, texObj, GL_TRUE); 30814b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 30824b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 30835874890c26f434f54e9218b83fae4eb8175c24e9Brian Paul /* probably too large of image */ 308411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); 30854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3086c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 30875ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 30885ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3089afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3090afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3091afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3092afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3093c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 309411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level, 309511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLenum internalFormat, 309611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, 309711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLsizei width, GLint border ) 3098afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3099fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 310011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); 310111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul} 3102c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 31032914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3104c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 310511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY 310611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 310711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint x, GLint y, GLsizei width, GLsizei height, 310811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GLint border ) 310911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{ 311011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul GET_CURRENT_CONTEXT(ctx); 311111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul copyteximage(ctx, 2, target, level, internalFormat, 311211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul x, y, width, height, border); 3113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 31161c23b860cea93534f726d2a18658444f37f43538Brian Paul 31171c23b860cea93534f726d2a18658444f37f43538Brian Paul/** 31181c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions. 31191c23b860cea93534f726d2a18658444f37f43538Brian Paul */ 31201c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void 31211c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, 31221c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 31231c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint x, GLint y, GLsizei width, GLsizei height) 3124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 31255ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell struct gl_texture_object *texObj; 3126347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul struct gl_texture_image *texImage; 312703bafd1f9fa000abdb794b2ae344a68840c83201Brian 3128cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3130d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 31311c23b860cea93534f726d2a18658444f37f43538Brian Paul _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n", 31321c23b860cea93534f726d2a18658444f37f43538Brian Paul dims, 3133d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), 31341c23b860cea93534f726d2a18658444f37f43538Brian Paul level, xoffset, yoffset, zoffset, x, y, width, height); 3135d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 313663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul if (ctx->NewState & NEW_COPY_TEX_STATE) 313708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_update_state(ctx); 3138fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul 31391c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check1(ctx, dims, target, level)) 3140ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul return; 3141ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul 3142b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 31435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 31445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 31455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 31465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 31475ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 31481c23b860cea93534f726d2a18658444f37f43538Brian Paul if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset, 31491c23b860cea93534f726d2a18658444f37f43538Brian Paul zoffset, width, height, texImage)) { 31501c23b860cea93534f726d2a18658444f37f43538Brian Paul /* error was recored */ 315103bafd1f9fa000abdb794b2ae344a68840c83201Brian } 3152a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul else { 31531c23b860cea93534f726d2a18658444f37f43538Brian Paul /* If we have a border, offset=-1 is legal. Bias by border width. */ 31541c23b860cea93534f726d2a18658444f37f43538Brian Paul switch (dims) { 31551c23b860cea93534f726d2a18658444f37f43538Brian Paul case 3: 31566eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (target != GL_TEXTURE_2D_ARRAY) 31576eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul zoffset += texImage->Border; 31581c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 31591c23b860cea93534f726d2a18658444f37f43538Brian Paul case 2: 31606eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul if (target != GL_TEXTURE_1D_ARRAY) 31616eba268ec65523fe8b2ec7dee670b2b5d4ebe1d9Brian Paul yoffset += texImage->Border; 31621c23b860cea93534f726d2a18658444f37f43538Brian Paul /* fall-through */ 31631c23b860cea93534f726d2a18658444f37f43538Brian Paul case 1: 31641c23b860cea93534f726d2a18658444f37f43538Brian Paul xoffset += texImage->Border; 31651c23b860cea93534f726d2a18658444f37f43538Brian Paul } 316603bafd1f9fa000abdb794b2ae344a68840c83201Brian 3167a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, 3168a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul &width, &height)) { 316956b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul struct gl_renderbuffer *srcRb = 317056b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul get_copy_tex_image_source(ctx, texImage->TexFormat); 317156b57aa360a8bad0c4b68fbdf7c64ac33f9e7661Brian Paul 3172cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul ctx->Driver.CopyTexSubImage(ctx, dims, texImage, 3173cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul xoffset, yoffset, zoffset, 3174cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886dBrian Paul srcRb, x, y, width, height); 31752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 31762914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 31772914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3178a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 3179a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 3180a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul } 31815ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 31825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 31861c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY 31871c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level, 31881c23b860cea93534f726d2a18658444f37f43538Brian Paul GLint xoffset, GLint x, GLint y, GLsizei width ) 31891c23b860cea93534f726d2a18658444f37f43538Brian Paul{ 31901c23b860cea93534f726d2a18658444f37f43538Brian Paul GET_CURRENT_CONTEXT(ctx); 31911c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1); 31921c23b860cea93534f726d2a18658444f37f43538Brian Paul} 31931c23b860cea93534f726d2a18658444f37f43538Brian Paul 31941c23b860cea93534f726d2a18658444f37f43538Brian Paul 3195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3196c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3197fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level, 3198fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, 3199fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3200afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3201fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 32021c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y, 32031c23b860cea93534f726d2a18658444f37f43538Brian Paul width, height); 3204afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 3205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 3208c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 3209fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level, 3210fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 3211fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GLint x, GLint y, GLsizei width, GLsizei height ) 3212afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 3213fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 32141c23b860cea93534f726d2a18658444f37f43538Brian Paul copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, 32151c23b860cea93534f726d2a18658444f37f43538Brian Paul x, y, width, height); 3216afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 32171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32181207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 32191207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 322089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 322189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 322289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/****** Compressed Textures ******/ 322389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/ 322489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 322589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 322689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 322754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture. 322854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */ 322954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint 323054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, 323154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul GLenum glformat) 323254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{ 323354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 323454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return _mesa_format_image_size(mesaFormat, width, height, depth); 323554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul} 323654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 323754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 323807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/* 323907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels. 324007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */ 324107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void 324207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) 324307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{ 324407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); 324507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul _mesa_get_format_block_size(mesaFormat, bw, bh); 324607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul} 324754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 324854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 324954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/** 325089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D(). 3251d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch * \param reason returns reason for error, if any 325289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 325389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 325489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3255f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions, 325689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 325789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum internalFormat, GLsizei width, 325889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei height, GLsizei depth, GLint border, 3259d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch GLsizei imageSize, char **reason) 326089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 32614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLenum proxyTarget = get_proxy_target(target); 32624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLint maxLevels = _mesa_max_texture_levels(ctx, target); 32634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint expectedSize; 32643ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum choose_format; 32653ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum choose_type; 32663ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick GLenum proxy_format; 326789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3268d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = ""; /* no error */ 3269d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch 32707404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!target_can_be_compressed(ctx, target, internalFormat)) { 3271d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "target"; 32727404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_ENUM; 32737404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 32747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 3275c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This will detect any invalid internalFormat value */ 3276d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (!_mesa_is_compressed_format(ctx, internalFormat)) { 3277d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 327889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 3279d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 328089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 32813ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick switch (internalFormat) { 32823ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick#if FEATURE_ES 32833ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGB8_OES: 32843ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGBA8_OES: 32853ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_R5_G6_B5_OES: 32863ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGBA4_OES: 32873ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE4_RGB5_A1_OES: 32883ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGB8_OES: 32893ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGBA8_OES: 32903ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_R5_G6_B5_OES: 32913ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGBA4_OES: 32923ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick case GL_PALETTE8_RGB5_A1_OES: 32933ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick _mesa_cpal_compressed_format_type(internalFormat, &choose_format, 32943ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick &choose_type); 32953ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format = choose_format; 32963ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 32973ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* check level */ 32983ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (level > 0 || level < -maxLevels) { 32993ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "level"; 33003ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_VALUE; 33013ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 33023ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33033ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (dimensions != 2) { 33043ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "compressed paletted textures must be 2D"; 33053ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_OPERATION; 33063ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 33073ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33083ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* Figure out the expected texture size (in bytes). This will be 33093ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * checked against the actual size later. 33103ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 33113ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick expectedSize = _mesa_cpal_compressed_size(level, internalFormat, 33123ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick width, height); 33133ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33143ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* This is for the benefit of the TestProxyTexImage below. It expects 33153ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * level to be non-negative. OES_compressed_paletted_texture uses a 33163ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * weird mechanism where the level specified to glCompressedTexImage2D 33173ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * is -(n-1) number of levels in the texture, and the data specifies the 33183ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * complete mipmap stack. This is done to ensure the palette is the 33193ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * same for all levels. 33203ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 33213ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick level = -level; 33223ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick break; 33233ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick#endif 33243ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33253ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick default: 33263ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_format = GL_NONE; 33273ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_type = GL_NONE; 33283ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format = internalFormat; 33293ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33303ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* check level */ 33313ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick if (level < 0 || level >= maxLevels) { 33323ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick *reason = "level"; 33333ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick return GL_INVALID_VALUE; 33343ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 33353ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 33363ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick /* Figure out the expected texture size (in bytes). This will be 33373ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick * checked against the actual size later. 33383ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick */ 33393ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick expectedSize = compressed_tex_size(width, height, depth, internalFormat); 33403ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick break; 33413ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick } 33423ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick 3343c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* This should really never fail */ 3344d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (_mesa_base_tex_format(ctx, internalFormat) < 0) { 3345d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "internalFormat"; 3346a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick return GL_INVALID_ENUM; 3347d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 3348a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick 33494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* No compressed formats support borders at this time */ 3350d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch if (border != 0) { 3351d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "border != 0"; 335289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3353d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 335489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 335589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* For cube map, width must equal height */ 33562efa3d4f9fd1e1683c5366d402d8740ecfb688e5Brian Paul if (_mesa_is_cube_face(target) && width != height) { 3357d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "width != height"; 335889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 3359d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch } 336089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 33617404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* check image size against compression block size */ 33627404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul { 33637404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul gl_format texFormat = 33643ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick ctx->Driver.ChooseTextureFormat(ctx, proxy_format, 33653ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_format, choose_type); 33667404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul GLuint bw, bh; 33677404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 33687404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul _mesa_get_format_block_size(texFormat, &bw, &bh); 33697404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if ((width > bw && width % bw > 0) || 33707404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul (height > bh && height % bh > 0)) { 33717404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* 33727404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is 33737404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * generated [...] if any parameter combinations are not 33747404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * supported by the specific compressed internal format. 33757404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3376d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width or height for compression format"; 33777404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 33787404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 33797404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 33807404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul 33814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image sizes */ 33824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level, 33833ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick proxy_format, choose_format, 33843ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick choose_type, 33853ebbfc8372d410801c799b3eb7821075dae73b17Ian Romanick width, height, depth, border)) { 33867404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* See error comment above */ 3387d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "invalid width, height or format"; 33887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul return GL_INVALID_OPERATION; 33894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 339089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 33914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check image size in bytes */ 33927404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (expectedSize != imageSize) { 33937404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...] 33947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * if <imageSize> is not consistent with the format, dimensions, and 33957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * contents of the specified image. 33967404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul */ 3397d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch *reason = "imageSize inconsistant with width/height/format"; 339889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 33997404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul } 340089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3401a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul if (!mutable_tex_object(ctx, target)) { 3402a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul *reason = "immutable texture"; 3403a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul return GL_INVALID_OPERATION; 3404a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul } 3405a0d736b3b7c325ab0295da3b0e3b92d170b44261Brian Paul 340689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 340789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 340889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 340989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 341089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 341189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D(). 34122371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning There are some bad assumptions here about the size of compressed 34132371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * texture tiles (multiple of 4) used to test the validity of the 34142371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * offset and size parameters. 341589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR. 341689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 341789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum 3418f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, 341989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum target, GLint level, 342089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint xoffset, GLint yoffset, GLint zoffset, 342189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLsizei width, GLsizei height, GLsizei depth, 342289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum format, GLsizei imageSize) 342389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 342489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLint expectedSize, maxLevels = 0, maxTextureSize; 342507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul GLuint bw, bh; 3426a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul (void) zoffset; 342789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 342889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (dimensions == 1) { 342989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 1D compressed textures not allowed */ 343089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 343189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 343289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 2) { 343389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (target == GL_PROXY_TEXTURE_2D) { 343489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 343589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 343689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_TEXTURE_2D) { 343789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxTextureLevels; 343889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 343989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) { 344089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 344189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 344289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 344389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 34442efa3d4f9fd1e1683c5366d402d8740ecfb688e5Brian Paul else if (_mesa_is_cube_face(target)) { 344589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (!ctx->Extensions.ARB_texture_cube_map) 344689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 344789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxLevels = ctx->Const.MaxCubeTextureLevels; 344889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 344989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else { 345089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; /*target*/ 345189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 345289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 345389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul else if (dimensions == 3) { 345489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul /* 3D compressed textures not allowed */ 345589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 345689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 345789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 345889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul maxTextureSize = 1 << (maxLevels - 1); 345989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3460c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul /* this will catch any invalid compressed format token */ 3461c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul if (!_mesa_is_compressed_format(ctx, format)) 346289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_ENUM; 346389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3464887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if (width < 1 || width > maxTextureSize) 346589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 346689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3467887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul if ((height < 1 || height > maxTextureSize) 346889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul && dimensions > 1) 346989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 347089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 347189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (level < 0 || level >= maxLevels) 347289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 347389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 347407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul /* 347507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * do checks which depend on compression block size 34762371033bbaf6e7477bfa893654a0467a084f335bBrian Paul */ 347707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul get_compressed_block_size(format, &bw, &bh); 347807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul 347907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((xoffset % bw != 0) || (yoffset % bh != 0)) 348089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 348189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 348207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((width % bw != 0) && width != 2 && width != 1) 348389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 348489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 348507ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul if ((height % bh != 0) && height != 2 && height != 1) 348689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 348789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 348854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul expectedSize = compressed_tex_size(width, height, depth, format); 348989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (expectedSize != imageSize) 349089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_INVALID_VALUE; 349189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 349289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return GL_NO_ERROR; 349389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 349489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 349589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3496f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/** 3497f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking. 3498f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise. 3499f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */ 3500f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean 3501f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims, 3502f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei width, GLsizei height, 3503f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul GLsizei depth, GLenum format, 3504f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul struct gl_texture_image *texImage) 3505f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{ 3506f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3507f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if ((GLint) format != texImage->InternalFormat) { 3508f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, 3509f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(format=0x%x)", dims, format); 3510f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3511f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3512f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3513d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (compressedteximage_only_format(ctx, format)) { 3514d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu _mesa_error(ctx, GL_INVALID_OPERATION, 3515d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu "glCompressedTexSubImage%uD(format=0x%x cannot be updated)" 3516d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu , dims, format); 3517d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_TRUE; 3518d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 3519d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 3520f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((width == 1 || width == 2) && 3521ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul width != (GLsizei) texImage->Width) || 3522ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (width > (GLsizei) texImage->Width)) { 3523f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3524f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(width=%d)", dims, width); 3525f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3526f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3527f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3528f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 2) { 3529f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((height == 1 || height == 2) && 3530ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul height != (GLsizei) texImage->Height) || 3531ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (height > (GLsizei) texImage->Height)) { 3532f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3533f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(height=%d)", dims, height); 3534f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3535f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3536f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3537f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3538f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (dims >= 3) { 3539f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul if (((depth == 1 || depth == 2) && 3540ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul depth != (GLsizei) texImage->Depth) || 3541ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul (depth > (GLsizei) texImage->Depth)) { 3542f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul _mesa_error(ctx, GL_INVALID_VALUE, 3543f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul "glCompressedTexSubImage%uD(depth=%d)", dims, depth); 3544f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_TRUE; 3545f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3546f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul } 3547f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3548f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul return GL_FALSE; 3549f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul} 3550f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 3551f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul 35524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/** 35534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions. 35544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */ 35554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void 35564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims, 35574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum target, GLint level, 35584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 35594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 35604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 35611207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 35624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum error; 3563d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch char *reason = ""; 35644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 3565cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3566aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3567d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 35684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_debug(ctx, 35694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n", 35704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, 3571d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(target), level, 3572d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora _mesa_lookup_enum_by_nr(internalFormat), 35734ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 35745ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 35754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* check target */ 35767404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul if (!legal_teximage_target(ctx, dims, target)) { 35774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)", 35784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul dims, _mesa_lookup_enum_by_nr(target)); 3579aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul return; 3580aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 35811207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 35824ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = compressed_texture_error_check(ctx, dims, target, level, 35834ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, width, height, depth, 3584d5a5893adc395158e1dc77dacd417f4eb2696237Carl-Philip Haensch border, imageSize, &reason); 3585d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora 3586af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul#if FEATURE_ES 3587af0e2ef8cc5c823e3c950233a09b8de87933a363Brian Paul /* XXX this is kind of a hack */ 358889efc1b839591473d0a448dc1087a5deb56579c7Brian Paul if (!error && dims == 2) { 35894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul switch (internalFormat) { 35904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB8_OES: 35914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA8_OES: 35924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_R5_G6_B5_OES: 35934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGBA4_OES: 35944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE4_RGB5_A1_OES: 35954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB8_OES: 35964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA8_OES: 35974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_R5_G6_B5_OES: 35984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGBA4_OES: 35994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul case GL_PALETTE8_RGB5_A1_OES: 36004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_cpal_compressed_teximage2d(target, level, internalFormat, 36014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, imageSize, data); 360289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3603aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 36044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 36054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif 3606aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 36074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (_mesa_is_proxy_texture(target)) { 36084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* Proxy texture: just check for errors and update proxy state */ 36094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_image *texImage; 36102914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 36118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul if (!error) { 36124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul struct gl_texture_object *texObj = 36134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_get_current_tex_object(ctx, target); 36144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul gl_format texFormat = 36154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_choose_texture_format(ctx, texObj, target, level, 36164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul internalFormat, GL_NONE, GL_NONE); 36174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (!legal_texture_size(ctx, texFormat, width, height, depth)) { 36184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul error = GL_OUT_OF_MEMORY; 36194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 3620aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 36215ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell 36224ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul texImage = _mesa_get_proxy_tex_image(ctx, target, level); 36234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (texImage) { 36244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul if (error) { 36254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* if error, clear all proxy texture image parameters */ 36264ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul clear_teximage_fields(texImage); 36274ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 36284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul else { 36294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul /* no error: store the teximage parameters */ 3630892a2542a3f0753a7064c710b96f077dd5490624Brian Paul _mesa_init_teximage_fields(ctx, texImage, width, height, 36314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul depth, border, internalFormat, 36324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul MESA_FORMAT_NONE); 36334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul } 363489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 3635aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3636aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul else { 36378c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul /* non-proxy target */ 3638aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_object *texObj; 3639aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul struct gl_texture_image *texImage; 36404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 364189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 364289efc1b839591473d0a448dc1087a5deb56579c7Brian Paul _mesa_error(ctx, error, "glCompressedTexImage%uD(%s)", dims, reason); 364389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 3644aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 3645aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul 3646b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 36479519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 36485ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 36495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 36505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_get_tex_image(ctx, texObj, target, level); 36515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell if (!texImage) { 36524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 36534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 36545ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 3655c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul else { 365683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul gl_format texFormat; 365783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 365868f8cf72638e974a5bf2ae3e88c2e3539d88e2b6Eric Anholt ctx->Driver.FreeTextureImageBuffer(ctx, texImage); 3659c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 366083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, 366183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul internalFormat, GL_NONE, 366283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul GL_NONE); 366383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul 36644b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul if (legal_texture_size(ctx, texFormat, width, height, depth)) { 3665892a2542a3f0753a7064c710b96f077dd5490624Brian Paul _mesa_init_teximage_fields(ctx, texImage, 36664b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul width, height, depth, 36674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul border, internalFormat, texFormat); 366811caea687e3f10ae12d33e44edf84635f73047ddBrian Paul 36695606bd574e264c4beda8eb1d10b48d17e9b8b497Pauli Nieminen ctx->Driver.CompressedTexImage(ctx, dims, texImage, imageSize, 36705606bd574e264c4beda8eb1d10b48d17e9b8b497Pauli Nieminen data); 3671c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 36724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul check_gen_mipmap(ctx, target, texObj, level); 36732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 3674878c69fe540a73011b676ead33ac8d9b8c9e63aaBrian Paul _mesa_dirty_texobj(ctx, texObj, GL_TRUE); 36754b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 36764b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul else { 36774ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, 36784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul "glCompressedTexImage%uD", dims); 36794b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul } 3680c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 3681c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 36825ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 3683aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul } 36844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 36859519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 36869519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul 36874ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 36884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level, 36894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 36904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLint border, GLsizei imageSize, 36914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 36924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 36934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 36944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 1, target, level, internalFormat, 36954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, 1, 1, border, imageSize, data); 36964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 36974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 36984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 36994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 37004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level, 37014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 37024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLint border, GLsizei imageSize, 37034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul const GLvoid *data) 37044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 37054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 37064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 2, target, level, internalFormat, 37074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, 1, border, imageSize, data); 37084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul} 37094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 37104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul 37114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY 37124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level, 37134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLenum internalFormat, GLsizei width, 37144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei height, GLsizei depth, GLint border, 37154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GLsizei imageSize, const GLvoid *data) 37164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{ 37174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul GET_CURRENT_CONTEXT(ctx); 37184ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul compressedteximage(ctx, 3, target, level, internalFormat, 37194ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul width, height, depth, border, imageSize, data); 37201207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37211207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37221207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/** 37246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D(). 37256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */ 37266bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void 37276bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level, 37286bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLint xoffset, GLint yoffset, GLint zoffset, 37296bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLsizei height, GLsizei depth, 37306bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLenum format, GLsizei imageSize, const GLvoid *data) 37311207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 37329540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_object *texObj; 37339540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul struct gl_texture_image *texImage; 373489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLenum error; 3735a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul GET_CURRENT_CONTEXT(ctx); 373675280a2c742ee241d392618a3b29548fce1520a9Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 373775280a2c742ee241d392618a3b29548fce1520a9Brian Paul 37386bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul error = compressed_subtexture_error_check(ctx, dims, target, level, 3739c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul xoffset, 0, 0, /* pos */ 37406bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, /* size */ 3741c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul format, imageSize); 374289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul if (error) { 37436bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims); 374489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul return; 37459540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 37469540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 3747b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul texObj = _mesa_get_current_tex_object(ctx, target); 3748c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul 37495ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_lock_texture(ctx, texObj); 37505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell { 37515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell texImage = _mesa_select_tex_image(ctx, texObj, target, level); 37525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell assert(texImage); 37539540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul 37546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul if (compressed_subtexture_error_check2(ctx, dims, width, height, depth, 3755f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul format, texImage)) { 3756f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul /* error was recorded */ 3757c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul } 37586bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul else if (width > 0 && height > 0 && depth > 0) { 3759ec19bdd16c3d4070af69fd865042babe0a627595Brian Paul ctx->Driver.CompressedTexSubImage(ctx, dims, texImage, 3760ec19bdd16c3d4070af69fd865042babe0a627595Brian Paul xoffset, yoffset, zoffset, 3761ec19bdd16c3d4070af69fd865042babe0a627595Brian Paul width, height, depth, 3762ec19bdd16c3d4070af69fd865042babe0a627595Brian Paul format, imageSize, data); 37632914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 37642914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul check_gen_mipmap(ctx, target, texObj, level); 37652914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul 37662914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul ctx->NewState |= _NEW_TEXTURE; 37675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell } 37689540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul } 37695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell _mesa_unlock_texture(ctx, texObj); 37701207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3773c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 37746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 37756bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei width, GLenum format, 37766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul GLsizei imageSize, const GLvoid *data) 37776bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{ 37786bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1, 37796bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul format, imageSize, data); 37806bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul} 37816bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 37826bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul 37836bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY 37841207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 37851207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLsizei width, GLsizei height, 37861207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLenum format, GLsizei imageSize, 37871207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul const GLvoid *data) 37881207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 37896bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0, 37906bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, 1, format, imageSize, data); 37911207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 37921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 37931207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul 3794c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 37951207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 37961207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLint yoffset, GLint zoffset, GLsizei width, 37971207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei height, GLsizei depth, GLenum format, 37981207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul GLsizei imageSize, const GLvoid *data) 37991207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{ 38006bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, 38016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul width, height, depth, format, imageSize, data); 38021207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul} 3803874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3804664355f05b39303fa0995b72160c82f5bf50e95eEric Anholtstatic gl_format 3805664355f05b39303fa0995b72160c82f5bf50e95eEric Anholtget_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat) 3806874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3807874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul switch (internalFormat) { 3808874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8: 3809664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_A8; 3810874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16: 3811664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_A16; 3812874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16F_ARB: 3813664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_FLOAT16; 3814874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32F_ARB: 3815664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_FLOAT32; 3816874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8I_EXT: 3817664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_INT8; 3818874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16I_EXT: 3819664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_INT16; 3820874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32I_EXT: 3821664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_INT32; 3822874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA8UI_EXT: 3823664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_UINT8; 3824874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA16UI_EXT: 3825664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_UINT16; 3826874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_ALPHA32UI_EXT: 3827664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_ALPHA_UINT32; 3828874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8: 3829664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_L8; 3830874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16: 3831664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_L16; 3832874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16F_ARB: 3833664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_FLOAT16; 3834874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32F_ARB: 3835664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_FLOAT32; 3836874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8I_EXT: 3837664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_INT8; 3838874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16I_EXT: 3839664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_INT16; 3840874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32I_EXT: 3841664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_INT32; 3842874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8UI_EXT: 3843664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_UINT8; 3844874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16UI_EXT: 3845664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_UINT16; 3846874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE32UI_EXT: 3847664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_UINT32; 3848874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE8_ALPHA8: 3849664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_AL88; 3850874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE16_ALPHA16: 3851664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_AL1616; 3852874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16F_ARB: 3853664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16; 3854874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32F_ARB: 3855664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32; 3856874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8I_EXT: 3857664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_INT8; 3858874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16I_EXT: 3859664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_INT8; 3860874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32I_EXT: 3861664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_INT16; 3862874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA8UI_EXT: 3863664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_UINT8; 3864874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA16UI_EXT: 3865664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_UINT16; 3866874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_LUMINANCE_ALPHA32UI_EXT: 3867664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_LUMINANCE_ALPHA_UINT32; 3868874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8: 3869664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_I8; 3870874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16: 3871664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_I16; 3872874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16F_ARB: 3873664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_FLOAT16; 3874874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32F_ARB: 3875664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_FLOAT32; 3876874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8I_EXT: 3877664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_INT8; 3878874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16I_EXT: 3879664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_INT16; 3880874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32I_EXT: 3881664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_INT32; 3882874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY8UI_EXT: 3883664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_UINT8; 3884874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY16UI_EXT: 3885664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_UINT16; 3886874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_INTENSITY32UI_EXT: 3887664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_INTENSITY_UINT32; 3888874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8: 3889664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA8888_REV; 3890874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16: 3891664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_16; 3892874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16F_ARB: 3893664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_FLOAT16; 3894874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32F_ARB: 3895664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_FLOAT32; 3896874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8I_EXT: 3897664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_INT8; 3898874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16I_EXT: 3899664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_INT16; 3900874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32I_EXT: 3901664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_INT32; 3902874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA8UI_EXT: 3903664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_UINT8; 3904874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA16UI_EXT: 3905664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_UINT16; 3906874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul case GL_RGBA32UI_EXT: 3907664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_RGBA_UINT32; 3908bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt 3909bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG8: 3910bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_GR88; 3911bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG16: 3912bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG1616; 3913bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG16F: 3914bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_FLOAT16; 3915bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG32F: 3916bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_FLOAT32; 3917bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG8I: 3918bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_INT8; 3919bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG16I: 3920bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_INT16; 3921bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG32I: 3922bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_INT32; 3923bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG8UI: 3924bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_UINT8; 3925bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG16UI: 3926bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_UINT16; 3927bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_RG32UI: 3928bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_RG_UINT32; 3929bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt 3930bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R8: 3931bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R8; 3932bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R16: 3933bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R16; 3934bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R16F: 3935bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_FLOAT16; 3936bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R32F: 3937bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_FLOAT32; 3938bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R8I: 3939bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_INT8; 3940bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R16I: 3941bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_INT16; 3942bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R32I: 3943bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_INT32; 3944bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R8UI: 3945bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_UINT8; 3946bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R16UI: 3947bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_UINT16; 3948bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt case GL_R32UI: 3949bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_R_UINT32; 3950bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt 3951874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul default: 3952664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_NONE; 3953874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 3954664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt} 3955874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3956664355f05b39303fa0995b72160c82f5bf50e95eEric Anholtstatic gl_format 3957664355f05b39303fa0995b72160c82f5bf50e95eEric Anholtvalidate_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat) 3958664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt{ 3959664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt gl_format format = get_texbuffer_format(ctx, internalFormat); 3960664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt GLenum datatype; 3961874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3962664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt if (format == MESA_FORMAT_NONE) 3963664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_NONE; 3964874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3965664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt datatype = _mesa_get_format_datatype(format); 3966664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt if (datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float) 3967664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_NONE; 3968664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt 3969664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt if (datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel) 3970664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return MESA_FORMAT_NONE; 3971664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt 3972bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make 3973bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt * any mention of R/RG formats, but they appear in the GL 3.1 core 3974bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt * specification. 3975bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt */ 39769c1b41879aab2ff7386c547a2ccce7686c018cf5Eric Anholt if (ctx->Version <= 30) { 3977bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt GLenum base_format = _mesa_get_format_base_format(format); 3978bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt 3979bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt if (base_format == GL_R || base_format == GL_RG) 3980bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt return MESA_FORMAT_NONE; 3981bf82ce3c66507e5e1722fccff0df47cf9dcdb2d4Eric Anholt } 3982664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt return format; 3983874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 3984874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3985874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3986874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul/** GL_ARB_texture_buffer_object */ 3987874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paulvoid GLAPIENTRY 3988874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) 3989874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul{ 3990874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_texture_object *texObj; 3991874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul struct gl_buffer_object *bufObj; 3992664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt gl_format format; 3993874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3994874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul GET_CURRENT_CONTEXT(ctx); 3995874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3996874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 3997874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (!ctx->Extensions.ARB_texture_buffer_object) { 3998874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer"); 3999874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 4000874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 4001874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 4002874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (target != GL_TEXTURE_BUFFER_ARB) { 4003874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)"); 4004874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 4005874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 4006874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 4007664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt format = validate_texbuffer_format(ctx, internalFormat); 4008664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt if (format == MESA_FORMAT_NONE) { 4009874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)", 4010874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul internalFormat); 4011874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 4012874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 4013874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 4014874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul bufObj = _mesa_lookup_bufferobj(ctx, buffer); 4015874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul if (buffer && !bufObj) { 4016874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer); 4017874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul return; 4018874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 4019874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 4020874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj = _mesa_get_current_tex_object(ctx, target); 4021874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul 4022874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_lock_texture(ctx, texObj); 4023874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul { 4024874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj); 4025874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul texObj->BufferObjectFormat = internalFormat; 4026664355f05b39303fa0995b72160c82f5bf50e95eEric Anholt texObj->_BufferObjectFormat = format; 4027874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul } 4028874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul _mesa_unlock_texture(ctx, texObj); 4029874a2c0b7da62f4dd08dedcec221f55b22e40e95Brian Paul} 4030