teximage.c revision 7404fa3f07a953343f2640fa97d82ab82ba5545d
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
2be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian * mesa 3-D graphics library
325be043940b25a5fe6eb8058070b3e8f12e92039Brian Paul * Version:  7.6
45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
59f6022d0567dc1288888212d7128acc48795b306Brian * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a
9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"),
10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation
11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the
13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions:
145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included
16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software.
175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
27add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul/**
28add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul * \file teximage.c
2977ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul * Texture image-related functions.
30add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul */
31add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul
32add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul
33fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h"
34b46712ca9d379d9c091f5543500088d82cf9776cBrian Paul#include "bufferobj.h"
35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h"
36d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora#include "enums.h"
3734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "fbobject.h"
3834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul#include "framebuffer.h"
392897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul#include "hash.h"
40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h"
413c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h"
42ebb248aa5c018dc676d389221d76ed329059789eBrian Paul#include "macros.h"
43fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul#include "state.h"
4489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h"
451a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul#include "texfetch.h"
46afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "teximage.h"
47afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "texstate.h"
487179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#include "texpal.h"
495e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h"
50afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
524cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/**
5363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * State changes which we care about for glCopyTex[Sub]Image() calls.
5463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * In particular, we care about pixel transfer state and buffer state
5563f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul * (such as glReadBuffer to make sure we read from the right renderbuffer).
5663f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul */
5763f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul#define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
5863f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul                            _NEW_BUFFERS | \
5963f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul                            _NEW_PIXEL)
6063f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul
6163f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul
6263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul
6363f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul/**
644cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
654cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * elsewhere.
664cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */
674cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid *
684cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_alloc_texmemory(GLsizei bytes)
694cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{
704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul   return _mesa_align_malloc(bytes, 512);
714cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul}
724cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul
734cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul
744cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul/**
754cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * Free texture memory allocated with _mesa_alloc_texmemory()
764cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul */
774cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paulvoid
784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul_mesa_free_texmemory(void *m)
794cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul{
804cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul   _mesa_align_free(m);
814cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul}
824cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul
834cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul
84f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul/*
85887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Compute floor(log_base_2(n)).
86973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul * If n < 0 return -1.
87afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
88fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paulstatic int
89fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paullogbase2( int n )
90afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLint i = 1;
92afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLint log2 = 0;
93afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
94973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul   if (n < 0)
95afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return -1;
96973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul
97973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul   if (n == 0)
98973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul      return 0;
99afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   while ( n > i ) {
101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      i *= 2;
102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      log2++;
103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (i != n) {
105887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul      return log2 - 1;
106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else {
108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return log2;
109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
1151749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * Return the simple base format for a given internal texture format.
1161749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
1176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
1186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
1191749a25ca889d514889b34cf6311c8014d97bf66Brian Paul * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
1206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
1226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
12389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul *
12489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * This is the format which is used during texture application (i.e. the
12589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * texture format and env mode determine the arithmetic used.
12673b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul *
12773b150c816c46a88e3e5d97f9b73ab0095f2bc60Brian Paul * XXX this could be static
128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
129b132e8da5e5f2b7da1f2141e0322e66bb0608e02Brian PaulGLint
130f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1321749a25ca889d514889b34cf6311c8014d97bf66Brian Paul   switch (internalFormat) {
133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_ALPHA:
134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_ALPHA4:
135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_ALPHA8:
136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_ALPHA12:
137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_ALPHA16:
138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_ALPHA;
139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case 1:
140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE:
141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE4:
142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE8:
143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE12:
144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE16:
145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_LUMINANCE;
146afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case 2:
147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE_ALPHA:
148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE4_ALPHA4:
149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE6_ALPHA2:
150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE8_ALPHA8:
151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE12_ALPHA4:
152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE12_ALPHA12:
153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_LUMINANCE16_ALPHA16:
154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_LUMINANCE_ALPHA;
155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_INTENSITY:
156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_INTENSITY4:
157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_INTENSITY8:
158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_INTENSITY12:
159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_INTENSITY16:
160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_INTENSITY;
161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case 3:
162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB:
163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_R3_G3_B2:
164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB4:
165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB5:
166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB8:
167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB10:
168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB12:
169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB16:
170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_RGB;
171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case 4:
172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA:
173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA2:
174afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA4:
175afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB5_A1:
176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA8:
177afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGB10_A2:
178afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA12:
179afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GL_RGBA16:
180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_RGBA;
181f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      default:
182f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         ; /* fallthrough */
183f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
184f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
185f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.EXT_paletted_texture) {
186f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
187f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX:
188f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX1_EXT:
189f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX2_EXT:
190f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX4_EXT:
191f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX8_EXT:
192f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX12_EXT:
193f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COLOR_INDEX16_EXT:
194e71654961868eac559210ced359c1af114138d8aBrian Paul            return GL_COLOR_INDEX;
195f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
196f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            ; /* fallthrough */
197f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
198f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
199f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
2004741dbcbbc2514de370a760f4b78a17491014555Ian Romanick   if (ctx->Extensions.ARB_depth_texture) {
201f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
202f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_DEPTH_COMPONENT:
2034741dbcbbc2514de370a760f4b78a17491014555Ian Romanick         case GL_DEPTH_COMPONENT16:
2044741dbcbbc2514de370a760f4b78a17491014555Ian Romanick         case GL_DEPTH_COMPONENT24:
2054741dbcbbc2514de370a760f4b78a17491014555Ian Romanick         case GL_DEPTH_COMPONENT32:
206f7e1dfeaefda8865252513bc4d880ea8640efe4dBrian Paul            return GL_DEPTH_COMPONENT;
207f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
208f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            ; /* fallthrough */
209f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
210f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
21189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
21233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   switch (internalFormat) {
21333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_ALPHA:
21433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_ALPHA;
21533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_LUMINANCE:
21633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_LUMINANCE;
21733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_LUMINANCE_ALPHA:
21833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_LUMINANCE_ALPHA;
21933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_INTENSITY:
22033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_INTENSITY;
22133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_RGB:
22233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_RGB;
22333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   case GL_COMPRESSED_RGBA:
22433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      return GL_RGBA;
22533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick   default:
22633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick      ; /* fallthrough */
227f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
228f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
229f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.TDFX_texture_compression_FXT1) {
230f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
231f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COMPRESSED_RGB_FXT1_3DFX:
23289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul            return GL_RGB;
233f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COMPRESSED_RGBA_FXT1_3DFX:
23489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul            return GL_RGBA;
235f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
236f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            ; /* fallthrough */
237f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
238f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
239f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
240f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.EXT_texture_compression_s3tc) {
241f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
2428f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul         case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2438f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul            return GL_RGB;
244f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
245f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
246f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
24740bd9d0b190e11d39350d1b08d2c2b28e3040bcaDaniel Borca            return GL_RGBA;
248f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
249f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            ; /* fallthrough */
250f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
251f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
252f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
253f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.S3_s3tc) {
254f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
255f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGB_S3TC:
256f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGB4_S3TC:
257663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca            return GL_RGB;
258f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGBA_S3TC:
259f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGBA4_S3TC:
260663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca            return GL_RGBA;
261f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
262f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            ; /* fallthrough */
263f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
264f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
26589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
266f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.MESA_ycbcr_texture) {
267f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      if (internalFormat == GL_YCBCR_MESA)
268f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         return GL_YCBCR_MESA;
269f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   }
2701749a25ca889d514889b34cf6311c8014d97bf66Brian Paul
271f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (ctx->Extensions.ARB_texture_float) {
272f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      switch (internalFormat) {
273f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_ALPHA16F_ARB:
274f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_ALPHA32F_ARB:
275f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_ALPHA;
276f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGBA16F_ARB:
277f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGBA32F_ARB:
278f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_RGBA;
279f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGB16F_ARB:
280f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_RGB32F_ARB:
281f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_RGB;
282f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_INTENSITY16F_ARB:
283f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_INTENSITY32F_ARB:
284f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_INTENSITY;
285f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_LUMINANCE16F_ARB:
286f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_LUMINANCE32F_ARB:
287f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_LUMINANCE;
288f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_LUMINANCE_ALPHA16F_ARB:
289f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         case GL_LUMINANCE_ALPHA32F_ARB:
290f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul            return GL_LUMINANCE_ALPHA;
291f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul         default:
2928f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul            ; /* fallthrough */
293f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul      }
294afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
295f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul
296114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger   if (ctx->Extensions.ATI_envmap_bumpmap) {
297114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger      switch (internalFormat) {
298114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger         case GL_DUDV_ATI:
299114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger         case GL_DU8DV8_ATI:
300114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger            return GL_DUDV_ATI;
301114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger         default:
302114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger            ; /* fallthrough */
303114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger      }
304114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger   }
305114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger
306c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger   if (ctx->Extensions.MESA_texture_signed_rgba) {
307c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger      switch (internalFormat) {
308c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger         case GL_RGBA_SNORM:
309c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger         case GL_RGBA8_SNORM:
310c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger            return GL_RGBA;
311c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger         default:
312c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger            ; /* fallthrough */
313c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger      }
314c6a6cc191813e8343a17b028146a34f193a6ce44Roland Scheidegger   }
315114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger
3161ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul   if (ctx->Extensions.EXT_packed_depth_stencil) {
3171ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul      switch (internalFormat) {
3181ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul         case GL_DEPTH_STENCIL_EXT:
3191ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul         case GL_DEPTH24_STENCIL8_EXT:
3201ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul            return GL_DEPTH_STENCIL_EXT;
3211ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul         default:
3221ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul            ; /* fallthrough */
3231ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul      }
3241ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul   }
3251ad7b99925e044f82e635f746c1ef2df77f69ac9Brian Paul
3260a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#if FEATURE_EXT_texture_sRGB
3270a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul   if (ctx->Extensions.EXT_texture_sRGB) {
3280a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      switch (internalFormat) {
3290a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SRGB_EXT:
3300a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SRGB8_EXT:
3310a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_EXT:
3320a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
3330a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul         return GL_RGB;
3340a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SRGB_ALPHA_EXT:
3350a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SRGB8_ALPHA8_EXT:
3360a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_ALPHA_EXT:
3370a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
3380a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
3390a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
3400a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul         return GL_RGBA;
3410a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SLUMINANCE_ALPHA_EXT:
3420a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SLUMINANCE8_ALPHA8_EXT:
3430a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SLUMINANCE_EXT:
3440a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
3450a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul         return GL_LUMINANCE_ALPHA;
3460a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SLUMINANCE_EXT:
3470a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      case GL_SLUMINANCE8_EXT:
3480a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul         return GL_LUMINANCE;
3490a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      default:
350abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         ; /* fallthrough */
3510a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul      }
3520a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul   }
3530a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul#endif /* FEATURE_EXT_texture_sRGB */
3540a4be7036864efa6b30d78e0aac449d34b812c13Brian Paul
355abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul   if (ctx->Extensions.EXT_texture_integer) {
356abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      switch (internalFormat) {
357abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA8UI_EXT:
358abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA16UI_EXT:
359abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA32UI_EXT:
360abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA8I_EXT:
361abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA16I_EXT:
362abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGBA32I_EXT:
363abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_RGBA;
364abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB8UI_EXT:
365abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB16UI_EXT:
366abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB32UI_EXT:
367abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB8I_EXT:
368abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB16I_EXT:
369abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_RGB32I_EXT:
370abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_RGB;
371abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA8UI_EXT:
372abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA16UI_EXT:
373abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA32UI_EXT:
374abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA8I_EXT:
375abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA16I_EXT:
376abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_ALPHA32I_EXT:
377abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_ALPHA;
378abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY8UI_EXT:
379abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY16UI_EXT:
380abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY32UI_EXT:
381abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY8I_EXT:
382abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY16I_EXT:
383abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_INTENSITY32I_EXT:
384abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_INTENSITY;
385abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE8UI_EXT:
386abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE16UI_EXT:
387abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE32UI_EXT:
388abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE8I_EXT:
389abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE16I_EXT:
390abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE32I_EXT:
391abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_LUMINANCE;
392abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA8UI_EXT:
393abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA16UI_EXT:
394abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA32UI_EXT:
395abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA8I_EXT:
396abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA16I_EXT:
397abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      case GL_LUMINANCE_ALPHA32I_EXT:
398abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         return GL_LUMINANCE_ALPHA;
399abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      default:
400abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul         ; /* fallthrough */
401abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul      }
4026988f65e43297ae63bbce30bf882f870b370096cBrian Paul   }
4036988f65e43297ae63bbce30bf882f870b370096cBrian Paul
4046988f65e43297ae63bbce30bf882f870b370096cBrian Paul   if (ctx->Extensions.ARB_texture_rg) {
4056988f65e43297ae63bbce30bf882f870b370096cBrian Paul      switch (internalFormat) {
4066988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R16F:
4073ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
4083ebbc176f9200ac954d461758937e755220ac551Ian Romanick	  */
4093ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.ARB_half_float_pixel)
4103ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4113ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* FALLTHROUGH */
4126988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R32F:
4133ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.ARB_texture_float)
4143ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4153ebbc176f9200ac954d461758937e755220ac551Ian Romanick         return GL_RED;
4166988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R8I:
4176988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R8UI:
4186988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R16I:
4196988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R16UI:
4206988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R32I:
4216988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R32UI:
4223ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.EXT_texture_integer)
4233ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4243ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* FALLTHROUGH */
4253ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_R8:
4263ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_R16:
4273ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_RED:
4283ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_COMPRESSED_RED:
4293ebbc176f9200ac954d461758937e755220ac551Ian Romanick         return GL_RED;
4303ebbc176f9200ac954d461758937e755220ac551Ian Romanick
4316988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG16F:
4323ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
4333ebbc176f9200ac954d461758937e755220ac551Ian Romanick	  */
4343ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.ARB_half_float_pixel)
4353ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4363ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* FALLTHROUGH */
4376988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG32F:
4383ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.ARB_texture_float)
4393ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4403ebbc176f9200ac954d461758937e755220ac551Ian Romanick         return GL_RG;
4416988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG8I:
4426988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG8UI:
4436988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG16I:
4446988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG16UI:
4456988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG32I:
4466988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RG32UI:
4473ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 if (!ctx->Extensions.EXT_texture_integer)
4483ebbc176f9200ac954d461758937e755220ac551Ian Romanick	    break;
4493ebbc176f9200ac954d461758937e755220ac551Ian Romanick	 /* FALLTHROUGH */
4503ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_RG:
4513ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_RG8:
4523ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_RG16:
4533ebbc176f9200ac954d461758937e755220ac551Ian Romanick      case GL_COMPRESSED_RG:
4546988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_RG;
4556988f65e43297ae63bbce30bf882f870b370096cBrian Paul      default:
4566988f65e43297ae63bbce30bf882f870b370096cBrian Paul         ; /* fallthrough */
4576988f65e43297ae63bbce30bf882f870b370096cBrian Paul      }
4586988f65e43297ae63bbce30bf882f870b370096cBrian Paul   }
4596988f65e43297ae63bbce30bf882f870b370096cBrian Paul
4606988f65e43297ae63bbce30bf882f870b370096cBrian Paul   if (ctx->Extensions.EXT_texture_shared_exponent) {
4616988f65e43297ae63bbce30bf882f870b370096cBrian Paul      switch (internalFormat) {
4626988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_RGB9_E5_EXT:
4636988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_RGB;
4646988f65e43297ae63bbce30bf882f870b370096cBrian Paul      default:
4656988f65e43297ae63bbce30bf882f870b370096cBrian Paul         ; /* fallthrough */
4666988f65e43297ae63bbce30bf882f870b370096cBrian Paul      }
4676988f65e43297ae63bbce30bf882f870b370096cBrian Paul   }
4686988f65e43297ae63bbce30bf882f870b370096cBrian Paul
4696988f65e43297ae63bbce30bf882f870b370096cBrian Paul   if (ctx->Extensions.EXT_packed_float) {
4706988f65e43297ae63bbce30bf882f870b370096cBrian Paul      switch (internalFormat) {
4716988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_R11F_G11F_B10F_EXT:
4726988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_RGB;
4736988f65e43297ae63bbce30bf882f870b370096cBrian Paul      default:
4746988f65e43297ae63bbce30bf882f870b370096cBrian Paul         ; /* fallthrough */
4756988f65e43297ae63bbce30bf882f870b370096cBrian Paul      }
4766988f65e43297ae63bbce30bf882f870b370096cBrian Paul   }
4776988f65e43297ae63bbce30bf882f870b370096cBrian Paul
4786988f65e43297ae63bbce30bf882f870b370096cBrian Paul   if (ctx->Extensions.ARB_depth_buffer_float) {
4796988f65e43297ae63bbce30bf882f870b370096cBrian Paul      switch (internalFormat) {
4806988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_DEPTH_COMPONENT32F:
4816988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_DEPTH_COMPONENT;
4826988f65e43297ae63bbce30bf882f870b370096cBrian Paul      case GL_DEPTH32F_STENCIL8:
4836988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_DEPTH_STENCIL;
4846988f65e43297ae63bbce30bf882f870b370096cBrian Paul      default:
4856988f65e43297ae63bbce30bf882f870b370096cBrian Paul         ; /* fallthrough */
4866988f65e43297ae63bbce30bf882f870b370096cBrian Paul      }
4876988f65e43297ae63bbce30bf882f870b370096cBrian Paul   }
4886988f65e43297ae63bbce30bf882f870b370096cBrian Paul
489e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick   if (ctx->Extensions.ARB_texture_compression_rgtc) {
4906988f65e43297ae63bbce30bf882f870b370096cBrian Paul      switch (internalFormat) {
491e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick      case GL_COMPRESSED_RED_RGTC1:
492e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick      case GL_COMPRESSED_SIGNED_RED_RGTC1:
4936988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_RED;
494e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick      case GL_COMPRESSED_RG_RGTC2:
495e2a054b70cb5dace40fc1426cbf936366dc72fb9Ian Romanick      case GL_COMPRESSED_SIGNED_RG_RGTC2:
4966988f65e43297ae63bbce30bf882f870b370096cBrian Paul         return GL_RG;
4976988f65e43297ae63bbce30bf882f870b370096cBrian Paul      default:
4986988f65e43297ae63bbce30bf882f870b370096cBrian Paul         ; /* fallthrough */
4996988f65e43297ae63bbce30bf882f870b370096cBrian Paul      }
500abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul   }
501abd5627a6a034885b0b01b995c73870da1361bb0Brian Paul
502f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   return -1; /* error */
503afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
504afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
507e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For cube map faces, return a face index in [0,5].
508e93243f8b7d43695654a36334c8cc5cea140d23cBrian * For other targets return 0;
509e93243f8b7d43695654a36334c8cc5cea140d23cBrian */
510e93243f8b7d43695654a36334c8cc5cea140d23cBrianGLuint
511e93243f8b7d43695654a36334c8cc5cea140d23cBrian_mesa_tex_target_to_face(GLenum target)
512519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{
513519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul   if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
514519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul       target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)
515519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul      return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
516519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul   else
517519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul      return 0;
518519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul}
519519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
520519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
521519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
5226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
5238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * Store a gl_texture_image pointer in a gl_texture_object structure
5248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * according to the target and level parameters.
5256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
5266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param tObj texture object.
5276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target.
5286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level.
5296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texImage texture image.
5306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
5318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * This was basically prompted by the introduction of cube maps.
532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
5333893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid
5343893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul_mesa_set_tex_image(struct gl_texture_object *tObj,
5353893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul                    GLenum target, GLint level,
5363893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul                    struct gl_texture_image *texImage)
537fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{
5389c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul   const GLuint face = _mesa_tex_target_to_face(target);
5399c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul
540fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul   ASSERT(tObj);
541fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul   ASSERT(texImage);
5429c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul   ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0);
5439c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul
5449c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul   tObj->Image[face][level] = texImage;
5459c9a9abd7b953ec9b6cfc52c2f6981c5d38b1691Brian Paul
546a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul   /* Set the 'back' pointer */
547a156b49800c1419785d0709b78ef0d35e6dab5dfBrian Paul   texImage->TexObject = tObj;
548fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul}
549fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul
550fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul
551a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/**
5526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Allocate a texture image structure.
5536dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
554a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Called via ctx->Driver.NewTextureImage() unless overriden by a device
555a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * driver.
5566dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
5576dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return a pointer to gl_texture_image struct with all fields initialized to
5586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * zero.
55977ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul */
56077ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulstruct gl_texture_image *
561f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_new_texture_image( struct gl_context *ctx )
56277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{
563a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   (void) ctx;
56477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul   return CALLOC_STRUCT(gl_texture_image);
56577ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul}
56677ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul
56777ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul
568a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/**
5693e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free texture image data.
5704cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul * This function is a fallback called via ctx->Driver.FreeTexImageData().
5713e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell *
5721eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image.
5733e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell *
5743e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image data if it's not marked as client data.
5753e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell */
5763e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwellvoid
577f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_free_texture_image_data(struct gl_context *ctx,
5784cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul                              struct gl_texture_image *texImage)
5793e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell{
580c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul   (void) ctx;
581c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul
5823e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell   if (texImage->Data && !texImage->IsClientData) {
5833e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell      /* free the old texture data */
5844cf6718725c7cf3bfb728118a8b14f8cf206c701Brian Paul      _mesa_free_texmemory(texImage->Data);
5853e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell   }
5863e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell
5873e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell   texImage->Data = NULL;
5883e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell}
5893e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell
5903e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell
5913e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell/**
5926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Free texture image.
5936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
5941eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texImage texture image.
5956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
5963e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell * Free the texture image structure and the associated image data.
597a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */
59877ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paulvoid
5993c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_delete_texture_image(struct gl_context *ctx,
6003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul                           struct gl_texture_image *texImage)
60177ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul{
6025ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   /* Free texImage->Data and/or any other driver-specific texture
6035ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell    * image storage.
6045ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell    */
6055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   ASSERT(ctx->Driver.FreeTexImageData);
6065ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   ctx->Driver.FreeTexImageData( ctx, texImage );
6075ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
6083e62d3a8d88b48d4ed19e00ea2bbc3d0a2b6acf7Keith Whitwell   ASSERT(texImage->Data == NULL);
609b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   if (texImage->ImageOffsets)
61032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg      free(texImage->ImageOffsets);
61132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg   free(texImage);
61277ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul}
61377ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul
61477ce6da028589efc2f3f16cece287f56fd98ce8eBrian Paul
6156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
6166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test if a target is a proxy target.
6176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
6186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target.
6196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
6206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
621aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul */
62277ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian PaulGLboolean
62377ee31930a1b0cc7766939415f4f04ed6a1fa4acBrian Paul_mesa_is_proxy_texture(GLenum target)
624aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul{
6252465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul   /* NUM_TEXTURE_TARGETS should match number of terms below */
6262465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul   assert(NUM_TEXTURE_TARGETS == 7);
6272465c4fa9cabe8c40e526b9e081de3b70c851455Brian Paul
6288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   return (target == GL_PROXY_TEXTURE_1D ||
6298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul           target == GL_PROXY_TEXTURE_2D ||
6308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul           target == GL_PROXY_TEXTURE_3D ||
63127f4484fb73ac7bf4f790ca2d3efd50b6bea25c3Brian Paul           target == GL_PROXY_TEXTURE_CUBE_MAP_ARB ||
632bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick           target == GL_PROXY_TEXTURE_RECTANGLE_NV ||
633bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick           target == GL_PROXY_TEXTURE_1D_ARRAY_EXT ||
634bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick           target == GL_PROXY_TEXTURE_2D_ARRAY_EXT);
635aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul}
636aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul
637aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul
6386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
63935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul * Return the proxy target which corresponds to the given texture target
64035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul */
64135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulstatic GLenum
64235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paulget_proxy_target(GLenum target)
64335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul{
64435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   switch (target) {
64535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_1D:
64635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_1D:
64735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_1D;
64835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_2D:
64935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_2D:
65035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_2D;
65135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_3D:
65235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_3D:
65335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_3D;
65435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
65535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
65635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
65735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
65835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
65935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
66035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_CUBE_MAP_ARB:
66135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
66235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_CUBE_MAP_ARB;
66335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_RECTANGLE_NV:
66435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_RECTANGLE_NV:
66535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_RECTANGLE_NV;
66635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_1D_ARRAY_EXT:
66735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
66835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_1D_ARRAY_EXT;
66935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_TEXTURE_2D_ARRAY_EXT:
67035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
67135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return GL_PROXY_TEXTURE_2D_ARRAY_EXT;
67235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   default:
67335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      _mesa_problem(NULL, "unexpected target in get_proxy_target()");
67435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      return 0;
67535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   }
67635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul}
67735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul
67835f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul
67935f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul/**
6803c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * Get the texture object that corresponds to the target of the given
6813c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * texture unit.
6826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
6836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
6846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param texUnit texture unit.
6856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target.
6866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
6876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return pointer to the texture object on success, or NULL on failure.
6886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
6896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_texture_unit.
69035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul */
69135d5301a54153930ee6fd60dff1010ce9f901397Brian Paulstruct gl_texture_object *
6923c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_object(struct gl_context *ctx,
6933c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul                        const struct gl_texture_unit *texUnit,
69435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul                        GLenum target)
69535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul{
69635d5301a54153930ee6fd60dff1010ce9f901397Brian Paul   switch (target) {
69735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_1D:
6989818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul         return texUnit->CurrentTex[TEXTURE_1D_INDEX];
69935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_PROXY_TEXTURE_1D:
700fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian         return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
70135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_2D:
7029818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul         return texUnit->CurrentTex[TEXTURE_2D_INDEX];
70335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_PROXY_TEXTURE_2D:
704fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian         return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
70535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_3D:
7069818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul         return texUnit->CurrentTex[TEXTURE_3D_INDEX];
70735d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_PROXY_TEXTURE_3D:
708fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian         return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
70935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
71035d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
71135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
71235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
71335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
71435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
7155ff4075a6961b26042dc2d7f4adcf333439823f4Brian Paul      case GL_TEXTURE_CUBE_MAP_ARB:
716a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell         return ctx->Extensions.ARB_texture_cube_map
7179818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul                ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL;
71835d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
719a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell         return ctx->Extensions.ARB_texture_cube_map
720fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian                ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
7218afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      case GL_TEXTURE_RECTANGLE_NV:
7228afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul         return ctx->Extensions.NV_texture_rectangle
7239818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul                ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL;
7248afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      case GL_PROXY_TEXTURE_RECTANGLE_NV:
7258afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul         return ctx->Extensions.NV_texture_rectangle
726fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian                ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
727bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      case GL_TEXTURE_1D_ARRAY_EXT:
728bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return ctx->Extensions.MESA_texture_array
7299818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul                ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
730bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
731bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return ctx->Extensions.MESA_texture_array
732fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian                ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
733bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      case GL_TEXTURE_2D_ARRAY_EXT:
734bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return ctx->Extensions.MESA_texture_array
7359818734e0148510967ca9ee0d1aa8b196b509f02Brian Paul                ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
736bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
737bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return ctx->Extensions.MESA_texture_array
738fe469007037d9d5cdbe1677d8ff7368b276e9e7cBrian                ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
73935d5301a54153930ee6fd60dff1010ce9f901397Brian Paul      default:
74008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul         _mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
74135d5301a54153930ee6fd60dff1010ce9f901397Brian Paul         return NULL;
74235d5301a54153930ee6fd60dff1010ce9f901397Brian Paul   }
74335d5301a54153930ee6fd60dff1010ce9f901397Brian Paul}
74435d5301a54153930ee6fd60dff1010ce9f901397Brian Paul
74535d5301a54153930ee6fd60dff1010ce9f901397Brian Paul
7466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
747b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul * Return pointer to texture object for given target on current texture unit.
748b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul */
749b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paulstruct gl_texture_object *
750f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target)
751b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul{
752b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
753b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   return _mesa_select_tex_object(ctx, texUnit, target);
754b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul}
755b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul
756b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul
757b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul/**
758c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * Get a texture image pointer from a texture object, given a texture
759c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * target and mipmap level.  The target and level parameters should
760c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * have already been error-checked.
7616dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
7626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
7631eee1bac1f6d911e6124daafc9b9291666d91cefVinson Lee * \param texObj texture unit.
7646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target.
7656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level.
7666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
767c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul * \return pointer to the texture image structure, or NULL on failure.
768fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul */
769fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paulstruct gl_texture_image *
7703c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_select_tex_image(struct gl_context *ctx,
7713c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul                       const struct gl_texture_object *texObj,
7725ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell		       GLenum target, GLint level)
773fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul{
774c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul   const GLuint face = _mesa_tex_target_to_face(target);
7755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
776c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul   ASSERT(texObj);
777c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul   ASSERT(level >= 0);
778c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul   ASSERT(level < MAX_TEXTURE_LEVELS);
779bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick
780c156eeb682d673e571c1798ff21e183ad4114feaBrian Paul   return texObj->Image[face][level];
781fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul}
782fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul
783fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul
784a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/**
785a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
786a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * it and install it.  Only return NULL if passed a bad parameter or run
787a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * out of memory.
788a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */
789a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image *
790f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
791a3f137094cd965d27e1b088499dd609b81a91906Brian Paul                    GLenum target, GLint level)
792a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{
793a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   struct gl_texture_image *texImage;
7945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
7955ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   if (!texObj)
7965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      return NULL;
7975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
7985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   texImage = _mesa_select_tex_image(ctx, texObj, target, level);
799a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   if (!texImage) {
800a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      texImage = ctx->Driver.NewTextureImage(ctx);
801a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (!texImage) {
802a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");
803a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
804a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      }
8055ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
806a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      _mesa_set_tex_image(texObj, target, level, texImage);
807a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   }
8085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
809a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   return texImage;
810a3f137094cd965d27e1b088499dd609b81a91906Brian Paul}
811a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
812a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
813a3f137094cd965d27e1b088499dd609b81a91906Brian Paul/**
814a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Return pointer to the specified proxy texture image.
815a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * Note that proxy textures are per-context, not per-texture unit.
816a3f137094cd965d27e1b088499dd609b81a91906Brian Paul * \return pointer to texture image or NULL if invalid target, invalid
817a3f137094cd965d27e1b088499dd609b81a91906Brian Paul *         level, or out of memory.
818a3f137094cd965d27e1b088499dd609b81a91906Brian Paul */
819a3f137094cd965d27e1b088499dd609b81a91906Brian Paulstruct gl_texture_image *
820f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level)
821a3f137094cd965d27e1b088499dd609b81a91906Brian Paul{
822a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   struct gl_texture_image *texImage;
82380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul   GLuint texIndex;
824a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
825a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   if (level < 0 )
826a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      return NULL;
827a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
828a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   switch (target) {
829a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   case GL_PROXY_TEXTURE_1D:
830a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (level >= ctx->Const.MaxTextureLevels)
831a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
83280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_1D_INDEX;
83380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
834a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   case GL_PROXY_TEXTURE_2D:
835a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (level >= ctx->Const.MaxTextureLevels)
836a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
83780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_2D_INDEX;
83880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
839a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   case GL_PROXY_TEXTURE_3D:
840a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (level >= ctx->Const.Max3DTextureLevels)
841a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
84280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_3D_INDEX;
84380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
844a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   case GL_PROXY_TEXTURE_CUBE_MAP:
845a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (level >= ctx->Const.MaxCubeTextureLevels)
846a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
84780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_CUBE_INDEX;
84880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
849a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   case GL_PROXY_TEXTURE_RECTANGLE_NV:
850a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      if (level > 0)
851a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         return NULL;
85280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_RECT_INDEX;
85380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
854bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
855bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      if (level >= ctx->Const.MaxTextureLevels)
856bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return NULL;
85780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_1D_ARRAY_INDEX;
85880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
859bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
860bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      if (level >= ctx->Const.MaxTextureLevels)
861bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return NULL;
86280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texIndex = TEXTURE_2D_ARRAY_INDEX;
86380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      break;
864a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   default:
865a3f137094cd965d27e1b088499dd609b81a91906Brian Paul      return NULL;
866a3f137094cd965d27e1b088499dd609b81a91906Brian Paul   }
86780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul
86880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul   texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
86980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul   if (!texImage) {
87080684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texImage = ctx->Driver.NewTextureImage(ctx);
87180684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      if (!texImage) {
87280684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul         _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
87380684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul         return NULL;
87480684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      }
87580684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage;
87680684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      /* Set the 'back' pointer */
87780684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul      texImage->TexObject = ctx->Texture.ProxyTex[texIndex];
87880684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul   }
87980684649a6d01f0e0517b14f61cbcad6fa101929Brian Paul   return texImage;
880a3f137094cd965d27e1b088499dd609b81a91906Brian Paul}
881a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
882a3f137094cd965d27e1b088499dd609b81a91906Brian Paul
8836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
8846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Get the maximum number of allowed mipmap levels.
8856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
8866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
8876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target.
8886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
8896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return the maximum number of allowed mipmap levels for the given
8906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * texture target, or zero if passed a bad target.
8916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
8926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa gl_constants.
893ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul */
894ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian PaulGLint
895f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_max_texture_levels(struct gl_context *ctx, GLenum target)
896ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul{
897ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   switch (target) {
898ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_1D:
899ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_PROXY_TEXTURE_1D:
900ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_2D:
901ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_PROXY_TEXTURE_2D:
902ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul      return ctx->Const.MaxTextureLevels;
903ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_3D:
904ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_PROXY_TEXTURE_3D:
905ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul      return ctx->Const.Max3DTextureLevels;
906ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
907ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
908ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
909ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
910ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
911ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
912add9f2168a5d6b15eb9955ee761246c4f4cf8458Brian Paul   case GL_TEXTURE_CUBE_MAP_ARB:
913ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
914fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul      return ctx->Extensions.ARB_texture_cube_map
915fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul         ? ctx->Const.MaxCubeTextureLevels : 0;
916ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_TEXTURE_RECTANGLE_NV:
917ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   case GL_PROXY_TEXTURE_RECTANGLE_NV:
918fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul      return ctx->Extensions.NV_texture_rectangle ? 1 : 0;
919fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul   case GL_TEXTURE_1D_ARRAY_EXT:
920fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
921fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul   case GL_TEXTURE_2D_ARRAY_EXT:
922fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
923fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul      return ctx->Extensions.MESA_texture_array
924fe988d786c4076bfbf410b84085d8c1115baa489Brian Paul         ? ctx->Const.MaxTextureLevels : 0;
925ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   default:
926ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul      return 0; /* bad target */
927ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul   }
928ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul}
929ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul
930ef31f60b12abc2109568fb8d9a2aaa70ec5c71ccBrian Paul
93183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul/**
9325e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul * Return number of dimensions per mipmap level for the given texture target.
93383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul */
93483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulstatic GLint
93583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulget_texture_dimensions(GLenum target)
93683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul{
93783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   switch (target) {
93883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_1D:
93983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_PROXY_TEXTURE_1D:
94083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul      return 1;
94183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_2D:
94283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_RECTANGLE:
94383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP:
94483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_PROXY_TEXTURE_2D:
94583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_PROXY_TEXTURE_RECTANGLE:
94683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_PROXY_TEXTURE_CUBE_MAP:
94783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
94883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
94983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
95083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
95183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
95283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
9535e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul   case GL_TEXTURE_1D_ARRAY:
9545e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul   case GL_PROXY_TEXTURE_1D_ARRAY:
95583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul      return 2;
95683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_TEXTURE_3D:
95783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   case GL_PROXY_TEXTURE_3D:
9585e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul   case GL_TEXTURE_2D_ARRAY:
9595e3733fadf08178fca7c9f20a0f4783f940383aaBrian Paul   case GL_PROXY_TEXTURE_2D_ARRAY:
96083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul      return 3;
96183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   default:
96283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul      _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()",
96383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                    target);
96483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul      return 2;
96583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   }
96683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul}
96783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
96883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
96983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
970fc4b44399a07a7a7559f20ceab8a791209b4d875Brian Paul
97162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#if 000 /* not used anymore */
972f93b3dd69e744cf1dd6b102a11cdb07c2df4a967Brian Paul/*
973afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * glTexImage[123]D can accept a NULL image pointer.  In this case we
974afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * create a texture image with unspecified image contents per the OpenGL
9758e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul * spec.
976afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
9778e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulstatic GLubyte *
9788e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulmake_null_texture(GLint width, GLint height, GLint depth, GLenum format)
979afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
9808e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   const GLint components = _mesa_components_in_format(format);
9818e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   const GLint numPixels = width * height * depth;
9828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte));
983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
984a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#ifdef DEBUG
985afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /*
986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * Let's see if anyone finds this.  If glTexImage2D() is called with
987afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * a NULL image pointer then load the texture image with something
988afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * interesting instead of leaving it indeterminate.
989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    */
9908e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   if (data) {
99165d54604c387dca986c876e811362d8e8517dcacBrian Paul      static const char message[8][32] = {
992afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X   X  XXXXX   XXX     X    ",
993afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   XX XX  X      X   X   X X   ",
994afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X X X  X      X      X   X  ",
995afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X   X  XXXX    XXX   XXXXX  ",
996afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X   X  X          X  X   X  ",
997afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X   X  X      X   X  X   X  ",
998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "   X   X  XXXXX   XXX   X   X  ",
999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         "                               "
1000afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      };
1001afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
10028e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      GLubyte *imgPtr = data;
10038e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      GLint h, i, j, k;
10048e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      for (h = 0; h < depth; h++) {
10058e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         for (i = 0; i < height; i++) {
10068e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            GLint srcRow = 7 - (i % 8);
10078e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul            for (j = 0; j < width; j++) {
10088e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               GLint srcCol = j % 32;
10098e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
10108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               for (k = 0; k < components; k++) {
10118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul                  *imgPtr++ = texel;
10128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul               }
1013afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1017a1503b00f863a48a517939a42d512f9cfe77f79cBrian Paul#endif
10188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
10198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul   return data;
1020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
102162c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul#endif
1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1025738318bb75dea8dac4465f53850987f6062a732dBrian Paul/**
1026f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * Reset the fields of a gl_texture_image struct to zero.
10276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
10286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure.
10296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
10309c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * This is called when a proxy texture test fails, we set all the
10319c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul * image members (except DriverData) to zero.
1032f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * It's also used in glTexImage[123]D as a safeguard to be sure all
1033f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * required fields get initialized properly by the Driver.TexImage[123]D
1034f378ab825c0c74aab263e7dec30194eead22c288Brian Paul * functions.
10359c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul */
10369c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paulstatic void
1037f378ab825c0c74aab263e7dec30194eead22c288Brian Paulclear_teximage_fields(struct gl_texture_image *img)
10389c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul{
10399c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   ASSERT(img);
1040a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   img->_BaseFormat = 0;
1041a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   img->InternalFormat = 0;
10429c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Border = 0;
10439c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Width = 0;
10449c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Height = 0;
10459c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Depth = 0;
1046681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul   img->RowStride = 0;
1047b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   if (img->ImageOffsets) {
104832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg      free(img->ImageOffsets);
1049b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul      img->ImageOffsets = NULL;
1050b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   }
10519c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Width2 = 0;
10529c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Height2 = 0;
10539c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Depth2 = 0;
10549c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->WidthLog2 = 0;
10559c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->HeightLog2 = 0;
10569c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->DepthLog2 = 0;
10579c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul   img->Data = NULL;
10581f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul   img->TexFormat = MESA_FORMAT_NONE;
10594f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul   img->FetchTexelc = NULL;
10604f295cee73bae1f687efe2dc062522b40d90b1e4Brian Paul   img->FetchTexelf = NULL;
10619c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul}
10629c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul
10639c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul
10646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
10656628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul * Initialize basic fields of the gl_texture_image struct.
10666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
10676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
1068b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
10696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param img texture image structure to be initialized.
10706dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width.
10716dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height.
10726dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth.
10736dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border.
10746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format.
107583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul * \param format  the actual hardware format (one of MESA_FORMAT_*)
10766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
10776dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Fills in the fields of \p img with the given information.
1078887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul * Note: width, height and depth include the border.
10796628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul */
10803893e638e6521b9c070e01c0b31d22754ff97a88Brian Paulvoid
1081f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
10823893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul                           struct gl_texture_image *img,
10833893e638e6521b9c070e01c0b31d22754ff97a88Brian Paul                           GLsizei width, GLsizei height, GLsizei depth,
108483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                           GLint border, GLenum internalFormat,
108583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                           gl_format format)
10866628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul{
108783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   GLint i, dims;
1088b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul
10896628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   ASSERT(img);
10908bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul   ASSERT(width >= 0);
10918bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul   ASSERT(height >= 0);
10928bc00c2047f69d8cd37d4fd70256850445b0fa1dBrian Paul   ASSERT(depth >= 0);
1093b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul
1094a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
1095a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   ASSERT(img->_BaseFormat > 0);
1096a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   img->InternalFormat = internalFormat;
10976628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   img->Border = border;
10986628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   img->Width = width;
10996628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   img->Height = height;
11006628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   img->Depth = depth;
1101c813b545ab4726fc5030f123ec6255224d64ad82Brian
11024d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul   img->Width2 = width - 2 * border;   /* == 1 << img->WidthLog2; */
11034d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul   img->WidthLog2 = logbase2(img->Width2);
1104c813b545ab4726fc5030f123ec6255224d64ad82Brian
1105c813b545ab4726fc5030f123ec6255224d64ad82Brian   if (height == 1) { /* 1-D texture */
1106c813b545ab4726fc5030f123ec6255224d64ad82Brian      img->Height2 = 1;
11076628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul      img->HeightLog2 = 0;
1108c813b545ab4726fc5030f123ec6255224d64ad82Brian   }
1109c813b545ab4726fc5030f123ec6255224d64ad82Brian   else {
1110c813b545ab4726fc5030f123ec6255224d64ad82Brian      img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */
11114d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul      img->HeightLog2 = logbase2(img->Height2);
1112c813b545ab4726fc5030f123ec6255224d64ad82Brian   }
1113c813b545ab4726fc5030f123ec6255224d64ad82Brian
1114c813b545ab4726fc5030f123ec6255224d64ad82Brian   if (depth == 1) {  /* 2-D texture */
1115c813b545ab4726fc5030f123ec6255224d64ad82Brian      img->Depth2 = 1;
11166628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul      img->DepthLog2 = 0;
1117c813b545ab4726fc5030f123ec6255224d64ad82Brian   }
1118c813b545ab4726fc5030f123ec6255224d64ad82Brian   else {
1119c813b545ab4726fc5030f123ec6255224d64ad82Brian      img->Depth2 = depth - 2 * border;   /* == 1 << img->DepthLog2; */
11204d0b7618cb3ada3b13e9e9b650ace34f5131e318Brian Paul      img->DepthLog2 = logbase2(img->Depth2);
1121c813b545ab4726fc5030f123ec6255224d64ad82Brian   }
1122c813b545ab4726fc5030f123ec6255224d64ad82Brian
11236628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul   img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
1124c813b545ab4726fc5030f123ec6255224d64ad82Brian
1125be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian   if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
1126be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian       (height == 1 || _mesa_is_pow_two(img->Height2)) &&
1127be1b8e5d6c6692010a3ec117035d9b218929e2b3Brian       (depth == 1 || _mesa_is_pow_two(img->Depth2)))
1128887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul      img->_IsPowerOfTwo = GL_TRUE;
1129887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul   else
1130887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul      img->_IsPowerOfTwo = GL_FALSE;
1131887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul
1132b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1133b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   img->RowStride = width;
1134b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   /* Allocate the ImageOffsets array and initialize to typical values.
1135b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul    * We allocate the array for 1D/2D textures too in order to avoid special-
1136b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul    * case code in the texstore routines.
1137b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul    */
1138a120778c72324bc56c63cd0f1873c6f2772228eaMichel Dänzer   if (img->ImageOffsets)
113932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg      free(img->ImageOffsets);
114032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg   img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
1141b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   for (i = 0; i < depth; i++) {
1142b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul      img->ImageOffsets[i] = i * width * height;
1143b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul   }
1144b0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08Brian Paul
11458afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul   /* Compute Width/Height/DepthScale for mipmap lod computation */
11468afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul   if (target == GL_TEXTURE_RECTANGLE_NV) {
11478afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      /* scale = 1.0 since texture coords directly map to texels */
11488afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->WidthScale = 1.0;
11498afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->HeightScale = 1.0;
11508afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->DepthScale = 1.0;
11518afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul   }
11528afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul   else {
11538afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->WidthScale = (GLfloat) img->Width;
11548afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->HeightScale = (GLfloat) img->Height;
11558afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      img->DepthScale = (GLfloat) img->Depth;
11568afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul   }
11571a2bb37264b4448d33f2948fe1702c9dc936395dBrian Paul
115883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   img->TexFormat = format;
115983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
116083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   dims = get_texture_dimensions(target);
116183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
116283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   _mesa_set_fetch_functions(img, dims);
11636628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul}
11646628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul
11656628bc9cff74a6d524165e809f73eabc85ba34b5Brian Paul
1166738318bb75dea8dac4465f53850987f6062a732dBrian Paul/**
116742b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * Free and clear fields of the gl_texture_image struct.
116842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu *
116942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param ctx GL context.
117042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * \param texImage texture image structure to be cleared.
117142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu *
117242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * After the call, \p texImage will have no data associated with it.  Its
117342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu * fields are cleared so that its parent object will test incomplete.
117442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu */
117542b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wuvoid
11763c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul_mesa_clear_texture_image(struct gl_context *ctx,
11773c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul                          struct gl_texture_image *texImage)
117842b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu{
117942b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu   ctx->Driver.FreeTexImageData(ctx, texImage);
118042b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu   clear_teximage_fields(texImage);
118142b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu}
118242b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu
118342b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu
118442b6b067ac68ac1309d0570613bea4a88f745559Chia-I Wu/**
1185738318bb75dea8dac4465f53850987f6062a732dBrian Paul * This is the fallback for Driver.TestProxyTexImage().  Test the texture
1186738318bb75dea8dac4465f53850987f6062a732dBrian Paul * level, width, height and depth against the ctx->Const limits for textures.
1187738318bb75dea8dac4465f53850987f6062a732dBrian Paul *
1188738318bb75dea8dac4465f53850987f6062a732dBrian Paul * A hardware driver might override this function if, for example, the
1189738318bb75dea8dac4465f53850987f6062a732dBrian Paul * max 3D texture size is 512x512x64 (i.e. not a cube).
1190738318bb75dea8dac4465f53850987f6062a732dBrian Paul *
1191aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * Note that width, height, depth == 0 is not an error.  However, a
1192aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * texture with zero width/height/depth will be considered "incomplete"
1193aa328291c5b015e74ebfd9c5cdb39227265b3000Brian * and texturing will effectively be disabled.
1194aa328291c5b015e74ebfd9c5cdb39227265b3000Brian *
1195738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param target  one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1196738318bb75dea8dac4465f53850987f6062a732dBrian Paul *                GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1197738318bb75dea8dac4465f53850987f6062a732dBrian Paul *                GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1198738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param level  as passed to glTexImage
1199738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param internalFormat  as passed to glTexImage
1200738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param format  as passed to glTexImage
1201738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param type  as passed to glTexImage
1202738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param width  as passed to glTexImage
1203738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param height  as passed to glTexImage
1204738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param depth  as passed to glTexImage
1205738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \param border  as passed to glTexImage
1206738318bb75dea8dac4465f53850987f6062a732dBrian Paul * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1207738318bb75dea8dac4465f53850987f6062a732dBrian Paul */
1208738318bb75dea8dac4465f53850987f6062a732dBrian PaulGLboolean
1209f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
1210738318bb75dea8dac4465f53850987f6062a732dBrian Paul                          GLint internalFormat, GLenum format, GLenum type,
1211738318bb75dea8dac4465f53850987f6062a732dBrian Paul                          GLint width, GLint height, GLint depth, GLint border)
1212738318bb75dea8dac4465f53850987f6062a732dBrian Paul{
1213738318bb75dea8dac4465f53850987f6062a732dBrian Paul   GLint maxSize;
12149c27278acfb786c8f2fc591eef9ed0c25135bcf0Brian Paul
1215738318bb75dea8dac4465f53850987f6062a732dBrian Paul   (void) internalFormat;
1216738318bb75dea8dac4465f53850987f6062a732dBrian Paul   (void) format;
1217738318bb75dea8dac4465f53850987f6062a732dBrian Paul   (void) type;
1218738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1219738318bb75dea8dac4465f53850987f6062a732dBrian Paul   switch (target) {
1220738318bb75dea8dac4465f53850987f6062a732dBrian Paul   case GL_PROXY_TEXTURE_1D:
1221738318bb75dea8dac4465f53850987f6062a732dBrian Paul      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1222c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1223738318bb75dea8dac4465f53850987f6062a732dBrian Paul         return GL_FALSE;
1224c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.MaxTextureLevels)
1225c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1226c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1227c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1228c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1229738318bb75dea8dac4465f53850987f6062a732dBrian Paul      }
1230738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1231c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1232738318bb75dea8dac4465f53850987f6062a732dBrian Paul   case GL_PROXY_TEXTURE_2D:
1233738318bb75dea8dac4465f53850987f6062a732dBrian Paul      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1234c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1235c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1236c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 2 * border || height > 2 + maxSize)
1237738318bb75dea8dac4465f53850987f6062a732dBrian Paul         return GL_FALSE;
1238c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.MaxTextureLevels)
1239c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1240c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1241c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1242c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1243c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
1244c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1245738318bb75dea8dac4465f53850987f6062a732dBrian Paul      }
1246738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1247c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1248738318bb75dea8dac4465f53850987f6062a732dBrian Paul   case GL_PROXY_TEXTURE_3D:
1249738318bb75dea8dac4465f53850987f6062a732dBrian Paul      maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
1250c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1251c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1252c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 2 * border || height > 2 + maxSize)
1253738318bb75dea8dac4465f53850987f6062a732dBrian Paul         return GL_FALSE;
1254c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (depth < 2 * border || depth > 2 + maxSize)
1255c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1256c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.Max3DTextureLevels)
1257c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1258c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1259c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1260c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1261c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
1262c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1263c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border))
1264c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1265738318bb75dea8dac4465f53850987f6062a732dBrian Paul      }
1266738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1267c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1268738318bb75dea8dac4465f53850987f6062a732dBrian Paul   case GL_PROXY_TEXTURE_RECTANGLE_NV:
1269c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      maxSize = ctx->Const.MaxTextureRectSize;
1270c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 0 || width > maxSize)
1271c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1272c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 0 || height > maxSize)
1273c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1274c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level != 0)
1275738318bb75dea8dac4465f53850987f6062a732dBrian Paul         return GL_FALSE;
1276738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1277c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1278738318bb75dea8dac4465f53850987f6062a732dBrian Paul   case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1279738318bb75dea8dac4465f53850987f6062a732dBrian Paul      maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
1280c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1281c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1282c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 2 * border || height > 2 + maxSize)
1283c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1284c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.MaxCubeTextureLevels)
1285738318bb75dea8dac4465f53850987f6062a732dBrian Paul         return GL_FALSE;
1286c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1287c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1288c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1289c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
1290c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1291738318bb75dea8dac4465f53850987f6062a732dBrian Paul      }
1292738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1293c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1294bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1295bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1296c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1297bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return GL_FALSE;
1298c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
1299bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return GL_FALSE;
1300c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.MaxTextureLevels)
1301c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1302c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1303c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1304c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1305bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      }
1306bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      return GL_TRUE;
1307c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1308bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1309bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1310c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (width < 2 * border || width > 2 + maxSize)
1311bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return GL_FALSE;
1312c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (height < 2 * border || height > 2 + maxSize)
1313c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1314c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
1315bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick         return GL_FALSE;
1316c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (level >= ctx->Const.MaxTextureLevels)
1317c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         return GL_FALSE;
1318c64447f47de168e82086bc2fb483817b82e59cabBrian Paul      if (!ctx->Extensions.ARB_texture_non_power_of_two) {
1319c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
1320c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1321c64447f47de168e82086bc2fb483817b82e59cabBrian Paul         if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
1322c64447f47de168e82086bc2fb483817b82e59cabBrian Paul            return GL_FALSE;
1323bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      }
1324bb372f1c9bc08e8b0dca983cb4ba36b2f2f039fbIan Romanick      return GL_TRUE;
1325c64447f47de168e82086bc2fb483817b82e59cabBrian Paul
1326738318bb75dea8dac4465f53850987f6062a732dBrian Paul   default:
1327738318bb75dea8dac4465f53850987f6062a732dBrian Paul      _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage");
1328738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_FALSE;
1329738318bb75dea8dac4465f53850987f6062a732dBrian Paul   }
1330738318bb75dea8dac4465f53850987f6062a732dBrian Paul}
1331738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1332738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1333738318bb75dea8dac4465f53850987f6062a732dBrian Paul/**
13344b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * Check if the memory used by the texture would exceed the driver's limit.
13354b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * This lets us support a max 3D texture size of 8K (for example) but
13364b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * prevents allocating a full 8K x 8K x 8K texture.
13374b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * XXX this could be rolled into the proxy texture size test (above) but
13384b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul * we don't have the actual texture internal format at that point.
13394b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul */
13404b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paulstatic GLboolean
13414b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paullegal_texture_size(struct gl_context *ctx, gl_format format,
13424b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul                   GLint width, GLint height, GLint depth)
13434b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul{
13444b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul   uint64_t bytes = _mesa_format_image_size64(format, width, height, depth);
13454b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul   uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */
13464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul   return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes;
13474b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul}
13484b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul
13494b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul
13504b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul
13514b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul/**
13527404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * Helper function to determine whether a target and specific compression
13537404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul * format are supported.
1354064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick */
1355064cd7c78c3108012f5d15206c70470f7b500259Ian Romanickstatic GLboolean
13567404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paultarget_can_be_compressed(const struct gl_context *ctx, GLenum target,
13577404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul                         GLenum intFormat)
1358064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick{
13597404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   (void) intFormat;  /* not used yet */
13607404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul
1361646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   switch (target) {
1362646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_2D:
1363646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_PROXY_TEXTURE_2D:
13647404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      return GL_TRUE; /* true for any compressed format so far */
1365646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_PROXY_TEXTURE_CUBE_MAP:
1366646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1367646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1368646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1369646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1370646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1371646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1372646afcc34045cd482e79ded241aac23082e65f6cBrian Paul      return ctx->Extensions.ARB_texture_cube_map;
1373646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1374646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   case GL_TEXTURE_2D_ARRAY_EXT:
1375646afcc34045cd482e79ded241aac23082e65f6cBrian Paul      return ctx->Extensions.MESA_texture_array;
1376646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   default:
1377646afcc34045cd482e79ded241aac23082e65f6cBrian Paul      return GL_FALSE;
1378646afcc34045cd482e79ded241aac23082e65f6cBrian Paul   }
1379064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick}
1380064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick
1381064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick
1382064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick/**
1383d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Check if the given texture target value is legal for a
1384d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * glTexImage1/2/3D call.
1385d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */
1386d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic GLboolean
1387d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paullegal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target)
1388d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{
1389d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   switch (dims) {
1390d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   case 1:
1391d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      switch (target) {
1392d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_1D:
1393d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_1D:
1394d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_TRUE;
1395d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      default:
1396d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_FALSE;
1397d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      }
1398d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   case 2:
1399d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      switch (target) {
1400d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_2D:
1401d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_2D:
1402d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_TRUE;
1403d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_CUBE_MAP:
1404d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1405d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1406d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1407d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1408d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1409d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return ctx->Extensions.ARB_texture_cube_map;
1411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_RECTANGLE_NV:
1412d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_RECTANGLE_NV:
1413d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return ctx->Extensions.NV_texture_rectangle;
1414d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_1D_ARRAY_EXT:
1415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return ctx->Extensions.MESA_texture_array;
1417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      default:
1418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_FALSE;
1419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      }
1420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   case 3:
1421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      switch (target) {
1422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_3D:
1423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_3D:
1424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_TRUE;
1425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_TEXTURE_2D_ARRAY_EXT:
1426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return ctx->Extensions.MESA_texture_array;
1428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      default:
1429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         return GL_FALSE;
1430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      }
1431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   default:
1432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims);
1433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      return GL_FALSE;
1434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   }
1435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul}
1436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
1437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
1438d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/**
143911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Check if the given texture target value is legal for a
144011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * glCopyTexImage1/2D call.
144111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */
144211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic GLboolean
144311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paullegal_copyteximage_target(struct gl_context *ctx, GLuint dims, GLenum target)
144411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{
144511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   switch (dims) {
144611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   case 1:
144711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      return target == GL_TEXTURE_1D;
144811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   case 2:
144911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      switch (target) {
145011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_2D:
145111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         return GL_TRUE;
145211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
145311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
145411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
145511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
145611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
145711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
145811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         return ctx->Extensions.ARB_texture_cube_map;
145911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_RECTANGLE_NV:
146011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         return ctx->Extensions.NV_texture_rectangle;
146111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      case GL_TEXTURE_1D_ARRAY_EXT:
146211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         return ctx->Extensions.MESA_texture_array;
146311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      default:
146411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         return GL_FALSE;
146511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      }
146611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   default:
146711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      _mesa_problem(ctx, "invalid dims=%u in legal_copyteximage_target()", dims);
146811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      return GL_FALSE;
146911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   }
147011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul}
147111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul
147211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul
147311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/**
14746dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Test the glTexImage[123]D() parameters for errors.
14756dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
14766dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
147785288ad722aa0ad378004c523a0e1a4984e15316Brian Paul * \param dimensions texture image dimensions (must be 1, 2 or 3).
14786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user.
14796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user.
14806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user.
14816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user.
14826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user.
14836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user.
14846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user.
14856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user.
14866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border image border given by the user.
14876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
14886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
14896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
14906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in
14913c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according
14923c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification.
1493afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1494c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean
149585288ad722aa0ad378004c523a0e1a4984e15316Brian Paultexture_error_check( struct gl_context *ctx,
149685288ad722aa0ad378004c523a0e1a4984e15316Brian Paul                     GLuint dimensions, GLenum target,
1497c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                     GLint level, GLint internalFormat,
1498c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                     GLenum format, GLenum type,
1499c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                     GLint width, GLint height,
1500c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                     GLint depth, GLint border )
1501afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
150235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   const GLenum proxyTarget = get_proxy_target(target);
150335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   const GLboolean isProxy = target == proxyTarget;
1504e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick   GLboolean sizeOK = GL_TRUE;
1505714c36c1202cd49c58cf6462afd391fd059b96c2Daniel Borca   GLboolean colorFormat, indexFormat;
1506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1507738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1508738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
1509738318bb75dea8dac4465f53850987f6062a732dBrian Paul      if (!isProxy) {
1510738318bb75dea8dac4465f53850987f6062a732dBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1511738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     "glTexImage%dD(level=%d)", dimensions, level);
15128afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      }
1513738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1514738318bb75dea8dac4465f53850987f6062a732dBrian Paul   }
1515738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1516738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Check border */
1517738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (border < 0 || border > 1 ||
1518738318bb75dea8dac4465f53850987f6062a732dBrian Paul       ((target == GL_TEXTURE_RECTANGLE_NV ||
1519738318bb75dea8dac4465f53850987f6062a732dBrian Paul         target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
1520738318bb75dea8dac4465f53850987f6062a732dBrian Paul      if (!isProxy) {
1521738318bb75dea8dac4465f53850987f6062a732dBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1522738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     "glTexImage%dD(border=%d)", dimensions, border);
1523738318bb75dea8dac4465f53850987f6062a732dBrian Paul      }
1524738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1525738318bb75dea8dac4465f53850987f6062a732dBrian Paul   }
1526738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1527973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul   if (width < 0 || height < 0 || depth < 0) {
1528f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul      if (!isProxy) {
1529f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1530973da83f6237b5af4a9ee77f32fdfa5c04ecabc8Brian Paul                     "glTexImage%dD(width, height or depth < 0)", dimensions);
1531f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul      }
1532f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul      return GL_TRUE;
1533f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul   }
1534f6e76fe9b5c4c57ac6dc81143b4474ebfee879d2Brian Paul
153535f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   /* Do this simple check before calling the TestProxyTexImage() function */
153635f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
153735f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul      sizeOK = (width == height);
1538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1539d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
154035f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   /*
154135f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul    * Use the proxy texture driver hook to see if the size/level/etc are
154235f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul    * legal.
154335f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul    */
154435f620d55ced7fcb3f39465c173ba2ae435a2ba1Brian Paul   sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
1545e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick                                                    internalFormat, format,
1546e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick                                                    type, width, height,
1547e2e4b60c7d9fc3618c0f9d7496c9ce3d5eee3ab5Ian Romanick                                                    depth, border);
1548738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (!sizeOK) {
1549c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (!isProxy) {
15504e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1551738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1552738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     dimensions, level, width, height, depth);
1553c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
1554afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return GL_TRUE;
1555afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1557738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Check internalFormat */
155889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (_mesa_base_tex_format(ctx, internalFormat) < 0) {
1559c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (!isProxy) {
15604e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1561a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul                     "glTexImage%dD(internalFormat=%s)",
1562a71edc9455ef81a8dd5ec284e88061a585e63580Brian Paul                     dimensions, _mesa_lookup_enum_by_nr(internalFormat));
1563c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
1564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return GL_TRUE;
1565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1566afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1567738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Check incoming image format and type */
1568f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97Brian Paul   if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
1569326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      /* Normally, GL_INVALID_OPERATION is generated by a format/type
1570326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       * mismatch (see the 1.2 spec page 94, sec 3.6.4.).  But with the
1571326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       * GL_EXT_texture_integer extension, some combinations should generate
1572326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       * GL_INVALID_ENUM instead (grr!).
157338f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes       */
157438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes      if (!isProxy) {
1575326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         GLenum error = _mesa_is_integer_format(format)
1576326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul            ? GL_INVALID_ENUM : GL_INVALID_OPERATION;
1577326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         _mesa_error(ctx, error,
15788a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                     "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
15798a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                     dimensions, format, type);
1580c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
158138f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes      return GL_TRUE;
1582afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1584601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   /* make sure internal format and format basically agree */
158522e442544bc451f114288f07cf9cc1584ca357a1Brian Paul   colorFormat = _mesa_is_color_format(format);
1586ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul   indexFormat = _mesa_is_index_format(format);
158722e442544bc451f114288f07cf9cc1584ca357a1Brian Paul   if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
1588ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul       (_mesa_is_index_format(internalFormat) && !indexFormat) ||
1589ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul       (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) ||
1590ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul       (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) ||
1591ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul       (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) ||
1592ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul       (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) {
1593601df9c742939c1f77de489561fe3e1d02f49618Brian Paul      if (!isProxy)
1594601df9c742939c1f77de489561fe3e1d02f49618Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
15958a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                     "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
15968a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                     dimensions, internalFormat, format);
1597601df9c742939c1f77de489561fe3e1d02f49618Brian Paul      return GL_TRUE;
1598601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   }
1599601df9c742939c1f77de489561fe3e1d02f49618Brian Paul
1600601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   /* additional checks for ycbcr textures */
1601601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   if (internalFormat == GL_YCBCR_MESA) {
1602c5b995066020191982b2315fc45d05e068eee761Brian Paul      ASSERT(ctx->Extensions.MESA_ycbcr_texture);
1603601df9c742939c1f77de489561fe3e1d02f49618Brian Paul      if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
1604601df9c742939c1f77de489561fe3e1d02f49618Brian Paul          type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
1605c5b995066020191982b2315fc45d05e068eee761Brian Paul         char message[100];
1606fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee         _mesa_snprintf(message, sizeof(message),
16072236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul                        "glTexImage%dD(format/type YCBCR mismatch", dimensions);
1608c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee         _mesa_error(ctx, GL_INVALID_ENUM, "%s", message);
1609c5b995066020191982b2315fc45d05e068eee761Brian Paul         return GL_TRUE; /* error */
1610c5b995066020191982b2315fc45d05e068eee761Brian Paul      }
1611d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      if (target != GL_TEXTURE_2D &&
1612d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul          target != GL_PROXY_TEXTURE_2D &&
1613d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul          target != GL_TEXTURE_RECTANGLE_NV &&
1614d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul          target != GL_PROXY_TEXTURE_RECTANGLE_NV) {
1615d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul         if (!isProxy)
1616d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul            _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)");
1617d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul         return GL_TRUE;
1618d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      }
1619d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      if (border != 0) {
1620d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul         if (!isProxy) {
1621d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul            char message[100];
1622fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee            _mesa_snprintf(message, sizeof(message),
16232236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul                           "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1624fc1be4a99425d09103bba9e06026f31f2b0142d2Vinson Lee                           dimensions, border);
1625c5dde53f4e42612518cd927bb58f08c0e22db17aVinson Lee            _mesa_error(ctx, GL_INVALID_VALUE, "%s", message);
1626d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul         }
1627d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul         return GL_TRUE;
1628d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      }
1629c5b995066020191982b2315fc45d05e068eee761Brian Paul   }
1630c5b995066020191982b2315fc45d05e068eee761Brian Paul
1631601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   /* additional checks for depth textures */
1632601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) {
16332b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul      /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1634601df9c742939c1f77de489561fe3e1d02f49618Brian Paul      if (target != GL_TEXTURE_1D &&
1635601df9c742939c1f77de489561fe3e1d02f49618Brian Paul          target != GL_PROXY_TEXTURE_1D &&
1636601df9c742939c1f77de489561fe3e1d02f49618Brian Paul          target != GL_TEXTURE_2D &&
16372b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul          target != GL_PROXY_TEXTURE_2D &&
16382b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul          target != GL_TEXTURE_RECTANGLE_ARB &&
16392b04dd9d2cba6ec3506e78016e64cffce6e8abf7Brian Paul          target != GL_PROXY_TEXTURE_RECTANGLE_ARB) {
1640601df9c742939c1f77de489561fe3e1d02f49618Brian Paul         if (!isProxy)
1641601df9c742939c1f77de489561fe3e1d02f49618Brian Paul            _mesa_error(ctx, GL_INVALID_ENUM,
1642601df9c742939c1f77de489561fe3e1d02f49618Brian Paul                        "glTexImage(target/internalFormat)");
1643601df9c742939c1f77de489561fe3e1d02f49618Brian Paul         return GL_TRUE;
1644601df9c742939c1f77de489561fe3e1d02f49618Brian Paul      }
1645601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   }
1646601df9c742939c1f77de489561fe3e1d02f49618Brian Paul
1647601df9c742939c1f77de489561fe3e1d02f49618Brian Paul   /* additional checks for compressed textures */
1648c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul   if (_mesa_is_compressed_format(ctx, internalFormat)) {
16497404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      if (!target_can_be_compressed(ctx, target, internalFormat)) {
16507404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul         if (!isProxy)
16517404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul            _mesa_error(ctx, GL_INVALID_ENUM,
16527404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul                        "glTexImage%dD(target)", dimensions);
1653064cd7c78c3108012f5d15206c70470f7b500259Ian Romanick         return GL_TRUE;
165489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
165589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      if (border != 0) {
165689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         if (!isProxy) {
165789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul            _mesa_error(ctx, GL_INVALID_OPERATION,
16588978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                        "glTexImage%dD(border!=0)", dimensions);
165989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         }
166089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_TRUE;
166189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
166289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   }
166389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
1664326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul   /* additional checks for integer textures */
1665326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul   if (ctx->Extensions.EXT_texture_integer &&
1666326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       (_mesa_is_integer_format(format) !=
1667326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul        _mesa_is_integer_format(internalFormat))) {
1668326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      if (!isProxy) {
1669326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
1670326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul                     "glTexImage%dD(integer/non-integer format mismatch)",
1671326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul                     dimensions);
1672326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      }
1673326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      return GL_TRUE;
1674326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul   }
1675326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul
1676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* if we get here, the parameters are OK */
1677afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return GL_FALSE;
1678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
16816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
1682c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glTexSubImage[123]D() parameters for errors.
16836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
16846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
16856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3).
16866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user.
16876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user.
16886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param xoffset sub-image x offset given by the user.
16896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param yoffset sub-image y offset given by the user.
16906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param zoffset sub-image z offset given by the user.
16916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param format pixel data format given by the user.
16926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param type pixel data type given by the user.
16936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user.
16946dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user.
16956dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param depth image depth given by the user.
16966dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
16976dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
16986dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
16996dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in
17003c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according
17013c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification.
1702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1703c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean
1704f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check( struct gl_context *ctx, GLuint dimensions,
1705c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                        GLenum target, GLint level,
1706c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                        GLint xoffset, GLint yoffset, GLint zoffset,
1707c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                        GLint width, GLint height, GLint depth,
1708c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                        GLenum format, GLenum type )
1709afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1710738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Basic level check */
1711738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
17124e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level);
1713c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1714c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
171645124e043da5a67e1081526d61b99422f4ccde19Brian Paul   /* Check for negative sizes */
1717c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (width < 0) {
17184e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
17194e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                  "glTexSubImage%dD(width=%d)", dimensions, width);
1720c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1721c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1722c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (height < 0 && dimensions > 1) {
17234e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
17244e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                  "glTexSubImage%dD(height=%d)", dimensions, height);
1725c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1726c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1727c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (depth < 0 && dimensions > 2) {
1728738318bb75dea8dac4465f53850987f6062a732dBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
1729738318bb75dea8dac4465f53850987f6062a732dBrian Paul                  "glTexSubImage%dD(depth=%d)", dimensions, depth);
1730c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1731c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1732afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
17335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
1734326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      /* As with the glTexImage2D check above, the error code here
1735326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       * depends on texture integer.
1736326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul       */
1737326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      GLenum error = _mesa_is_integer_format(format)
1738326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         ? GL_INVALID_OPERATION : GL_INVALID_ENUM;
1739326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      _mesa_error(ctx, error,
17408a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                  "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
17418a8919a7ddd2348c4a4cbcbab2358c49e47e2ea5Brian Paul                  dimensions, format, type);
17425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      return GL_TRUE;
17435ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   }
17445ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
17455ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   return GL_FALSE;
17465ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell}
1747f2718b0966f54049056e16e7cca08718341557b2Brian Paul
1748d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul
1749d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul/**
1750d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * Do second part of glTexSubImage which depends on the destination texture.
1751d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul * \return GL_TRUE if error recorded, GL_FALSE otherwise
1752d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul */
17535ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean
1754f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsubtexture_error_check2( struct gl_context *ctx, GLuint dimensions,
17555ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			 GLenum target, GLint level,
17565ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			 GLint xoffset, GLint yoffset, GLint zoffset,
17575ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			 GLint width, GLint height, GLint depth,
17585ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			 GLenum format, GLenum type,
17595ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			 const struct gl_texture_image *destTex )
17605ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{
1761c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (!destTex) {
1762738318bb75dea8dac4465f53850987f6062a732dBrian Paul      /* undefined image level */
1763738318bb75dea8dac4465f53850987f6062a732dBrian Paul      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions);
1764c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1765c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1767c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (xoffset < -((GLint)destTex->Border)) {
1768738318bb75dea8dac4465f53850987f6062a732dBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)",
1769738318bb75dea8dac4465f53850987f6062a732dBrian Paul                  dimensions);
1770c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1772c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
1773738318bb75dea8dac4465f53850987f6062a732dBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)",
1774738318bb75dea8dac4465f53850987f6062a732dBrian Paul                  dimensions);
1775c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1776c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1777c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (dimensions > 1) {
1778c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (yoffset < -((GLint)destTex->Border)) {
1779738318bb75dea8dac4465f53850987f6062a732dBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)",
1780738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     dimensions);
1781c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
1782afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1783c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
1784738318bb75dea8dac4465f53850987f6062a732dBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)",
1785738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     dimensions);
1786c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
1787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1789c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (dimensions > 2) {
1790c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (zoffset < -((GLint)destTex->Border)) {
179108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
1792c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
1793c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
179438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes      if (zoffset + depth  > (GLint) (destTex->Depth + destTex->Border)) {
179508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
1796c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
1797c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
1798afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1800b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul   if (_mesa_is_format_compressed(destTex->TexFormat)) {
1801d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      GLuint bw, bh;
1802d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul
1803d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      /* do tests which depend on compression block size */
1804d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh);
1805d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul
1806d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      /* offset must be multiple of block size */
1807d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      if ((xoffset % bw != 0) || (yoffset % bh != 0)) {
1808e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
18098978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1810d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul                     dimensions, xoffset, yoffset);
1811e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         return GL_TRUE;
1812e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul      }
1813d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      /* size must be multiple of bw by bh or equal to whole texture size */
1814d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      if ((width % bw != 0) && (GLuint) width != destTex->Width) {
1815e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
18168978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glTexSubImage%dD(width = %d)", dimensions, width);
1817e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         return GL_TRUE;
181889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
1819d580c0c8f7cad69b808118ef2aa6161f62f160d8Brian Paul      if ((height % bh != 0) && (GLuint) height != destTex->Height) {
182089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
18218978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glTexSubImage%dD(height = %d)", dimensions, height);
182289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_TRUE;
182389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
1824e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul   }
1825e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul
1826c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   return GL_FALSE;
1827c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul}
1828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
18306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
1831c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul * Test glCopyTexImage[12]D() parameters for errors.
18326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
18336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
18346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3).
18356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user.
18366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user.
18376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param internalFormat internal format given by the user.
18386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width image width given by the user.
18396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param height image height given by the user.
18406dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param border texture border.
18416dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
18426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
18436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
18446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies each of the parameters against the constants specified in
18453c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * __struct gl_contextRec::Const and the supported extensions, and according
18463c59febf05e6af80d63e5b9a478a11b275ac429cBrian Paul * to the OpenGL specification.
1847afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1848c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean
1849f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexture_error_check( struct gl_context *ctx, GLuint dimensions,
1850c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                         GLenum target, GLint level, GLint internalFormat,
1851c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul                         GLint width, GLint height, GLint border )
1852afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
185311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   const GLenum proxyTarget = get_proxy_target(target);
185411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   const GLenum type = GL_FLOAT;
1855738318bb75dea8dac4465f53850987f6062a732dBrian Paul   GLboolean sizeOK;
18560899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   GLint format;
1857afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
185811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   /* check target */
185911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   if (!legal_copyteximage_target(ctx, dimensions, target)) {
186011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)",
186111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                  dimensions, _mesa_lookup_enum_by_nr(target));
186211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      return GL_TRUE;
186311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   }
186411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul
1865738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1866738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
18675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      _mesa_error(ctx, GL_INVALID_VALUE,
18685ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell                  "glCopyTexImage%dD(level=%d)", dimensions, level);
18695ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      return GL_TRUE;
18705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   }
18715ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
187234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   /* Check that the source buffer is complete */
187334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   if (ctx->ReadBuffer->Name) {
187434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
187534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
187634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul         _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
187734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul                     "glCopyTexImage%dD(invalid readbuffer)", dimensions);
187834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul         return GL_TRUE;
187934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      }
188034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   }
188134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul
1882738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Check border */
1883738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (border < 0 || border > 1 ||
1884738318bb75dea8dac4465f53850987f6062a732dBrian Paul       ((target == GL_TEXTURE_RECTANGLE_NV ||
1885738318bb75dea8dac4465f53850987f6062a732dBrian Paul         target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
1886738318bb75dea8dac4465f53850987f6062a732dBrian Paul      return GL_TRUE;
1887738318bb75dea8dac4465f53850987f6062a732dBrian Paul   }
1888738318bb75dea8dac4465f53850987f6062a732dBrian Paul
1889738318bb75dea8dac4465f53850987f6062a732dBrian Paul   format = _mesa_base_tex_format(ctx, internalFormat);
18900899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   if (format < 0) {
18910899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
18920899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul                  "glCopyTexImage%dD(internalFormat)", dimensions);
18930899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      return GL_TRUE;
18940899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   }
18950899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul
189634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   if (!_mesa_source_buffer_exists(ctx, format)) {
189734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      _mesa_error(ctx, GL_INVALID_OPERATION,
189834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul                  "glCopyTexImage%dD(missing readbuffer)", dimensions);
189934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      return GL_TRUE;
190034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   }
190134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul
190211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   /* Do size, level checking */
190311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB)
190411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      ? (width == height) : 1;
1905738318bb75dea8dac4465f53850987f6062a732dBrian Paul
190611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
190711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                                                    internalFormat, format,
190811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                                                    type, width, height,
190911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                                                    1, border);
1910c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
1911738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (!sizeOK) {
1912738318bb75dea8dac4465f53850987f6062a732dBrian Paul      if (dimensions == 1) {
19134e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1914738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     "glCopyTexImage1D(width=%d)", width);
1915c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
1916738318bb75dea8dac4465f53850987f6062a732dBrian Paul      else {
1917738318bb75dea8dac4465f53850987f6062a732dBrian Paul         ASSERT(dimensions == 2);
1918738318bb75dea8dac4465f53850987f6062a732dBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
1919738318bb75dea8dac4465f53850987f6062a732dBrian Paul                     "glCopyTexImage2D(width=%d, height=%d)", width, height);
1920ad817704fa2c6d8449f55565f07ab5592a574fb6Brian Paul      }
1921c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1922c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1923c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
1924c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul   if (_mesa_is_compressed_format(ctx, internalFormat)) {
19257404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      if (!target_can_be_compressed(ctx, target, internalFormat)) {
192689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_ENUM,
19272236a301c35d29a8e0775d2b62499d8843607ee1Brian Paul                     "glCopyTexImage%dD(target)", dimensions);
192889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_TRUE;
192989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
193089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      if (border != 0) {
193189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
19328978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexImage%dD(border!=0)", dimensions);
193389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_TRUE;
193489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
193589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   }
1936ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul   else if (_mesa_is_depth_format(internalFormat)) {
19370899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      /* make sure we have depth/stencil buffers */
19381a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul      if (!ctx->ReadBuffer->_DepthBuffer) {
19390899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
19408978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexImage%dD(no depth)", dimensions);
19410899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         return GL_TRUE;
19420899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      }
19430899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   }
1944ba2a55ccd61d9fa5565640faefb64fd6fb0e70abBrian Paul   else if (_mesa_is_depthstencil_format(internalFormat)) {
19450899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      /* make sure we have depth/stencil buffers */
19461a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul      if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
19470899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
19488978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexImage%dD(no depth/stencil buffer)", dimensions);
19490899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         return GL_TRUE;
19500899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      }
19510899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   }
195289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
1953c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   /* if we get here, the parameters are OK */
1954c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   return GL_FALSE;
1955c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul}
1956c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
1957c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
19586dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
195934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul * Test glCopyTexSubImage[12]D() parameters for errors.
19609dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Note that this is the first part of error checking.
19619dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * See also copytexsubimage_error_check2() below for the second part.
19626dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
19636dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
19646dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param dimensions texture image dimensions (must be 1, 2 or 3).
19656dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param target texture target given by the user.
19666dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param level image level given by the user.
19676dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
19686dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
19696dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
1970c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paulstatic GLboolean
1971f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions,
19729dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul                              GLenum target, GLint level)
1973c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{
197434bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   /* Check that the source buffer is complete */
197534bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   if (ctx->ReadBuffer->Name) {
197634bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
197734bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
197834bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul         _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
197934bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul                     "glCopyTexImage%dD(invalid readbuffer)", dimensions);
198034bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul         return GL_TRUE;
198134bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul      }
198234bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul   }
198334bd1233a9874fe12a822c4fcb926d48456e1f29Brian Paul
19841c23b860cea93534f726d2a18658444f37f43538Brian Paul   /* check target (proxies not allowed) */
19851c23b860cea93534f726d2a18658444f37f43538Brian Paul   if (!legal_teximage_target(ctx, dimensions, target) ||
19861c23b860cea93534f726d2a18658444f37f43538Brian Paul       _mesa_is_proxy_texture(target)) {
19871c23b860cea93534f726d2a18658444f37f43538Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)",
19881c23b860cea93534f726d2a18658444f37f43538Brian Paul                  dimensions, _mesa_lookup_enum_by_nr(target));
19891c23b860cea93534f726d2a18658444f37f43538Brian Paul      return GL_TRUE;
1990c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1991c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
1992738318bb75dea8dac4465f53850987f6062a732dBrian Paul   /* Check level */
1993738318bb75dea8dac4465f53850987f6062a732dBrian Paul   if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
19944e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
19954e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                  "glCopyTexSubImage%dD(level=%d)", dimensions, level);
1996c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
1997c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
1998c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
19995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   return GL_FALSE;
20005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell}
20015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
20029dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul
20039dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul/**
20049dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * Second part of error checking for glCopyTexSubImage[12]D().
20059dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param xoffset sub-image x offset given by the user.
20069dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param yoffset sub-image y offset given by the user.
20079dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param zoffset sub-image z offset given by the user.
20089dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param width image width given by the user.
20099dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul * \param height image height given by the user.
20109dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul */
20115ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwellstatic GLboolean
2012f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcopytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions,
20135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			      GLenum target, GLint level,
20145ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			      GLint xoffset, GLint yoffset, GLint zoffset,
20155ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			      GLsizei width, GLsizei height,
20165ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell			      const struct gl_texture_image *teximage )
20175ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell{
20189dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   /* check that dest tex image exists */
2019c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (!teximage) {
20204e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_OPERATION,
2021b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul                  "glCopyTexSubImage%dD(undefined texture level: %d)",
2022b9f75444e60477e7a523e7eec1bb49a8232fd4e7Brian Paul                  dimensions, level);
2023c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
2024c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
2025c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
20269dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   /* Check size */
20279dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   if (width < 0) {
20289dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
20299dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul                  "glCopyTexSubImage%dD(width=%d)", dimensions, width);
20309dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul      return GL_TRUE;
20319dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   }
20329dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   if (dimensions > 1 && height < 0) {
20339dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
20349dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul                  "glCopyTexSubImage%dD(height=%d)", dimensions, height);
20359dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul      return GL_TRUE;
20369dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   }
20379dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul
20389dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   /* check x/y offsets */
2039c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (xoffset < -((GLint)teximage->Border)) {
20404e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
20414e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                  "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
2042c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
2043c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
204438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes   if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) {
20454e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
20464e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                  "glCopyTexSubImage%dD(xoffset+width)", dimensions);
2047c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      return GL_TRUE;
2048c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
2049c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (dimensions > 1) {
2050c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (yoffset < -((GLint)teximage->Border)) {
20514e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20524e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                     "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset);
2053c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
2054c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
2055c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      /* NOTE: we're adding the border here, not subtracting! */
205638f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes      if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) {
20574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20584e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                     "glCopyTexSubImage%dD(yoffset+height)", dimensions);
2059c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
2060c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
2061c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
2062c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
20639dfd54fa83f9d2266ee637721365f8922deb17fcBrian Paul   /* check z offset */
2064c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   if (dimensions > 2) {
2065c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      if (zoffset < -((GLint)teximage->Border)) {
20664e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20674e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                     "glCopyTexSubImage%dD(zoffset)", dimensions);
2068c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
2069c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
207038f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes      if (zoffset > (GLint) (teximage->Depth + teximage->Border)) {
20714e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20724e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul                     "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
2073c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul         return GL_TRUE;
2074c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
2075c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
2076c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
2077b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul   if (_mesa_is_format_compressed(teximage->TexFormat)) {
207889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      /* offset must be multiple of 4 */
207989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      if ((xoffset & 3) || (yoffset & 3)) {
208089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20818978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions);
2082e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         return GL_TRUE;
2083e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul      }
208489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      /* size must be multiple of 4 */
2085798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz      if ((width & 3) != 0 && (GLuint) width != teximage->Width) {
208689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20878978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexSubImage%dD(width)", dimensions);
2088e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul         return GL_TRUE;
208989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
2090798d83cf67098a7df293c711e0d2c8c296fc4c8fKarl Schultz      if ((height & 3) != 0 && (GLuint) height != teximage->Height) {
209189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
20928978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexSubImage%dD(height)", dimensions);
209389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_TRUE;
209489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
2095e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul   }
2096e4276667dafc8de0c6e64af8300fc7598437de6eBrian Paul
2097a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   if (teximage->InternalFormat == GL_YCBCR_MESA) {
2098d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D");
2099d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul      return GL_TRUE;
2100d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul   }
2101d8419c730e73c3be2eadfb0bee176ab06885766aBrian Paul
2102985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane   if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) {
2103985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane      _mesa_error(ctx, GL_INVALID_OPERATION,
2104803504e69fbd85713fc6d93af21f5245852cecabBrian Paul                  "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2105803504e69fbd85713fc6d93af21f5245852cecabBrian Paul                  dimensions, teximage->_BaseFormat);
2106985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane      return GL_TRUE;
2107985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane   }
2108985a2eff82111e81f70b6dea9d9b3184dd0061d3Alan Hourihane
2109a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) {
21101a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul      if (!ctx->ReadBuffer->_DepthBuffer) {
21110899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
21128978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexSubImage%dD(no depth buffer)",
21130899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul                     dimensions);
21140899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         return GL_TRUE;
21150899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      }
21160899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   }
2117a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul   else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
21181a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul      if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
21190899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
21208978e45e50118d0e3660fdd9cd58b8790c0a6bb8Vinson Lee                     "glCopyTexSubImage%dD(no depth/stencil buffer)",
21210899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul                     dimensions);
21220899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul         return GL_TRUE;
21230899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul      }
21240899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul   }
21250899afae33a29d1f6d15ebc96dc6ea8a8371cdb6Brian Paul
2126326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul   /* If copying into an integer texture, the source buffer must also be
2127326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul    * integer-valued.
2128326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul    */
2129412b9608838b872bc294569b3ee913343a7e66f6Brian Paul   if (_mesa_is_format_integer_color(teximage->TexFormat)) {
2130326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
2131412b9608838b872bc294569b3ee913343a7e66f6Brian Paul      if (!_mesa_is_format_integer_color(rb->Format)) {
2132326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         _mesa_error(ctx, GL_INVALID_OPERATION,
2133326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul                  "glCopyTexSubImage%dD(source buffer is not integer format)",
2134326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul                  dimensions);
2135326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul         return GL_TRUE;
2136326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul      }
2137326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul   }
2138326b981d3fafbf0cc253d2b224f0c9ad307038a3Brian Paul
2139c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   /* if we get here, the parameters are OK */
2140c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   return GL_FALSE;
2141c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul}
2142c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
2143c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
21442897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/** Callback info for walking over FBO hash table */
21452897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstruct cb_info
21462897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{
2147f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx;
21482897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   struct gl_texture_object *texObj;
21492897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   GLuint level, face;
21502897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul};
21512897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul
21528e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul
2153519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul/**
21542897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Check render to texture callback.  Called from _mesa_HashWalk().
2155519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul */
2156519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paulstatic void
21572897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulcheck_rtt_cb(GLuint key, void *data, void *userData)
2158519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul{
21592897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
21602897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   const struct cb_info *info = (struct cb_info *) userData;
2161f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = info->ctx;
21622897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   const struct gl_texture_object *texObj = info->texObj;
21632897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   const GLuint level = info->level, face = info->face;
21642897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul
21652897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   /* If this is a user-created FBO */
21662897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   if (fb->Name) {
2167519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul      GLuint i;
21682897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      /* check if any of the FBO's attachments point to 'texObj' */
2169519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul      for (i = 0; i < BUFFER_COUNT; i++) {
21702897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul         struct gl_renderbuffer_attachment *att = fb->Attachment + i;
2171519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul         if (att->Type == GL_TEXTURE &&
2172519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul             att->Texture == texObj &&
2173519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul             att->TextureLevel == level &&
2174519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul             att->CubeMapFace == face) {
2175519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul            ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
2176519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul            /* Tell driver about the new renderbuffer texture */
2177ea4fe661d7f3a95d9db17e1475076f1badf8e1a6Brian Paul            ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
21782897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul            /* Mark fb status as indeterminate to force re-validation */
21792897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul            fb->_Status = 0;
2180519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul         }
2181519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul      }
2182519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul   }
2183519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul}
2184519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
2185519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
21862897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul/**
21872897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * When a texture image is specified we have to check if it's bound to
21882897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * any framebuffer objects (render to texture) in order to detect changes
21892897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * in size or format since that effects FBO completeness.
21902897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul * Any FBOs rendering into the texture must be re-validated.
21912897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul */
21922897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paulstatic void
2193f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj,
21942897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul                   GLuint face, GLuint level)
21952897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul{
21962897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   /* Only check this texture if it's been marked as RenderToTexture */
21972897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   if (texObj->_RenderToTexture) {
21982897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      struct cb_info info;
21992897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      info.ctx = ctx;
22002897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      info.texObj = texObj;
22012897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      info.level = level;
22022897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      info.face = face;
22032897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul      _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info);
22042897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul   }
22052897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul}
22062897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul
22072897cee99fb877e1f3cd9a881a61418c9c31867fBrian Paul
22082914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul/**
22092914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * If the texture object's GenerateMipmap flag is set and we've
22102914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * changed the texture base level image, regenerate the rest of the
22112914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul * mipmap levels now.
22122914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul */
22132914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paulstatic INLINE void
2214f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcheck_gen_mipmap(struct gl_context *ctx, GLenum target,
22152914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul                 struct gl_texture_object *texObj, GLint level)
22162914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul{
22172914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul   ASSERT(target != GL_TEXTURE_CUBE_MAP);
2218ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul   if (texObj->GenerateMipmap &&
2219ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul       level == texObj->BaseLevel &&
2220ecb03d75a2961b28ab3d90fdd5df768608fc9447Brian Paul       level < texObj->MaxLevel) {
22212914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul      ASSERT(ctx->Driver.GenerateMipmap);
22222914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul      ctx->Driver.GenerateMipmap(ctx, target, texObj);
22232914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul   }
22242914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul}
22252914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
22262914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
22271826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul/** Debug helper: override the user-requested internal format */
22281826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paulstatic GLenum
22291826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Pauloverride_internal_format(GLenum internalFormat, GLint width, GLint height)
22301826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul{
22311826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#if 0
22321826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   if (internalFormat == GL_RGBA16F_ARB ||
22331826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul       internalFormat == GL_RGBA32F_ARB) {
22341826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      printf("Convert rgba float tex to int %d x %d\n", width, height);
22351826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return GL_RGBA;
22361826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22371826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else if (internalFormat == GL_RGB16F_ARB ||
22381826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul            internalFormat == GL_RGB32F_ARB) {
22391826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      printf("Convert rgb float tex to int %d x %d\n", width, height);
22401826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return GL_RGB;
22411826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22421826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB ||
22431826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul            internalFormat == GL_LUMINANCE_ALPHA32F_ARB) {
22441826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      printf("Convert luminance float tex to int %d x %d\n", width, height);
22451826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return GL_LUMINANCE_ALPHA;
22461826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22471826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else if (internalFormat == GL_LUMINANCE16F_ARB ||
22481826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul            internalFormat == GL_LUMINANCE32F_ARB) {
22491826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      printf("Convert luminance float tex to int %d x %d\n", width, height);
22501826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return GL_LUMINANCE;
22511826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22521826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else if (internalFormat == GL_ALPHA16F_ARB ||
22531826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul            internalFormat == GL_ALPHA32F_ARB) {
22541826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      printf("Convert luminance float tex to int %d x %d\n", width, height);
22551826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return GL_ALPHA;
22561826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22571826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   /*
22581826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
22591826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      internalFormat = GL_RGBA;
22601826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22611826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   */
22621826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   else {
22631826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul      return internalFormat;
22641826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   }
22651826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#else
22661826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul   return internalFormat;
22671826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul#endif
22681826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul}
22691826ff3fb34e9fb19bc8d8dee2cce5280da5e069Brian Paul
2270519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
2271bab484a59b21fff84579a492d079d46e27d486ddBrian Paul/**
2272bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Choose the actual hardware format for a texture image.
2273bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Try to use the same format as the previous image level when possible.
2274bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * Otherwise, ask the driver for the best format.
2275bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * It's important to try to choose a consistant format for all levels
2276bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * for efficient texture memory layout/allocation.  In particular, this
2277bab484a59b21fff84579a492d079d46e27d486ddBrian Paul * comes up during automatic mipmap generation.
2278bab484a59b21fff84579a492d079d46e27d486ddBrian Paul */
227983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paulgl_format
2280f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_choose_texture_format(struct gl_context *ctx,
2281bab484a59b21fff84579a492d079d46e27d486ddBrian Paul                            struct gl_texture_object *texObj,
2282bab484a59b21fff84579a492d079d46e27d486ddBrian Paul                            GLenum target, GLint level,
2283bab484a59b21fff84579a492d079d46e27d486ddBrian Paul                            GLenum internalFormat, GLenum format, GLenum type)
2284bab484a59b21fff84579a492d079d46e27d486ddBrian Paul{
228583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   gl_format f;
228683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
2287bab484a59b21fff84579a492d079d46e27d486ddBrian Paul   /* see if we've already chosen a format for the previous level */
2288bab484a59b21fff84579a492d079d46e27d486ddBrian Paul   if (level > 0) {
2289bab484a59b21fff84579a492d079d46e27d486ddBrian Paul      struct gl_texture_image *prevImage =
2290bab484a59b21fff84579a492d079d46e27d486ddBrian Paul	 _mesa_select_tex_image(ctx, texObj, target, level - 1);
2291bab484a59b21fff84579a492d079d46e27d486ddBrian Paul      /* See if the prev level is defined and has an internal format which
2292bab484a59b21fff84579a492d079d46e27d486ddBrian Paul       * matches the new internal format.
2293bab484a59b21fff84579a492d079d46e27d486ddBrian Paul       */
2294bab484a59b21fff84579a492d079d46e27d486ddBrian Paul      if (prevImage &&
2295bab484a59b21fff84579a492d079d46e27d486ddBrian Paul          prevImage->Width > 0 &&
2296bab484a59b21fff84579a492d079d46e27d486ddBrian Paul          prevImage->InternalFormat == internalFormat) {
2297bab484a59b21fff84579a492d079d46e27d486ddBrian Paul         /* use the same format */
229883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul         ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE);
229983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul         return prevImage->TexFormat;
2300bab484a59b21fff84579a492d079d46e27d486ddBrian Paul      }
2301bab484a59b21fff84579a492d079d46e27d486ddBrian Paul   }
2302bab484a59b21fff84579a492d079d46e27d486ddBrian Paul
2303bab484a59b21fff84579a492d079d46e27d486ddBrian Paul   /* choose format from scratch */
230483e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
230583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   ASSERT(f != MESA_FORMAT_NONE);
230683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul   return f;
2307bab484a59b21fff84579a492d079d46e27d486ddBrian Paul}
2308bab484a59b21fff84579a492d079d46e27d486ddBrian Paul
2309bab484a59b21fff84579a492d079d46e27d486ddBrian Paul
2310d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/**
2311d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Common code to implement all the glTexImage1D/2D/3D functions.
2312c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul */
2313d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulstatic void
2314d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulteximage(struct gl_context *ctx, GLuint dims,
2315d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         GLenum target, GLint level, GLint internalFormat,
2316d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         GLsizei width, GLsizei height, GLsizei depth,
2317d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         GLint border, GLenum format, GLenum type,
2318d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         const GLvoid *pixels)
2319c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul{
2320d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   GLboolean error;
2321d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2322cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2323c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
2324d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2325d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2326d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  dims,
2327d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(target), level,
2328d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  _mesa_lookup_enum_by_nr(internalFormat),
2329d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  width, height, depth, border,
2330d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(format),
2331d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(type), pixels);
2332d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora
2333d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   internalFormat = override_internal_format(internalFormat, width, height);
233411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul
2335d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   /* target error checking */
2336d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   if (!legal_teximage_target(ctx, dims, target)) {
2337d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)",
2338d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  dims, _mesa_lookup_enum_by_nr(target));
2339d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      return;
2340d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   }
2341ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul
2342d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   /* general error checking */
2343d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   error = texture_error_check(ctx, dims, target, level, internalFormat,
2344d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                               format, type, width, height, depth, border);
23452914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
2346d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   if (_mesa_is_proxy_texture(target)) {
2347d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      /* Proxy texture: just clear or set state depending on error checking */
2348d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      struct gl_texture_image *texImage =
2349d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         _mesa_get_proxy_tex_image(ctx, target, level);
235062c734f49948df7aeef55ad23a6664cbf3e11533Brian Paul
2351d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      if (error) {
2352738318bb75dea8dac4465f53850987f6062a732dBrian Paul         /* when error, clear all proxy texture image parameters */
2353a3f137094cd965d27e1b088499dd609b81a91906Brian Paul         if (texImage)
2354a3f137094cd965d27e1b088499dd609b81a91906Brian Paul            clear_teximage_fields(texImage);
2355c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
235689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      else {
235789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         /* no error, set the tex image parameters */
2358bab484a59b21fff84579a492d079d46e27d486ddBrian Paul         struct gl_texture_object *texObj =
2359bab484a59b21fff84579a492d079d46e27d486ddBrian Paul            _mesa_get_current_tex_object(ctx, target);
2360d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         gl_format texFormat = _mesa_choose_texture_format(ctx, texObj,
2361d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                                           target, level,
236283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                           internalFormat,
236383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                           format, type);
2364d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2365d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul         if (legal_texture_size(ctx, texFormat, width, height, depth)) {
2366d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul            _mesa_init_teximage_fields(ctx, target, texImage, width, height,
2367d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                       depth, border, internalFormat,
2368d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                       texFormat);
23694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         }
23704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         else if (texImage) {
23714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            clear_teximage_fields(texImage);
23724b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         }
237389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
2374c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   }
2375c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul   else {
23768e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* non-proxy target */
2377d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      const GLuint face = _mesa_tex_target_to_face(target);
23780293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul      struct gl_texture_object *texObj;
23790293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul      struct gl_texture_image *texImage;
2380f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul
2381d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul      if (error) {
23828e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul         return;   /* error was recorded */
2383c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul      }
2384c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul
23851ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul      if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
23865ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 _mesa_update_state(ctx);
2387fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul
2388b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul      texObj = _mesa_get_current_tex_object(ctx, target);
2389d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
23905ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      _mesa_lock_texture(ctx, texObj);
23915ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      {
23925ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2393d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
23945ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 if (!texImage) {
2395d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
23965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 }
2397ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul         else {
239883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul            gl_format texFormat;
239983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
2400ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul            if (texImage->Data) {
2401ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul               ctx->Driver.FreeTexImageData( ctx, texImage );
2402ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul            }
2403ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul
2404ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul            ASSERT(texImage->Data == NULL);
240583e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
240683e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                    internalFormat, format,
240783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                    type);
240883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
2409d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul            if (legal_texture_size(ctx, texFormat, width, height, depth)) {
2410d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               _mesa_init_teximage_fields(ctx, target, texImage,
2411d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                          width, height, depth,
2412d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                          border, internalFormat, texFormat);
241311caea687e3f10ae12d33e44edf84635f73047ddBrian Paul
24144b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               /* Give the texture to the driver.  <pixels> may be null. */
2415d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               ASSERT(ctx->Driver.TexImage3D);
2416d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               switch (dims) {
2417d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               case 1:
2418d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
2419d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         width, border, format,
2420d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         type, pixels, &ctx->Unpack, texObj,
2421d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         texImage);
2422d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  break;
2423d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               case 2:
2424d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
2425d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         width, height, border, format,
2426d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         type, pixels, &ctx->Unpack, texObj,
2427d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         texImage);
2428d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  break;
2429d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               case 3:
2430d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  ctx->Driver.TexImage3D(ctx, target, level, internalFormat,
2431d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         width, height, depth, border, format,
2432d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         type, pixels, &ctx->Unpack, texObj,
2433d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                                         texImage);
2434d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  break;
2435d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               default:
2436d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  _mesa_problem(ctx, "invalid dims=%u in teximage()", dims);
2437d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               }
2438ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul
24394b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               check_gen_mipmap(ctx, target, texObj, level);
24402914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
24414b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               update_fbo_texture(ctx, texObj, face, level);
2442ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul
24434b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               /* state update */
24444b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               texObj->_Complete = GL_FALSE;
24454b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               ctx->NewState |= _NEW_TEXTURE;
24464b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            }
24474b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            else {
2448d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul               _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
24494b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            }
2450ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul         }
2451ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul      }
24525ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      _mesa_unlock_texture(ctx, texObj);
2453afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
2454d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul}
2455d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2456d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2457d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul/*
2458d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul * Called from the API.  Note that width includes the border.
2459d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul */
2460d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY
2461d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
2462d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  GLsizei width, GLint border, GLenum format,
2463d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  GLenum type, const GLvoid *pixels )
2464d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{
2465d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   GET_CURRENT_CONTEXT(ctx);
2466d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   teximage(ctx, 1, target, level, internalFormat, width, 1, 1,
2467d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul            border, format, type, pixels);
2468d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul}
2469d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2470d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul
2471d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paulvoid GLAPIENTRY
2472d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
2473d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  GLsizei width, GLsizei height, GLint border,
2474d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  GLenum format, GLenum type,
2475d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul                  const GLvoid *pixels )
2476d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul{
2477d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   GET_CURRENT_CONTEXT(ctx);
2478d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   teximage(ctx, 2, target, level, internalFormat, width, height, 1,
2479d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul            border, format, type, pixels);
2480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2481afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2482afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2483afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
2484afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Called by the API or display list executor.
2485afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Note that width and height include the border.
2486afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
2487c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2488b5fd886ee12ef52126969f712dee0bd4b2eea706Brian Paul_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
2489fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                  GLsizei width, GLsizei height, GLsizei depth,
2490fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                  GLint border, GLenum format, GLenum type,
2491fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                  const GLvoid *pixels )
2492afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2493fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
2494d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul   teximage(ctx, 3, target, level, internalFormat, width, height, depth,
2495d0b2b8da7d363f6b79fcab7bfe6e81d1d436944eBrian Paul            border, format, type, pixels);
2496afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2497afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2498afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2499c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
250043911c8ef06c44d486a17cf9a8fa8ea263b08adeBrian Paul_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
2501663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul                     GLsizei width, GLsizei height, GLsizei depth,
2502663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul                     GLint border, GLenum format, GLenum type,
2503663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul                     const GLvoid *pixels )
2504663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul{
250589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
2506663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul                    depth, border, format, type, pixels);
2507663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul}
2508663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul
2509663049a719ed76aa0a6f24f1951a411d241bc8a4Brian Paul
2510d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#if FEATURE_OES_EGL_image
2511d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsbergvoid GLAPIENTRY
2512d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
2513d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg{
2514d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   struct gl_texture_object *texObj;
2515d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   struct gl_texture_image *texImage;
251617efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee   GET_CURRENT_CONTEXT(ctx);
251717efc8c05c6931a4638ee9f6138794f2b2b29540Vinson Lee   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2518d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
25192002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu   if (!ctx->Extensions.OES_EGL_image) {
25202002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu      _mesa_error(ctx, GL_INVALID_OPERATION,
25212002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu                  "glEGLImageTargetTexture2DOES(unsupported)");
25222002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu      return;
25232002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu   }
25242002e4d06e2627241cd4af88f65b54d2101ef151Chia-I Wu
2525d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   if (target != GL_TEXTURE_2D) {
2526d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      _mesa_error(ctx, GL_INVALID_ENUM,
2527d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg		  "glEGLImageTargetTexture2D(target=%d)", target);
2528d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      return;
2529d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   }
2530d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2531d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2532d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      _mesa_update_state(ctx);
2533d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2534d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   texObj = _mesa_get_current_tex_object(ctx, target);
2535d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   _mesa_lock_texture(ctx, texObj);
2536d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2537d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
2538d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   if (!texImage) {
2539d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D");
2540d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   } else {
2541d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      if (texImage->Data)
2542d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg	 ctx->Driver.FreeTexImageData( ctx, texImage );
2543d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2544d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      ASSERT(texImage->Data == NULL);
2545d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      ctx->Driver.EGLImageTargetTexture2D(ctx, target,
2546d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg					  texObj, texImage, image);
2547d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2548d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      /* state update */
2549d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      texObj->_Complete = GL_FALSE;
2550d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg      ctx->NewState |= _NEW_TEXTURE;
2551d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   }
2552d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg   _mesa_unlock_texture(ctx, texObj);
2553d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2554d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg}
2555d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg#endif
2556d1dc5b124e133379be5bb57b68733c09c0e04f71Kristian Høgsberg
2557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
255845124e043da5a67e1081526d61b99422f4ccde19Brian Paul
255945124e043da5a67e1081526d61b99422f4ccde19Brian Paul/**
256045124e043da5a67e1081526d61b99422f4ccde19Brian Paul * Implement all the glTexSubImage1/2/3D() functions.
256145124e043da5a67e1081526d61b99422f4ccde19Brian Paul */
256245124e043da5a67e1081526d61b99422f4ccde19Brian Paulstatic void
256345124e043da5a67e1081526d61b99422f4ccde19Brian Paultexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
256445124e043da5a67e1081526d61b99422f4ccde19Brian Paul            GLint xoffset, GLint yoffset, GLint zoffset,
256545124e043da5a67e1081526d61b99422f4ccde19Brian Paul            GLsizei width, GLsizei height, GLsizei depth,
256645124e043da5a67e1081526d61b99422f4ccde19Brian Paul            GLenum format, GLenum type, const GLvoid *pixels )
2567afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
25680293878846551bfe349a4aa029a0489f9a73f1ffBrian Paul   struct gl_texture_object *texObj;
2569b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   struct gl_texture_image *texImage;
257045124e043da5a67e1081526d61b99422f4ccde19Brian Paul
257175280a2c742ee241d392618a3b29548fce1520a9Brian Paul   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
257275280a2c742ee241d392618a3b29548fce1520a9Brian Paul
2573d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
257445124e043da5a67e1081526d61b99422f4ccde19Brian Paul      _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
257545124e043da5a67e1081526d61b99422f4ccde19Brian Paul                  dims,
2576d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(target), level,
257745124e043da5a67e1081526d61b99422f4ccde19Brian Paul                  xoffset, yoffset, zoffset, width, height, depth,
257845124e043da5a67e1081526d61b99422f4ccde19Brian Paul                  _mesa_lookup_enum_by_nr(format),
2579d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(type), pixels);
2580d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora
258145124e043da5a67e1081526d61b99422f4ccde19Brian Paul   /* check target (proxies not allowed) */
258245124e043da5a67e1081526d61b99422f4ccde19Brian Paul   if (!legal_teximage_target(ctx, dims, target) ||
258345124e043da5a67e1081526d61b99422f4ccde19Brian Paul       _mesa_is_proxy_texture(target)) {
258445124e043da5a67e1081526d61b99422f4ccde19Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)",
258545124e043da5a67e1081526d61b99422f4ccde19Brian Paul                  dims, _mesa_lookup_enum_by_nr(target));
258645124e043da5a67e1081526d61b99422f4ccde19Brian Paul      return;
258745124e043da5a67e1081526d61b99422f4ccde19Brian Paul   }
258845124e043da5a67e1081526d61b99422f4ccde19Brian Paul
25891ed5fe5cbfb64c57997ec46684748f8ae516d19cBrian Paul   if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
259008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state(ctx);
25912aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul
259245124e043da5a67e1081526d61b99422f4ccde19Brian Paul   if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset,
259345124e043da5a67e1081526d61b99422f4ccde19Brian Paul                              width, height, depth, format, type)) {
2594f7b5707d66678f09bec652ecce024a0da6cc4a4bBrian Paul      return;   /* error was detected */
2595afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
2596afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2597b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   texObj = _mesa_get_current_tex_object(ctx, target);
2598afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
25995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_lock_texture(ctx, texObj);
26005ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   {
26015ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2602afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
260345124e043da5a67e1081526d61b99422f4ccde19Brian Paul      if (subtexture_error_check2(ctx, dims, target, level,
260445124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                  xoffset, yoffset, zoffset,
260545124e043da5a67e1081526d61b99422f4ccde19Brian Paul				  width, height, depth,
260645124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                  format, type, texImage)) {
2607a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul         /* error was recorded */
26085ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      }
260945124e043da5a67e1081526d61b99422f4ccde19Brian Paul      else if (width > 0 && height > 0 && height > 0) {
261045124e043da5a67e1081526d61b99422f4ccde19Brian Paul         /* If we have a border, offset=-1 is legal.  Bias by border width. */
261145124e043da5a67e1081526d61b99422f4ccde19Brian Paul         switch (dims) {
261245124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 3:
261345124e043da5a67e1081526d61b99422f4ccde19Brian Paul            zoffset += texImage->Border;
261445124e043da5a67e1081526d61b99422f4ccde19Brian Paul            /* fall-through */
261545124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 2:
261645124e043da5a67e1081526d61b99422f4ccde19Brian Paul            yoffset += texImage->Border;
261745124e043da5a67e1081526d61b99422f4ccde19Brian Paul            /* fall-through */
261845124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 1:
261945124e043da5a67e1081526d61b99422f4ccde19Brian Paul            xoffset += texImage->Border;
262045124e043da5a67e1081526d61b99422f4ccde19Brian Paul         }
2621347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul
262245124e043da5a67e1081526d61b99422f4ccde19Brian Paul         switch (dims) {
262345124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 1:
262445124e043da5a67e1081526d61b99422f4ccde19Brian Paul            ctx->Driver.TexSubImage1D(ctx, target, level,
262545124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      xoffset, width,
262645124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      format, type, pixels,
262745124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      &ctx->Unpack, texObj, texImage );
262845124e043da5a67e1081526d61b99422f4ccde19Brian Paul            break;
262945124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 2:
263045124e043da5a67e1081526d61b99422f4ccde19Brian Paul            ctx->Driver.TexSubImage2D(ctx, target, level,
263145124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      xoffset, yoffset, width, height,
263245124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      format, type, pixels,
263345124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      &ctx->Unpack, texObj, texImage );
263445124e043da5a67e1081526d61b99422f4ccde19Brian Paul            break;
263545124e043da5a67e1081526d61b99422f4ccde19Brian Paul         case 3:
263645124e043da5a67e1081526d61b99422f4ccde19Brian Paul            ctx->Driver.TexSubImage3D(ctx, target, level,
263745124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      xoffset, yoffset, zoffset,
263845124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      width, height, depth,
263945124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      format, type, pixels,
264045124e043da5a67e1081526d61b99422f4ccde19Brian Paul                                      &ctx->Unpack, texObj, texImage );
264145124e043da5a67e1081526d61b99422f4ccde19Brian Paul            break;
264245124e043da5a67e1081526d61b99422f4ccde19Brian Paul         default:
264345124e043da5a67e1081526d61b99422f4ccde19Brian Paul            _mesa_problem(ctx, "unexpected dims in subteximage()");
264445124e043da5a67e1081526d61b99422f4ccde19Brian Paul         }
26452914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
26462914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul         check_gen_mipmap(ctx, target, texObj, level);
26472914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
2648ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul         ctx->NewState |= _NEW_TEXTURE;
2649ecf6f37fc201d7c88f8214b04ca1f61071c460a1Brian Paul      }
26505ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   }
26515ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_unlock_texture(ctx, texObj);
2652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2655c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
265645124e043da5a67e1081526d61b99422f4ccde19Brian Paul_mesa_TexSubImage1D( GLenum target, GLint level,
265745124e043da5a67e1081526d61b99422f4ccde19Brian Paul                     GLint xoffset, GLsizei width,
265845124e043da5a67e1081526d61b99422f4ccde19Brian Paul                     GLenum format, GLenum type,
265945124e043da5a67e1081526d61b99422f4ccde19Brian Paul                     const GLvoid *pixels )
266045124e043da5a67e1081526d61b99422f4ccde19Brian Paul{
266145124e043da5a67e1081526d61b99422f4ccde19Brian Paul   GET_CURRENT_CONTEXT(ctx);
266245124e043da5a67e1081526d61b99422f4ccde19Brian Paul   texsubimage(ctx, 1, target, level,
266345124e043da5a67e1081526d61b99422f4ccde19Brian Paul               xoffset, 0, 0,
266445124e043da5a67e1081526d61b99422f4ccde19Brian Paul               width, 1, 1,
266545124e043da5a67e1081526d61b99422f4ccde19Brian Paul               format, type, pixels);
266645124e043da5a67e1081526d61b99422f4ccde19Brian Paul}
266745124e043da5a67e1081526d61b99422f4ccde19Brian Paul
266845124e043da5a67e1081526d61b99422f4ccde19Brian Paul
266945124e043da5a67e1081526d61b99422f4ccde19Brian Paulvoid GLAPIENTRY
2670fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage2D( GLenum target, GLint level,
2671fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLint xoffset, GLint yoffset,
2672fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLsizei width, GLsizei height,
2673fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLenum format, GLenum type,
2674fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     const GLvoid *pixels )
2675afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
26762c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   GET_CURRENT_CONTEXT(ctx);
267745124e043da5a67e1081526d61b99422f4ccde19Brian Paul   texsubimage(ctx, 2, target, level,
267845124e043da5a67e1081526d61b99422f4ccde19Brian Paul               xoffset, yoffset, 0,
267945124e043da5a67e1081526d61b99422f4ccde19Brian Paul               width, height, 1,
268045124e043da5a67e1081526d61b99422f4ccde19Brian Paul               format, type, pixels);
2681c3f0a511a725c7b3d3d7d93b1955aaaa2bb32f0dBrian Paul}
2682afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2683afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2684afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2685c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2686fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_TexSubImage3D( GLenum target, GLint level,
2687fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLint xoffset, GLint yoffset, GLint zoffset,
2688fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLsizei width, GLsizei height, GLsizei depth,
2689fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     GLenum format, GLenum type,
2690fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                     const GLvoid *pixels )
2691afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
26922c3d34c905fa6b831a066afae83b938de05eb241Gareth Hughes   GET_CURRENT_CONTEXT(ctx);
269345124e043da5a67e1081526d61b99422f4ccde19Brian Paul   texsubimage(ctx, 3, target, level,
269445124e043da5a67e1081526d61b99422f4ccde19Brian Paul               xoffset, yoffset, zoffset,
269545124e043da5a67e1081526d61b99422f4ccde19Brian Paul               width, height, depth,
269645124e043da5a67e1081526d61b99422f4ccde19Brian Paul               format, type, pixels);
2697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2700afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
270111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul/**
270211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul * Implement the glCopyTexImage1/2D() functions.
270311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul */
270411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulstatic void
270511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulcopyteximage(struct gl_context *ctx, GLuint dims,
270611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul             GLenum target, GLint level, GLenum internalFormat,
270711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul             GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
2708afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
27092aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul   struct gl_texture_object *texObj;
27102aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul   struct gl_texture_image *texImage;
2711e93243f8b7d43695654a36334c8cc5cea140d23cBrian   const GLuint face = _mesa_tex_target_to_face(target);
271211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul
2713cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2715d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
271611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul      _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
271711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                  dims,
2718d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(target), level,
2719d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(internalFormat),
272011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                  x, y, width, height, border);
2721d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora
272263f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul   if (ctx->NewState & NEW_COPY_TEX_STATE)
272308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state(ctx);
2724fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul
272511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   if (copytexture_error_check(ctx, dims, target, level, internalFormat,
272611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                               width, height, border))
2727ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul      return;
2728ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul
2729b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   texObj = _mesa_get_current_tex_object(ctx, target);
2730a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul
27315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_lock_texture(ctx, texObj);
27325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   {
27335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      texImage = _mesa_get_tex_image(ctx, texObj, target, level);
273411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul
27355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      if (!texImage) {
273611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul	 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
27375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      }
2738c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul      else {
273983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul         gl_format texFormat;
274083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
2741c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         if (texImage->Data) {
2742c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul            ctx->Driver.FreeTexImageData( ctx, texImage );
2743c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         }
27447dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul
2745c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         ASSERT(texImage->Data == NULL);
27467dac13272a959654f1010b80c1f1ec6dcae5a4faBrian Paul
274783e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul         texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
274883e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                 internalFormat, GL_NONE,
274983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                 GL_NONE);
27502aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul
275111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul         if (legal_texture_size(ctx, texFormat, width, height, 1)) {
275211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul            _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
27534b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul                                       border, internalFormat, texFormat);
275411caea687e3f10ae12d33e44edf84635f73047ddBrian Paul
275511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul            ASSERT(ctx->Driver.CopyTexImage2D);
275611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul            if (dims == 1)
275711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul               ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
275811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                                          x, y, width, border);
275911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul            else
276011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul               ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
276111f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                                          x, y, width, height, border);
27622aadbf41dfd4f63c6118d0ad2d8659d289cbe454Brian Paul
27634b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            check_gen_mipmap(ctx, target, texObj, level);
27642914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
27654b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            update_fbo_texture(ctx, texObj, face, level);
2766519b23b21f9cd6945fd17cdb26e7a6f531cdeec0Brian Paul
27674b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            /* state update */
27684b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            texObj->_Complete = GL_FALSE;
27694b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            ctx->NewState |= _NEW_TEXTURE;
27704b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         }
27714b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         else {
277211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
27734b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul         }
2774c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul      }
27755ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   }
27765ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_unlock_texture(ctx, texObj);
2777afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2778afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2781c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
278211f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage1D( GLenum target, GLint level,
278311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                      GLenum internalFormat,
278411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                      GLint x, GLint y,
278511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                      GLsizei width, GLint border )
2786afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2787fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
278811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border);
278911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul}
2790c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul
27912914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
2792c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul
279311f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paulvoid GLAPIENTRY
279411f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
279511f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                      GLint x, GLint y, GLsizei width, GLsizei height,
279611f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                      GLint border )
279711f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul{
279811f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   GET_CURRENT_CONTEXT(ctx);
279911f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul   copyteximage(ctx, 2, target, level, internalFormat,
280011f386fb504b9f07dd501a65f31185cfa0e9a679Brian Paul                x, y, width, height, border);
2801afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2802afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2803afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
28041c23b860cea93534f726d2a18658444f37f43538Brian Paul
28051c23b860cea93534f726d2a18658444f37f43538Brian Paul/**
28061c23b860cea93534f726d2a18658444f37f43538Brian Paul * Implementation for glCopyTexSubImage1/2/3D() functions.
28071c23b860cea93534f726d2a18658444f37f43538Brian Paul */
28081c23b860cea93534f726d2a18658444f37f43538Brian Paulstatic void
28091c23b860cea93534f726d2a18658444f37f43538Brian Paulcopytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
28101c23b860cea93534f726d2a18658444f37f43538Brian Paul                GLint xoffset, GLint yoffset, GLint zoffset,
28111c23b860cea93534f726d2a18658444f37f43538Brian Paul                GLint x, GLint y, GLsizei width, GLsizei height)
2812afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
28135ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   struct gl_texture_object *texObj;
2814347b3f0dafe8d0cc30e9d1e7595d12b0ac31bb4aBrian Paul   struct gl_texture_image *texImage;
281503bafd1f9fa000abdb794b2ae344a68840c83201Brian
2816cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2818d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
28191c23b860cea93534f726d2a18658444f37f43538Brian Paul      _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
28201c23b860cea93534f726d2a18658444f37f43538Brian Paul                  dims,
2821d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(target),
28221c23b860cea93534f726d2a18658444f37f43538Brian Paul                  level, xoffset, yoffset, zoffset, x, y, width, height);
2823d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora
282463f01309801c5a900d8d7f5ccd63413e33ff9bffBrian Paul   if (ctx->NewState & NEW_COPY_TEX_STATE)
282508836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_update_state(ctx);
2826fa4525e289b475b928a7b2c4055af9dd7fe46600Brian Paul
28271c23b860cea93534f726d2a18658444f37f43538Brian Paul   if (copytexsubimage_error_check1(ctx, dims, target, level))
2828ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul      return;
2829ab6e78f3a0abac7becbd8a58ed2c89f860cc6b0bBrian Paul
2830b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   texObj = _mesa_get_current_tex_object(ctx, target);
28315ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
28325ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_lock_texture(ctx, texObj);
28335ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   {
28345ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      texImage = _mesa_select_tex_image(ctx, texObj, target, level);
28355ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
28361c23b860cea93534f726d2a18658444f37f43538Brian Paul      if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset,
28371c23b860cea93534f726d2a18658444f37f43538Brian Paul				       zoffset, width, height, texImage)) {
28381c23b860cea93534f726d2a18658444f37f43538Brian Paul         /* error was recored */
283903bafd1f9fa000abdb794b2ae344a68840c83201Brian      }
2840a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul      else {
28411c23b860cea93534f726d2a18658444f37f43538Brian Paul         /* If we have a border, offset=-1 is legal.  Bias by border width. */
28421c23b860cea93534f726d2a18658444f37f43538Brian Paul         switch (dims) {
28431c23b860cea93534f726d2a18658444f37f43538Brian Paul         case 3:
28441c23b860cea93534f726d2a18658444f37f43538Brian Paul            zoffset += texImage->Border;
28451c23b860cea93534f726d2a18658444f37f43538Brian Paul            /* fall-through */
28461c23b860cea93534f726d2a18658444f37f43538Brian Paul         case 2:
28471c23b860cea93534f726d2a18658444f37f43538Brian Paul            yoffset += texImage->Border;
28481c23b860cea93534f726d2a18658444f37f43538Brian Paul            /* fall-through */
28491c23b860cea93534f726d2a18658444f37f43538Brian Paul         case 1:
28501c23b860cea93534f726d2a18658444f37f43538Brian Paul            xoffset += texImage->Border;
28511c23b860cea93534f726d2a18658444f37f43538Brian Paul         }
285203bafd1f9fa000abdb794b2ae344a68840c83201Brian
2853a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul         if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
2854a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul                                        &width, &height)) {
28551c23b860cea93534f726d2a18658444f37f43538Brian Paul            switch (dims) {
28561c23b860cea93534f726d2a18658444f37f43538Brian Paul            case 1:
28571c23b860cea93534f726d2a18658444f37f43538Brian Paul               ctx->Driver.CopyTexSubImage1D(ctx, target, level,
28581c23b860cea93534f726d2a18658444f37f43538Brian Paul                                             xoffset, x, y, width);
28591c23b860cea93534f726d2a18658444f37f43538Brian Paul               break;
28601c23b860cea93534f726d2a18658444f37f43538Brian Paul            case 2:
28611c23b860cea93534f726d2a18658444f37f43538Brian Paul               ctx->Driver.CopyTexSubImage2D(ctx, target, level,
28621c23b860cea93534f726d2a18658444f37f43538Brian Paul                                             xoffset, yoffset,
28631c23b860cea93534f726d2a18658444f37f43538Brian Paul                                             x, y, width, height);
28641c23b860cea93534f726d2a18658444f37f43538Brian Paul               break;
28651c23b860cea93534f726d2a18658444f37f43538Brian Paul            case 3:
28661c23b860cea93534f726d2a18658444f37f43538Brian Paul               ctx->Driver.CopyTexSubImage3D(ctx, target, level,
28671c23b860cea93534f726d2a18658444f37f43538Brian Paul                                             xoffset, yoffset, zoffset,
28681c23b860cea93534f726d2a18658444f37f43538Brian Paul                                             x, y, width, height);
28691c23b860cea93534f726d2a18658444f37f43538Brian Paul               break;
28701c23b860cea93534f726d2a18658444f37f43538Brian Paul            default:
28711c23b860cea93534f726d2a18658444f37f43538Brian Paul               _mesa_problem(ctx, "bad dims in copytexsubimage()");
28721c23b860cea93534f726d2a18658444f37f43538Brian Paul            }
28732914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
28742914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul            check_gen_mipmap(ctx, target, texObj, level);
28752914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
2876a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul            ctx->NewState |= _NEW_TEXTURE;
2877a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul         }
2878a31ac84d743e33dabdcbbb4998fb6b7ceccf27d4Brian Paul      }
28795ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   }
28805ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_unlock_texture(ctx, texObj);
2881afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2882afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2883afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
28841c23b860cea93534f726d2a18658444f37f43538Brian Paulvoid GLAPIENTRY
28851c23b860cea93534f726d2a18658444f37f43538Brian Paul_mesa_CopyTexSubImage1D( GLenum target, GLint level,
28861c23b860cea93534f726d2a18658444f37f43538Brian Paul                         GLint xoffset, GLint x, GLint y, GLsizei width )
28871c23b860cea93534f726d2a18658444f37f43538Brian Paul{
28881c23b860cea93534f726d2a18658444f37f43538Brian Paul   GET_CURRENT_CONTEXT(ctx);
28891c23b860cea93534f726d2a18658444f37f43538Brian Paul   copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1);
28901c23b860cea93534f726d2a18658444f37f43538Brian Paul}
28911c23b860cea93534f726d2a18658444f37f43538Brian Paul
28921c23b860cea93534f726d2a18658444f37f43538Brian Paul
2893afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2894c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2895fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage2D( GLenum target, GLint level,
2896fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                         GLint xoffset, GLint yoffset,
2897fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                         GLint x, GLint y, GLsizei width, GLsizei height )
2898afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2899fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
29001c23b860cea93534f726d2a18658444f37f43538Brian Paul   copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y,
29011c23b860cea93534f726d2a18658444f37f43538Brian Paul                   width, height);
2902afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2904afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2905afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2906c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2907fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CopyTexSubImage3D( GLenum target, GLint level,
2908fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                         GLint xoffset, GLint yoffset, GLint zoffset,
2909fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul                         GLint x, GLint y, GLsizei width, GLsizei height )
2910afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2911fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
29121c23b860cea93534f726d2a18658444f37f43538Brian Paul   copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
29131c23b860cea93534f726d2a18658444f37f43538Brian Paul                   x, y, width, height);
2914afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
29151207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
29161207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
29171207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
291889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
291989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/
292089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/******                   Compressed Textures                    ******/
292189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**********************************************************************/
292289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
292389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
292489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**
292554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Return expected size of a compressed texture.
292654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul */
292754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulstatic GLuint
292854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulcompressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
292954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul                    GLenum glformat)
293054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul{
293154bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul   gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
293254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul   return _mesa_format_image_size(mesaFormat, width, height, depth);
293354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul}
293454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul
293554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul
293607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul/*
293707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul * Return compressed texture block size, in pixels.
293807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul */
293907ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulstatic void
294007ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paulget_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh)
294107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul{
294207ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
294307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   _mesa_get_format_block_size(mesaFormat, bw, bh);
294407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul}
294554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul
294654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul
294754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul/**
294889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexImage[123]D().
294989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR.
295089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */
295189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum
2952f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
295389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                               GLenum target, GLint level,
295489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                               GLenum internalFormat, GLsizei width,
295589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                               GLsizei height, GLsizei depth, GLint border,
295689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                               GLsizei imageSize)
295789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{
29584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   const GLenum proxyTarget = get_proxy_target(target);
29594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
29604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   GLint expectedSize;
296189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
29624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* check level */
29634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   if (level < 0 || level >= maxLevels)
29644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      return GL_INVALID_VALUE;
296589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
29667404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   if (!target_can_be_compressed(ctx, target, internalFormat)) {
29677404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      return GL_INVALID_ENUM;
29687404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   }
29697404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul
2970c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul   /* This will detect any invalid internalFormat value */
2971c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul   if (!_mesa_is_compressed_format(ctx, internalFormat))
297289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_ENUM;
297389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
2974c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul   /* This should really never fail */
2975a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick   if (_mesa_base_tex_format(ctx, internalFormat) < 0)
2976a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick      return GL_INVALID_ENUM;
2977a2dc424acfe83f3c66d3509f5a1efc24ce884367Ian Romanick
29784ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* No compressed formats support borders at this time */
297989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (border != 0)
298089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
298189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
298289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   /* For cube map, width must equal height */
298389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
298489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul       target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height)
298589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
298689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
29877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   /* check image size against compression block size */
29887404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   {
29897404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      gl_format texFormat =
29907404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul         ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
29917404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul                                         GL_NONE, GL_NONE);
29927404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      GLuint bw, bh;
29937404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul
29947404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      _mesa_get_format_block_size(texFormat, &bw, &bh);
29957404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      if ((width > bw && width % bw > 0) ||
29967404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul          (height > bh && height % bh > 0)) {
29977404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul         /*
29987404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul          * Per GL_ARB_texture_compression:  GL_INVALID_OPERATION is
29997404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul          * generated [...] if any parameter combinations are not
30007404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul          * supported by the specific compressed internal format.
30017404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul          */
30027404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul         return GL_INVALID_OPERATION;
30037404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      }
30047404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   }
30057404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul
30064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* check image sizes */
30074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
30084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                      internalFormat, GL_NONE, GL_NONE,
30094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                      width, height, depth, border)) {
30107404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      /* See error comment above */
30117404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      return GL_INVALID_OPERATION;
30124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   }
301389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
30144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* check image size in bytes */
301554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul   expectedSize = compressed_tex_size(width, height, depth, internalFormat);
30167404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   if (expectedSize != imageSize) {
30177404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul      /* Per GL_ARB_texture_compression:  GL_INVALID_VALUE is generated [...]
30187404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul       * if <imageSize> is not consistent with the format, dimensions, and
30197404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul       * contents of the specified image.
30207404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul       */
302189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
30227404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   }
302389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
302489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   return GL_NO_ERROR;
302589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul}
302689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
302789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
302889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/**
302989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Error checking for glCompressedTexSubImage[123]D().
30302371033bbaf6e7477bfa893654a0467a084f335bBrian Paul * \warning  There are some bad assumptions here about the size of compressed
30312371033bbaf6e7477bfa893654a0467a084f335bBrian Paul *           texture tiles (multiple of 4) used to test the validity of the
30322371033bbaf6e7477bfa893654a0467a084f335bBrian Paul *           offset and size parameters.
303389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return error code or GL_NO_ERROR.
303489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */
303589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paulstatic GLenum
3036f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions,
303789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                                  GLenum target, GLint level,
303889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                                  GLint xoffset, GLint yoffset, GLint zoffset,
303989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                                  GLsizei width, GLsizei height, GLsizei depth,
304089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul                                  GLenum format, GLsizei imageSize)
304189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{
304289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   GLint expectedSize, maxLevels = 0, maxTextureSize;
304307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   GLuint bw, bh;
3044a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul   (void) zoffset;
304589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
304689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (dimensions == 1) {
304789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      /* 1D compressed textures not allowed */
304889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_ENUM;
304989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   }
305089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   else if (dimensions == 2) {
305189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      if (target == GL_PROXY_TEXTURE_2D) {
305289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         maxLevels = ctx->Const.MaxTextureLevels;
305389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
305489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      else if (target == GL_TEXTURE_2D) {
305589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         maxLevels = ctx->Const.MaxTextureLevels;
305689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
305789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
305889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         if (!ctx->Extensions.ARB_texture_cube_map)
305989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul            return GL_INVALID_ENUM; /*target*/
306089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         maxLevels = ctx->Const.MaxCubeTextureLevels;
306189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
306289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
306389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul               target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
306489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         if (!ctx->Extensions.ARB_texture_cube_map)
306589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul            return GL_INVALID_ENUM; /*target*/
306689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         maxLevels = ctx->Const.MaxCubeTextureLevels;
306789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
306889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      else {
306989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return GL_INVALID_ENUM; /*target*/
307089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
307189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   }
307289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   else if (dimensions == 3) {
307389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      /* 3D compressed textures not allowed */
307489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_ENUM;
307589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   }
307689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
307789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   maxTextureSize = 1 << (maxLevels - 1);
307889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
3079c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul   /* this will catch any invalid compressed format token */
3080c34feadd1c2fa5c62022c1f48ee675b25a985ac6Brian Paul   if (!_mesa_is_compressed_format(ctx, format))
308189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_ENUM;
308289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
3083887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul   if (width < 1 || width > maxTextureSize)
308489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
308589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
3086887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul   if ((height < 1 || height > maxTextureSize)
308789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul       && dimensions > 1)
308889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
308989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
309089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (level < 0 || level >= maxLevels)
309189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
309289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
309307ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   /*
309407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul    * do checks which depend on compression block size
30952371033bbaf6e7477bfa893654a0467a084f335bBrian Paul    */
309607ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   get_compressed_block_size(format, &bw, &bh);
309707ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul
309807ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   if ((xoffset % bw != 0) || (yoffset % bh != 0))
309989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
310089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
310107ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   if ((width % bw != 0) && width != 2 && width != 1)
310289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
310389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
310407ad6393cb31d8f1f086f9c46705334ef9cf25f6Brian Paul   if ((height % bh != 0) && height != 2 && height != 1)
310589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
310689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
310754bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul   expectedSize = compressed_tex_size(width, height, depth, format);
310889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (expectedSize != imageSize)
310989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return GL_INVALID_VALUE;
311089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
311189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   return GL_NO_ERROR;
311289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul}
311389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
311489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul
3115f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul/**
3116f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * Do second part of glCompressedTexSubImage error checking.
3117f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul * \return GL_TRUE if error found, GL_FALSE otherwise.
3118f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul */
3119f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paulstatic GLboolean
3120f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergcompressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims,
3121f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                                   GLsizei width, GLsizei height,
3122f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                                   GLsizei depth, GLenum format,
3123f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                                   struct gl_texture_image *texImage)
3124f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul{
3125f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3126f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   if ((GLint) format != texImage->InternalFormat) {
3127f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      _mesa_error(ctx, GL_INVALID_OPERATION,
3128f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                  "glCompressedTexSubImage%uD(format=0x%x)", dims, format);
3129f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      return GL_TRUE;
3130f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   }
3131f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3132f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   if (((width == 1 || width == 2) &&
3133ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul        width != (GLsizei) texImage->Width) ||
3134ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul       (width > (GLsizei) texImage->Width)) {
3135f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      _mesa_error(ctx, GL_INVALID_VALUE,
3136f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                  "glCompressedTexSubImage%uD(width=%d)", dims, width);
3137f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      return GL_TRUE;
3138f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   }
3139f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3140f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   if (dims >= 2) {
3141f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      if (((height == 1 || height == 2) &&
3142ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul           height != (GLsizei) texImage->Height) ||
3143ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul          (height > (GLsizei) texImage->Height)) {
3144f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
3145f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                     "glCompressedTexSubImage%uD(height=%d)", dims, height);
3146f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul         return GL_TRUE;
3147f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      }
3148f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   }
3149f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3150f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   if (dims >= 3) {
3151f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      if (((depth == 1 || depth == 2) &&
3152ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul           depth != (GLsizei) texImage->Depth) ||
3153ca0d048e4e0cc5885cd309cdf9057cfe6044924eBrian Paul          (depth > (GLsizei) texImage->Depth)) {
3154f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul         _mesa_error(ctx, GL_INVALID_VALUE,
3155f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                     "glCompressedTexSubImage%uD(depth=%d)", dims, depth);
3156f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul         return GL_TRUE;
3157f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul      }
3158f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   }
3159f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3160f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul   return GL_FALSE;
3161f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul}
3162f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
3163f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul
31644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul/**
31654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul * Implementation of the glCompressedTexImage1/2/3D() functions.
31664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul */
31674ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulstatic void
31684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulcompressedteximage(struct gl_context *ctx, GLuint dims,
31694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                   GLenum target, GLint level,
31704ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                   GLenum internalFormat, GLsizei width,
31714ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                   GLsizei height, GLsizei depth, GLint border,
31724ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                   GLsizei imageSize, const GLvoid *data)
31731207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{
31744ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   GLenum error;
31754ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
3176cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3177aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul
3178d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
31794ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      _mesa_debug(ctx,
31804ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
31814ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  dims,
3182d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(target), level,
3183d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora                  _mesa_lookup_enum_by_nr(internalFormat),
31844ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  width, height, depth, border, imageSize, data);
31855ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
31864ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* check target */
31877404fa3f07a953343f2640fa97d82ab82ba5545dBrian Paul   if (!legal_teximage_target(ctx, dims, target)) {
31884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)",
31894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  dims, _mesa_lookup_enum_by_nr(target));
3190aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      return;
3191aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul   }
31921207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
31934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   error = compressed_texture_error_check(ctx, dims, target, level,
31944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                          internalFormat, width, height, depth,
31954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                          border, imageSize);
3196d100cbf721010f4eacc87507cc87c5314150d493Maciej Cencora
31977179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg#if FEATURE_ES
31984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   /* XXX this is kind of a hack */
31994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   if (error) {
32004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      _mesa_error(ctx, error, "glTexImage2D");
32017179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg      return;
32027179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg   }
32037179a822628963d8cfa0817cf072c5acb70638a7Kristian Høgsberg
32044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   if (dims == 2) {
32054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      switch (internalFormat) {
32064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE4_RGB8_OES:
32074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE4_RGBA8_OES:
32084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE4_R5_G6_B5_OES:
32094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE4_RGBA4_OES:
32104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE4_RGB5_A1_OES:
32114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE8_RGB8_OES:
32124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE8_RGBA8_OES:
32134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE8_R5_G6_B5_OES:
32144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE8_RGBA4_OES:
32154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      case GL_PALETTE8_RGB5_A1_OES:
32164ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         _mesa_cpal_compressed_teximage2d(target, level, internalFormat,
32174ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                          width, height, imageSize, data);
321889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return;
3219aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      }
32204ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   }
32214ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul#endif
3222aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul
32234ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   if (_mesa_is_proxy_texture(target)) {
32244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      /* Proxy texture: just check for errors and update proxy state */
32254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      struct gl_texture_image *texImage;
32262914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
32278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      if (!error) {
32284ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         struct gl_texture_object *texObj =
32294ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            _mesa_get_current_tex_object(ctx, target);
32304ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         gl_format texFormat =
32314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            _mesa_choose_texture_format(ctx, texObj, target, level,
32324ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                        internalFormat, GL_NONE, GL_NONE);
32334ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         if (!legal_texture_size(ctx, texFormat, width, height, depth)) {
32344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            error = GL_OUT_OF_MEMORY;
32354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         }
3236aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      }
32375ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell
32384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      texImage = _mesa_get_proxy_tex_image(ctx, target, level);
32394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul      if (texImage) {
32404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         if (error) {
32414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            /* if error, clear all proxy texture image parameters */
32424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            clear_teximage_fields(texImage);
32434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         }
32444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         else {
32454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            /* no error: store the teximage parameters */
32464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul            _mesa_init_teximage_fields(ctx, target, texImage, width, height,
32474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                       depth, border, internalFormat,
32484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                       MESA_FORMAT_NONE);
32494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         }
325089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      }
3251aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul   }
3252aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul   else {
32538c3ddf4270ff075ee783a67e5d5d04fa16a9cb45Brian Paul      /* non-proxy target */
3254aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      struct gl_texture_object *texObj;
3255aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      struct gl_texture_image *texImage;
32564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
325789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      if (error) {
32584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul         _mesa_error(ctx, error, "glCompressedTexImage%uD", dims);
325989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul         return;
3260aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul      }
3261aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul
3262b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul      texObj = _mesa_get_current_tex_object(ctx, target);
32639519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul
32645ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      _mesa_lock_texture(ctx, texObj);
32655ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      {
32665ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
32675ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 if (!texImage) {
32684ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul	    _mesa_error(ctx, GL_OUT_OF_MEMORY,
32694ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                        "glCompressedTexImage%uD", dims);
32705ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell	 }
3271c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         else {
327283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul            gl_format texFormat;
327383e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
3274c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul            if (texImage->Data) {
3275c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul               ctx->Driver.FreeTexImageData( ctx, texImage );
3276c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul            }
3277c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul            ASSERT(texImage->Data == NULL);
3278c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul
327983e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
328083e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                    internalFormat, GL_NONE,
328183e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul                                                    GL_NONE);
328283e93b6008213ad86607027e8434ecaccc8b1a2cBrian Paul
32834b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            if (legal_texture_size(ctx, texFormat, width, height, depth)) {
32844b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               _mesa_init_teximage_fields(ctx, target, texImage,
32854b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul                                          width, height, depth,
32864b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul                                          border, internalFormat, texFormat);
328711caea687e3f10ae12d33e44edf84635f73047ddBrian Paul
32884ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               switch (dims) {
32894ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               case 1:
32904ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ASSERT(ctx->Driver.CompressedTexImage1D);
32914ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ctx->Driver.CompressedTexImage1D(ctx, target, level,
32924ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   internalFormat,
32934ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   width,
32944ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   border, imageSize, data,
32954ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   texObj, texImage);
32964ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  break;
32974ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               case 2:
32984ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ASSERT(ctx->Driver.CompressedTexImage2D);
32994ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ctx->Driver.CompressedTexImage2D(ctx, target, level,
33004ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   internalFormat,
33014ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   width, height,
33024ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   border, imageSize, data,
33034ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   texObj, texImage);
33044ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  break;
33054ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               case 3:
33064ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ASSERT(ctx->Driver.CompressedTexImage3D);
33074ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  ctx->Driver.CompressedTexImage3D(ctx, target, level,
33084ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   internalFormat,
33094ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   width, height, depth,
33104ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   border, imageSize, data,
33114ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                                                   texObj, texImage);
33124ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  break;
33134ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               default:
33144ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                  _mesa_problem(ctx, "bad dims in compressedteximage");
33154ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               }
3316c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul
33174b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               check_gen_mipmap(ctx, target, texObj, level);
33182914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
33194b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               /* state update */
33204b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               texObj->_Complete = GL_FALSE;
33214b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul               ctx->NewState |= _NEW_TEXTURE;
33224b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            }
33234b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            else {
33244ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul               _mesa_error(ctx, GL_OUT_OF_MEMORY,
33254ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                           "glCompressedTexImage%uD", dims);
33264b08f35487fa439fd9ca4d653d3a146c3dc09c1cBrian Paul            }
3327c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         }
3328c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul      }
33295ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      _mesa_unlock_texture(ctx, texObj);
3330aea66b135eaa5a5f2bc8c652fa7a1a42cca2fe83Brian Paul   }
33314ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul}
33329519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul
33339519603f7405a1043ea39bf1dfaf4c88529ce2d1Brian Paul
33344ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY
33354ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage1DARB(GLenum target, GLint level,
33364ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLenum internalFormat, GLsizei width,
33374ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLint border, GLsizei imageSize,
33384ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              const GLvoid *data)
33394ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{
33404ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   GET_CURRENT_CONTEXT(ctx);
33414ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   compressedteximage(ctx, 1, target, level, internalFormat,
33424ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                      width, 1, 1, border, imageSize, data);
33434ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul}
33444ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
33454ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
33464ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY
33474ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
33484ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLenum internalFormat, GLsizei width,
33494ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLsizei height, GLint border, GLsizei imageSize,
33504ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              const GLvoid *data)
33514ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{
33524ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   GET_CURRENT_CONTEXT(ctx);
33534ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   compressedteximage(ctx, 2, target, level, internalFormat,
33544ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                      width, height, 1, border, imageSize, data);
33554ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul}
33564ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
33574ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul
33584ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paulvoid GLAPIENTRY
33594ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul_mesa_CompressedTexImage3DARB(GLenum target, GLint level,
33604ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLenum internalFormat, GLsizei width,
33614ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLsizei height, GLsizei depth, GLint border,
33624ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                              GLsizei imageSize, const GLvoid *data)
33634ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul{
33644ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   GET_CURRENT_CONTEXT(ctx);
33654ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul   compressedteximage(ctx, 3, target, level, internalFormat,
33664ff70b7a8f5f6383d8f320e68d798d0654799210Brian Paul                      width, height, depth, border, imageSize, data);
33671207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul}
33681207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
33691207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
33706bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul/**
33716bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul * Common helper for glCompressedTexSubImage1/2/3D().
33726bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul */
33736bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulstatic void
33746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulcompressed_tex_sub_image(GLuint dims, GLenum target, GLint level,
33756bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                         GLint xoffset, GLint yoffset, GLint zoffset,
33766bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                         GLsizei width, GLsizei height, GLsizei depth,
33776bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                         GLenum format, GLsizei imageSize, const GLvoid *data)
33781207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{
33799540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul   struct gl_texture_object *texObj;
33809540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul   struct gl_texture_image *texImage;
338189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   GLenum error;
3382a1f1586bcb9fcd4a30930fd14b73323642ce85c5Brian Paul   GET_CURRENT_CONTEXT(ctx);
338375280a2c742ee241d392618a3b29548fce1520a9Brian Paul   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
338475280a2c742ee241d392618a3b29548fce1520a9Brian Paul
33856bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul   error = compressed_subtexture_error_check(ctx, dims, target, level,
3386c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul                                             xoffset, 0, 0, /* pos */
33876bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                             width, height, depth,   /* size */
3388c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul                                             format, imageSize);
338989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul   if (error) {
33906bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul      _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims);
339189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul      return;
33929540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul   }
33939540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul
3394b8fdb900fb9b1c8b1e9ec88509624237307a869aBrian Paul   texObj = _mesa_get_current_tex_object(ctx, target);
3395c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul
33965ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_lock_texture(ctx, texObj);
33975ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   {
33985ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      texImage = _mesa_select_tex_image(ctx, texObj, target, level);
33995ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      assert(texImage);
34009540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul
34016bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul      if (compressed_subtexture_error_check2(ctx, dims, width, height, depth,
3402f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul                                             format, texImage)) {
3403f3c29bd74f01370a6bbff1329966ca9d1864315fBrian Paul         /* error was recorded */
3404c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul      }
34056bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul      else if (width > 0 && height > 0 && depth > 0) {
34066bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul         switch (dims) {
34076bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul         case 1:
34086bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            if (ctx->Driver.CompressedTexSubImage1D) {
34096bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul               ctx->Driver.CompressedTexSubImage1D(ctx, target, level,
34106bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   xoffset, width,
34116bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   format, imageSize, data,
34126bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   texObj, texImage);
34136bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            }
34146bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            break;
34156bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul         case 2:
34166bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            if (ctx->Driver.CompressedTexSubImage2D) {
34176bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul               ctx->Driver.CompressedTexSubImage2D(ctx, target, level,
34186bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   xoffset, yoffset,
34196bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   width, height,
34206bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   format, imageSize, data,
34216bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   texObj, texImage);
34226bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            }
34236bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            break;
34246bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul         case 3:
34256bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            if (ctx->Driver.CompressedTexSubImage3D) {
34266bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul               ctx->Driver.CompressedTexSubImage3D(ctx, target, level,
34276bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   xoffset, yoffset, zoffset,
34286bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   width, height, depth,
34296bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   format, imageSize, data,
34306bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                                   texObj, texImage);
34316bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            }
34326bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            break;
34336bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul         default:
34346bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul            ;
3435c352566933b932ef09cea3f144df21147a7f6bc1Brian Paul         }
34362914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
34372914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul         check_gen_mipmap(ctx, target, texObj, level);
34382914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul
34392914f2b7fd9bd1082f8cce724d234208b900c3d4Brian Paul         ctx->NewState |= _NEW_TEXTURE;
34405ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell      }
34419540a1dbcf213645b23c6cd9284e92a1152cca05Brian Paul   }
34425ac93f86210eb5c2a8dee74ec19b0ecd54376863Keith Whitwell   _mesa_unlock_texture(ctx, texObj);
34431207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul}
34441207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
34451207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
3446c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
34476bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
34486bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                 GLsizei width, GLenum format,
34496bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                                 GLsizei imageSize, const GLvoid *data)
34506bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul{
34516bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul   compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1,
34526bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                            format, imageSize, data);
34536bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul}
34546bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul
34556bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul
34566bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paulvoid GLAPIENTRY
34571207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
34581207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 GLint yoffset, GLsizei width, GLsizei height,
34591207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 GLenum format, GLsizei imageSize,
34601207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 const GLvoid *data)
34611207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{
34626bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul   compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0,
34636bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                            width, height, 1, format, imageSize, data);
34641207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul}
34651207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
34661207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul
3467c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
34681207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
34691207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 GLint yoffset, GLint zoffset, GLsizei width,
34701207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 GLsizei height, GLsizei depth, GLenum format,
34711207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul                                 GLsizei imageSize, const GLvoid *data)
34721207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul{
34736bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul   compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset,
34746bc1e9fd6989483fbc1c94730a8014b4c62b242cBrian Paul                            width, height, depth, format, imageSize, data);
34751207bf057aeea3376e5e0f03f789a5d67ed4d29dBrian Paul}
3476