blob: 7eb8d9352b1584674ddaf1c013b2e6f32995499d [file] [log] [blame]
Brian Paul1f575632001-02-26 18:24:55 +00001/* $Id: teximage.c,v 1.79 2001/02/26 18:24:55 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul01e54752000-09-05 15:40:34 +00005 * Version: 3.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Brian Paul663049a2000-01-31 23:10:16 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00008 *
jtgafb833d1999-08-19 00:55:39 +00009 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
jtgafb833d1999-08-19 00:55:39 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000018 *
jtgafb833d1999-08-19 00:55:39 +000019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "context.h"
Brian Paulf93b3dd2000-08-30 18:22:28 +000033#include "convolve.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "image.h"
Brian Paulebb248a2000-10-29 18:23:16 +000035#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000036#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "mmath.h"
Brian Paulfa4525e2000-08-21 14:22:24 +000038#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000039#include "teximage.h"
40#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000041#include "mtypes.h"
Brian Paul7298e712000-11-07 16:40:37 +000042#include "swrast/s_span.h" /* XXX SWRAST hack */
jtgafb833d1999-08-19 00:55:39 +000043#endif
44
45
46/*
47 * NOTES:
48 *
Brian Paul699bc7b2000-10-29 18:12:14 +000049 * Mesa's native texture datatype is GLchan. Native formats are
Brian Paulc3f0a511999-11-03 17:27:05 +000050 * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA,
51 * and GL_COLOR_INDEX.
52 * Device drivers are free to implement any internal format they want.
jtgafb833d1999-08-19 00:55:39 +000053 */
54
55
Brian Paul48271792000-03-29 18:13:59 +000056#ifdef DEBUG
Brian Paule5d68a22000-03-30 18:37:51 +000057static void PrintTexture(const struct gl_texture_image *img)
Brian Paul48271792000-03-29 18:13:59 +000058{
Brian Paule5d68a22000-03-30 18:37:51 +000059 int i, j, c;
Brian Paul699bc7b2000-10-29 18:12:14 +000060 GLchan *data = img->Data;
Brian Paule5d68a22000-03-30 18:37:51 +000061
62 if (!data) {
63 printf("No texture data\n");
64 return;
65 }
66
67 switch (img->Format) {
68 case GL_ALPHA:
69 case GL_LUMINANCE:
70 case GL_INTENSITY:
71 case GL_COLOR_INDEX:
72 c = 1;
73 break;
74 case GL_LUMINANCE_ALPHA:
75 c = 2;
76 break;
77 case GL_RGB:
78 c = 3;
79 break;
80 case GL_RGBA:
81 c = 4;
82 break;
83 default:
84 gl_problem(NULL, "error in PrintTexture\n");
85 return;
86 }
87
88
89 for (i = 0; i < img->Height; i++) {
90 for (j = 0; j < img->Width; j++) {
Brian Paul48271792000-03-29 18:13:59 +000091 if (c==1)
92 printf("%02x ", data[0]);
93 else if (c==2)
Brian Paule5d68a22000-03-30 18:37:51 +000094 printf("%02x%02x ", data[0], data[1]);
Brian Paul48271792000-03-29 18:13:59 +000095 else if (c==3)
Brian Paule5d68a22000-03-30 18:37:51 +000096 printf("%02x%02x%02x ", data[0], data[1], data[2]);
Brian Paul48271792000-03-29 18:13:59 +000097 else if (c==4)
Brian Paule5d68a22000-03-30 18:37:51 +000098 printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]);
Brian Paul48271792000-03-29 18:13:59 +000099 data += c;
100 }
101 printf("\n");
102 }
103}
104#endif
105
106
107
Brian Paulf7b57072000-03-20 14:37:52 +0000108/*
jtgafb833d1999-08-19 00:55:39 +0000109 * Compute log base 2 of n.
110 * If n isn't an exact power of two return -1.
111 * If n<0 return -1.
112 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000113static int
114logbase2( int n )
jtgafb833d1999-08-19 00:55:39 +0000115{
116 GLint i = 1;
117 GLint log2 = 0;
118
119 if (n<0) {
120 return -1;
121 }
122
123 while ( n > i ) {
124 i *= 2;
125 log2++;
126 }
127 if (i != n) {
128 return -1;
129 }
130 else {
131 return log2;
132 }
133}
134
135
136
137/*
138 * Given an internal texture format enum or 1, 2, 3, 4 return the
139 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
Brian Paulc3f0a511999-11-03 17:27:05 +0000140 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA.
141 * Return -1 if invalid enum.
jtgafb833d1999-08-19 00:55:39 +0000142 */
Brian Paulb132e8d2000-03-23 16:23:14 +0000143GLint
Brian Paulaea66b12000-05-24 14:04:06 +0000144_mesa_base_tex_format( GLcontext *ctx, GLint format )
jtgafb833d1999-08-19 00:55:39 +0000145{
Brian Paul289d47e2000-08-29 23:31:23 +0000146 /*
147 * Ask the driver for the base format, if it doesn't
148 * know, it will return -1;
149 */
150 if (ctx->Driver.BaseCompressedTexFormat) {
151 GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format);
152 if (ifmt >= 0) {
153 return ifmt;
154 }
155 }
jtgafb833d1999-08-19 00:55:39 +0000156 switch (format) {
157 case GL_ALPHA:
158 case GL_ALPHA4:
159 case GL_ALPHA8:
160 case GL_ALPHA12:
161 case GL_ALPHA16:
162 return GL_ALPHA;
163 case 1:
164 case GL_LUMINANCE:
165 case GL_LUMINANCE4:
166 case GL_LUMINANCE8:
167 case GL_LUMINANCE12:
168 case GL_LUMINANCE16:
169 return GL_LUMINANCE;
170 case 2:
171 case GL_LUMINANCE_ALPHA:
172 case GL_LUMINANCE4_ALPHA4:
173 case GL_LUMINANCE6_ALPHA2:
174 case GL_LUMINANCE8_ALPHA8:
175 case GL_LUMINANCE12_ALPHA4:
176 case GL_LUMINANCE12_ALPHA12:
177 case GL_LUMINANCE16_ALPHA16:
178 return GL_LUMINANCE_ALPHA;
179 case GL_INTENSITY:
180 case GL_INTENSITY4:
181 case GL_INTENSITY8:
182 case GL_INTENSITY12:
183 case GL_INTENSITY16:
184 return GL_INTENSITY;
185 case 3:
186 case GL_RGB:
187 case GL_R3_G3_B2:
188 case GL_RGB4:
189 case GL_RGB5:
190 case GL_RGB8:
191 case GL_RGB10:
192 case GL_RGB12:
193 case GL_RGB16:
194 return GL_RGB;
195 case 4:
196 case GL_RGBA:
197 case GL_RGBA2:
198 case GL_RGBA4:
199 case GL_RGB5_A1:
200 case GL_RGBA8:
201 case GL_RGB10_A2:
202 case GL_RGBA12:
203 case GL_RGBA16:
204 return GL_RGBA;
205 case GL_COLOR_INDEX:
206 case GL_COLOR_INDEX1_EXT:
207 case GL_COLOR_INDEX2_EXT:
208 case GL_COLOR_INDEX4_EXT:
209 case GL_COLOR_INDEX8_EXT:
210 case GL_COLOR_INDEX12_EXT:
211 case GL_COLOR_INDEX16_EXT:
212 return GL_COLOR_INDEX;
Brian Paulf7e1dfe2001-02-17 00:15:39 +0000213 case GL_DEPTH_COMPONENT:
214 case GL_DEPTH_COMPONENT16_SGIX:
215 case GL_DEPTH_COMPONENT24_SGIX:
216 case GL_DEPTH_COMPONENT32_SGIX:
217 if (ctx->Extensions.SGIX_depth_texture)
218 return GL_DEPTH_COMPONENT;
219 else
220 return -1;
jtgafb833d1999-08-19 00:55:39 +0000221 default:
222 return -1; /* error */
223 }
224}
225
226
Brian Paulf7e1dfe2001-02-17 00:15:39 +0000227/*
228 * Test if the given image format is a color/rgba format. That is,
229 * not color index, depth, stencil, etc.
230 */
231static GLboolean
232is_color_format(GLenum format)
233{
234 switch (format) {
235 case GL_ALPHA:
236 case GL_ALPHA4:
237 case GL_ALPHA8:
238 case GL_ALPHA12:
239 case GL_ALPHA16:
240 case 1:
241 case GL_LUMINANCE:
242 case GL_LUMINANCE4:
243 case GL_LUMINANCE8:
244 case GL_LUMINANCE12:
245 case GL_LUMINANCE16:
246 case 2:
247 case GL_LUMINANCE_ALPHA:
248 case GL_LUMINANCE4_ALPHA4:
249 case GL_LUMINANCE6_ALPHA2:
250 case GL_LUMINANCE8_ALPHA8:
251 case GL_LUMINANCE12_ALPHA4:
252 case GL_LUMINANCE12_ALPHA12:
253 case GL_LUMINANCE16_ALPHA16:
254 case GL_INTENSITY:
255 case GL_INTENSITY4:
256 case GL_INTENSITY8:
257 case GL_INTENSITY12:
258 case GL_INTENSITY16:
259 case 3:
260 case GL_RGB:
261 case GL_R3_G3_B2:
262 case GL_RGB4:
263 case GL_RGB5:
264 case GL_RGB8:
265 case GL_RGB10:
266 case GL_RGB12:
267 case GL_RGB16:
268 case 4:
269 case GL_RGBA:
270 case GL_RGBA2:
271 case GL_RGBA4:
272 case GL_RGB5_A1:
273 case GL_RGBA8:
274 case GL_RGB10_A2:
275 case GL_RGBA12:
276 case GL_RGBA16:
277 return GL_TRUE;
278 default:
279 return GL_FALSE;
280 }
281}
282
283
284static GLboolean
285is_index_format(GLenum format)
286{
287 switch (format) {
288 case GL_COLOR_INDEX:
289 case GL_COLOR_INDEX1_EXT:
290 case GL_COLOR_INDEX2_EXT:
291 case GL_COLOR_INDEX4_EXT:
292 case GL_COLOR_INDEX8_EXT:
293 case GL_COLOR_INDEX12_EXT:
294 case GL_COLOR_INDEX16_EXT:
295 return GL_TRUE;
296 default:
297 return GL_FALSE;
298 }
299}
300
jtgafb833d1999-08-19 00:55:39 +0000301
302/*
Brian Paulaea66b12000-05-24 14:04:06 +0000303 * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE
304 * otherwise.
305 */
306static GLboolean
Brian Paul289d47e2000-08-29 23:31:23 +0000307is_compressed_format(GLcontext *ctx, GLenum internalFormat)
Brian Paulaea66b12000-05-24 14:04:06 +0000308{
Brian Paul289d47e2000-08-29 23:31:23 +0000309 if (ctx->Driver.IsCompressedFormat) {
310 return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat);
311 }
312 return GL_FALSE;
Brian Paulaea66b12000-05-24 14:04:06 +0000313}
314
315
jtgafb833d1999-08-19 00:55:39 +0000316
jtgafb833d1999-08-19 00:55:39 +0000317/*
Brian Paul8e39ad22001-02-06 21:42:48 +0000318 * Store a gl_texture_image pointer in a gl_texture_object structure
319 * according to the target and level parameters.
320 * This was basically prompted by the introduction of cube maps.
jtgafb833d1999-08-19 00:55:39 +0000321 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000322static void
Brian Paulfc4b4432000-05-23 15:17:12 +0000323set_tex_image(struct gl_texture_object *tObj,
324 GLenum target, GLint level,
325 struct gl_texture_image *texImage)
326{
327 ASSERT(tObj);
328 ASSERT(texImage);
329 switch (target) {
330 case GL_TEXTURE_2D:
331 tObj->Image[level] = texImage;
332 return;
333 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
Brian Paul413d6a22000-05-26 14:44:59 +0000334 tObj->Image[level] = texImage;
Brian Paulfc4b4432000-05-23 15:17:12 +0000335 return;
336 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
337 tObj->NegX[level] = texImage;
338 return;
339 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
340 tObj->PosY[level] = texImage;
341 return;
342 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
343 tObj->NegY[level] = texImage;
344 return;
345 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
346 tObj->PosZ[level] = texImage;
347 return;
348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
349 tObj->NegZ[level] = texImage;
350 return;
351 default:
352 gl_problem(NULL, "bad target in set_tex_image()");
353 return;
354 }
355}
356
357
Brian Paul8e39ad22001-02-06 21:42:48 +0000358
Brian Paul77ce6da2000-03-20 23:40:12 +0000359/*
360 * Return new gl_texture_image struct with all fields initialized to zero.
361 */
362struct gl_texture_image *
Brian Paul021a5252000-03-27 17:54:17 +0000363_mesa_alloc_texture_image( void )
Brian Paul77ce6da2000-03-20 23:40:12 +0000364{
365 return CALLOC_STRUCT(gl_texture_image);
366}
367
368
369
Brian Paul77ce6da2000-03-20 23:40:12 +0000370void
Brian Paul021a5252000-03-27 17:54:17 +0000371_mesa_free_texture_image( struct gl_texture_image *teximage )
Brian Paul77ce6da2000-03-20 23:40:12 +0000372{
373 if (teximage->Data) {
374 FREE( teximage->Data );
375 teximage->Data = NULL;
376 }
377 FREE( teximage );
378}
379
380
Brian Paulfc4b4432000-05-23 15:17:12 +0000381/*
Brian Paul8e39ad22001-02-06 21:42:48 +0000382 * Return GL_TRUE if the target is a proxy target.
Brian Paulaea66b12000-05-24 14:04:06 +0000383 */
Brian Paul8e39ad22001-02-06 21:42:48 +0000384static GLboolean
385is_proxy_target(GLenum target)
Brian Paulaea66b12000-05-24 14:04:06 +0000386{
Brian Paul8e39ad22001-02-06 21:42:48 +0000387 return (target == GL_PROXY_TEXTURE_1D ||
388 target == GL_PROXY_TEXTURE_2D ||
389 target == GL_PROXY_TEXTURE_3D ||
390 target == GL_PROXY_TEXTURE_CUBE_MAP_ARB);
Brian Paulaea66b12000-05-24 14:04:06 +0000391}
392
393
Brian Paulaea66b12000-05-24 14:04:06 +0000394/*
Brian Paul35d53012000-05-23 17:14:49 +0000395 * Given a texture unit and a texture target, return the corresponding
396 * texture object.
397 */
398struct gl_texture_object *
Brian Paul01e54752000-09-05 15:40:34 +0000399_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
Brian Paul35d53012000-05-23 17:14:49 +0000400 GLenum target)
401{
402 switch (target) {
403 case GL_TEXTURE_1D:
Brian Paula8523782000-11-19 23:10:25 +0000404 return texUnit->Current1D;
Brian Paul35d53012000-05-23 17:14:49 +0000405 case GL_PROXY_TEXTURE_1D:
406 return ctx->Texture.Proxy1D;
407 case GL_TEXTURE_2D:
Brian Paula8523782000-11-19 23:10:25 +0000408 return texUnit->Current2D;
Brian Paul35d53012000-05-23 17:14:49 +0000409 case GL_PROXY_TEXTURE_2D:
410 return ctx->Texture.Proxy2D;
411 case GL_TEXTURE_3D:
Brian Paula8523782000-11-19 23:10:25 +0000412 return texUnit->Current3D;
Brian Paul35d53012000-05-23 17:14:49 +0000413 case GL_PROXY_TEXTURE_3D:
414 return ctx->Texture.Proxy3D;
415 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
416 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
417 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
418 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
419 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
420 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000421 return ctx->Extensions.ARB_texture_cube_map
Brian Paul35d53012000-05-23 17:14:49 +0000422 ? texUnit->CurrentCubeMap : NULL;
423 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000424 return ctx->Extensions.ARB_texture_cube_map
Brian Paul35d53012000-05-23 17:14:49 +0000425 ? ctx->Texture.ProxyCubeMap : NULL;
426 default:
427 gl_problem(NULL, "bad target in _mesa_select_tex_object()");
428 return NULL;
429 }
430}
431
432
433/*
Brian Paulfc4b4432000-05-23 15:17:12 +0000434 * Return the texture image struct which corresponds to target and level
435 * for the given texture unit.
436 */
437struct gl_texture_image *
438_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit,
439 GLenum target, GLint level)
440{
441 ASSERT(texUnit);
442 switch (target) {
443 case GL_TEXTURE_1D:
Brian Paula8523782000-11-19 23:10:25 +0000444 return texUnit->Current1D->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000445 case GL_PROXY_TEXTURE_1D:
446 return ctx->Texture.Proxy1D->Image[level];
447 case GL_TEXTURE_2D:
Brian Paula8523782000-11-19 23:10:25 +0000448 return texUnit->Current2D->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000449 case GL_PROXY_TEXTURE_2D:
450 return ctx->Texture.Proxy2D->Image[level];
451 case GL_TEXTURE_3D:
Brian Paula8523782000-11-19 23:10:25 +0000452 return texUnit->Current3D->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000453 case GL_PROXY_TEXTURE_3D:
454 return ctx->Texture.Proxy3D->Image[level];
455 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000456 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paul413d6a22000-05-26 14:44:59 +0000457 return texUnit->CurrentCubeMap->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000458 else
459 return NULL;
460 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000461 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paulfc4b4432000-05-23 15:17:12 +0000462 return texUnit->CurrentCubeMap->NegX[level];
463 else
464 return NULL;
465 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000466 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paulfc4b4432000-05-23 15:17:12 +0000467 return texUnit->CurrentCubeMap->PosY[level];
468 else
469 return NULL;
470 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000471 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paulfc4b4432000-05-23 15:17:12 +0000472 return texUnit->CurrentCubeMap->NegY[level];
473 else
474 return NULL;
475 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000476 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paulfc4b4432000-05-23 15:17:12 +0000477 return texUnit->CurrentCubeMap->PosZ[level];
478 else
479 return NULL;
480 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000481 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paulfc4b4432000-05-23 15:17:12 +0000482 return texUnit->CurrentCubeMap->NegZ[level];
483 else
484 return NULL;
485 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
Keith Whitwella96308c2000-10-30 13:31:59 +0000486 if (ctx->Extensions.ARB_texture_cube_map)
Brian Paul413d6a22000-05-26 14:44:59 +0000487 return ctx->Texture.ProxyCubeMap->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000488 else
489 return NULL;
490 default:
491 gl_problem(ctx, "bad target in _mesa_select_tex_image()");
492 return NULL;
493 }
494}
495
496
497
Brian Paulf93b3dd2000-08-30 18:22:28 +0000498/*
jtgafb833d1999-08-19 00:55:39 +0000499 * glTexImage[123]D can accept a NULL image pointer. In this case we
500 * create a texture image with unspecified image contents per the OpenGL
Brian Paul8e39ad22001-02-06 21:42:48 +0000501 * spec.
jtgafb833d1999-08-19 00:55:39 +0000502 */
Brian Paul8e39ad22001-02-06 21:42:48 +0000503static GLubyte *
504make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
jtgafb833d1999-08-19 00:55:39 +0000505{
Brian Paul8e39ad22001-02-06 21:42:48 +0000506 const GLint components = _mesa_components_in_format(format);
507 const GLint numPixels = width * height * depth;
508 GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte));
jtgafb833d1999-08-19 00:55:39 +0000509
510 /*
511 * Let's see if anyone finds this. If glTexImage2D() is called with
512 * a NULL image pointer then load the texture image with something
513 * interesting instead of leaving it indeterminate.
514 */
Brian Paul8e39ad22001-02-06 21:42:48 +0000515 if (data) {
Brian Paul65d54602000-03-01 23:28:20 +0000516 static const char message[8][32] = {
jtgafb833d1999-08-19 00:55:39 +0000517 " X X XXXXX XXX X ",
518 " XX XX X X X X X ",
519 " X X X X X X X ",
520 " X X XXXX XXX XXXXX ",
521 " X X X X X X ",
522 " X X X X X X X ",
523 " X X XXXXX XXX X X ",
524 " "
525 };
526
Brian Paul8e39ad22001-02-06 21:42:48 +0000527 GLubyte *imgPtr = data;
528 GLint h, i, j, k;
529 for (h = 0; h < depth; h++) {
530 for (i = 0; i < height; i++) {
531 GLint srcRow = 7 - (i % 8);
532 for (j = 0; j < width; j++) {
533 GLint srcCol = j % 32;
534 GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
535 for (k = 0; k < components; k++) {
536 *imgPtr++ = texel;
537 }
jtgafb833d1999-08-19 00:55:39 +0000538 }
539 }
540 }
541 }
Brian Paul8e39ad22001-02-06 21:42:48 +0000542
543 return data;
jtgafb833d1999-08-19 00:55:39 +0000544}
545
546
547
548/*
Brian Paulf378ab82001-02-06 23:35:26 +0000549 * Reset the fields of a gl_texture_image struct to zero.
Brian Paul9c272782000-09-05 22:04:30 +0000550 * This is called when a proxy texture test fails, we set all the
551 * image members (except DriverData) to zero.
Brian Paulf378ab82001-02-06 23:35:26 +0000552 * It's also used in glTexImage[123]D as a safeguard to be sure all
553 * required fields get initialized properly by the Driver.TexImage[123]D
554 * functions.
Brian Paul9c272782000-09-05 22:04:30 +0000555 */
556static void
Brian Paulf378ab82001-02-06 23:35:26 +0000557clear_teximage_fields(struct gl_texture_image *img)
Brian Paul9c272782000-09-05 22:04:30 +0000558{
559 ASSERT(img);
560 img->Format = 0;
Brian Paulf7e1dfe2001-02-17 00:15:39 +0000561 img->Type = 0;
Brian Paul9c272782000-09-05 22:04:30 +0000562 img->IntFormat = 0;
563 img->RedBits = 0;
564 img->GreenBits = 0;
565 img->BlueBits = 0;
566 img->AlphaBits = 0;
567 img->IntensityBits = 0;
568 img->LuminanceBits = 0;
569 img->IndexBits = 0;
570 img->Border = 0;
571 img->Width = 0;
572 img->Height = 0;
573 img->Depth = 0;
574 img->Width2 = 0;
575 img->Height2 = 0;
576 img->Depth2 = 0;
577 img->WidthLog2 = 0;
578 img->HeightLog2 = 0;
579 img->DepthLog2 = 0;
580 img->Data = NULL;
581 img->IsCompressed = 0;
582 img->CompressedSize = 0;
Brian Paulf378ab82001-02-06 23:35:26 +0000583 img->FetchTexel = NULL;
Brian Paul9c272782000-09-05 22:04:30 +0000584}
585
586
Brian Paul6628bc92001-02-07 03:27:41 +0000587/*
588 * Initialize basic fields of the gl_texture_image struct.
589 */
590static void
591init_teximage_fields(GLcontext *ctx,
592 struct gl_texture_image *img,
593 GLsizei width, GLsizei height, GLsizei depth,
594 GLint border, GLenum internalFormat)
595{
596 ASSERT(img);
597
598 img->IntFormat = internalFormat;
599 img->Border = border;
600 img->Width = width;
601 img->Height = height;
602 img->Depth = depth;
603 img->WidthLog2 = logbase2(width - 2 * border);
604 if (height == 1) /* 1-D texture */
605 img->HeightLog2 = 0;
606 else
607 img->HeightLog2 = logbase2(height - 2 * border);
608 if (depth == 1) /* 2-D texture */
609 img->DepthLog2 = 0;
610 else
611 img->DepthLog2 = logbase2(depth - 2 * border);
612 img->Width2 = 1 << img->WidthLog2;
613 img->Height2 = 1 << img->HeightLog2;
614 img->Depth2 = 1 << img->DepthLog2;
615 img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
616 img->IsCompressed = is_compressed_format(ctx, internalFormat);
617}
618
619
Brian Paul9c272782000-09-05 22:04:30 +0000620
621/*
Brian Paulc3f0a511999-11-03 17:27:05 +0000622 * Test glTexImage[123]D() parameters for errors.
jtgafb833d1999-08-19 00:55:39 +0000623 * Input:
624 * dimensions - must be 1 or 2 or 3
625 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
626 */
Brian Paulc3f0a511999-11-03 17:27:05 +0000627static GLboolean
628texture_error_check( GLcontext *ctx, GLenum target,
629 GLint level, GLint internalFormat,
630 GLenum format, GLenum type,
Brian Paul5b37c321999-11-05 06:43:10 +0000631 GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +0000632 GLint width, GLint height,
633 GLint depth, GLint border )
jtgafb833d1999-08-19 00:55:39 +0000634{
635 GLboolean isProxy;
636 GLint iformat;
637
638 if (dimensions == 1) {
Brian Paul5b37c321999-11-05 06:43:10 +0000639 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D);
jtgafb833d1999-08-19 00:55:39 +0000640 if (target != GL_TEXTURE_1D && !isProxy) {
641 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
642 return GL_TRUE;
643 }
644 }
645 else if (dimensions == 2) {
Brian Paul8e39ad22001-02-06 21:42:48 +0000646 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D ||
647 target == GL_PROXY_TEXTURE_CUBE_MAP_ARB);
Brian Paul413d6a22000-05-26 14:44:59 +0000648 if (target != GL_TEXTURE_2D && !isProxy &&
Keith Whitwella96308c2000-10-30 13:31:59 +0000649 !(ctx->Extensions.ARB_texture_cube_map &&
Brian Paul413d6a22000-05-26 14:44:59 +0000650 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
651 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
jtgafb833d1999-08-19 00:55:39 +0000652 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
653 return GL_TRUE;
654 }
655 }
656 else if (dimensions == 3) {
Brian Paul5b37c321999-11-05 06:43:10 +0000657 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D);
jtgafb833d1999-08-19 00:55:39 +0000658 if (target != GL_TEXTURE_3D && !isProxy) {
659 gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
660 return GL_TRUE;
661 }
662 }
663 else {
664 gl_problem( ctx, "bad dims in texture_error_check" );
665 return GL_TRUE;
666 }
667
668 /* Border */
Brian Paul9fd2b0a2000-03-24 23:59:06 +0000669 if (border != 0 && border != 1) {
jtgafb833d1999-08-19 00:55:39 +0000670 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000671 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000672 sprintf(message, "glTexImage%dD(border=%d)", dimensions, border);
Brian Paulc3f0a511999-11-03 17:27:05 +0000673 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +0000674 }
675 return GL_TRUE;
676 }
677
678 /* Width */
679 if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
680 || logbase2( width - 2 * border ) < 0) {
681 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000682 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000683 sprintf(message, "glTexImage%dD(width=%d)", dimensions, width);
Brian Paulc3f0a511999-11-03 17:27:05 +0000684 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +0000685 }
686 return GL_TRUE;
687 }
688
689 /* Height */
690 if (dimensions >= 2) {
691 if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
692 || logbase2( height - 2 * border ) < 0) {
693 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000694 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000695 sprintf(message, "glTexImage%dD(height=%d)", dimensions, height);
Brian Paulc3f0a511999-11-03 17:27:05 +0000696 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +0000697 }
Brian Paulc3f0a511999-11-03 17:27:05 +0000698 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000699 }
700 }
701
Brian Paulad817702000-05-30 00:27:24 +0000702 /* For cube map, width must equal height */
703 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
704 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
705 if (width != height) {
706 if (!isProxy) {
707 gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)");
708 }
709 return GL_TRUE;
710 }
711 }
712
jtgafb833d1999-08-19 00:55:39 +0000713 /* Depth */
714 if (dimensions >= 3) {
715 if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize
716 || logbase2( depth - 2 * border ) < 0) {
717 if (!isProxy) {
Brian Paulec153982000-12-08 18:09:33 +0000718 char message[100];
719 sprintf(message, "glTexImage3D(depth=%d)", depth );
720 gl_error( ctx, GL_INVALID_VALUE, message );
jtgafb833d1999-08-19 00:55:39 +0000721 }
722 return GL_TRUE;
723 }
724 }
725
726 /* Level */
Brian Paul9fd2b0a2000-03-24 23:59:06 +0000727 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000728 if (!isProxy) {
729 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000730 sprintf(message, "glTexImage%dD(level=%d)", dimensions, level);
Brian Paulc3f0a511999-11-03 17:27:05 +0000731 gl_error(ctx, GL_INVALID_VALUE, message);
732 }
jtgafb833d1999-08-19 00:55:39 +0000733 return GL_TRUE;
734 }
735
Brian Paul1f575632001-02-26 18:24:55 +0000736 /* For cube map, width must equal height */
737 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
738 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
739 if (width != height) {
740 gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)");
741 return GL_TRUE;
742 }
743 }
744
Brian Paulaea66b12000-05-24 14:04:06 +0000745 iformat = _mesa_base_tex_format( ctx, internalFormat );
jtgafb833d1999-08-19 00:55:39 +0000746 if (iformat < 0) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000747 if (!isProxy) {
748 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000749 sprintf(message, "glTexImage%dD(internalFormat=0x%x)", dimensions,
750 internalFormat);
Brian Paulc3f0a511999-11-03 17:27:05 +0000751 gl_error(ctx, GL_INVALID_VALUE, message);
752 }
jtgafb833d1999-08-19 00:55:39 +0000753 return GL_TRUE;
754 }
755
Brian Paul289d47e2000-08-29 23:31:23 +0000756 if (!is_compressed_format(ctx, internalFormat)) {
Brian Paulaea66b12000-05-24 14:04:06 +0000757 if (!_mesa_is_legal_format_and_type( format, type )) {
758 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
759 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
760 */
761 if (!isProxy) {
762 char message[100];
763 sprintf(message, "glTexImage%dD(format or type)", dimensions);
764 gl_error(ctx, GL_INVALID_OPERATION, message);
765 }
766 return GL_TRUE;
Brian Paulc3f0a511999-11-03 17:27:05 +0000767 }
jtgafb833d1999-08-19 00:55:39 +0000768 }
769
770 /* if we get here, the parameters are OK */
771 return GL_FALSE;
772}
773
774
775
776/*
Brian Paulc3f0a511999-11-03 17:27:05 +0000777 * Test glTexSubImage[123]D() parameters for errors.
778 * Input:
779 * dimensions - must be 1 or 2 or 3
780 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
781 */
782static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +0000783subtexture_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +0000784 GLenum target, GLint level,
785 GLint xoffset, GLint yoffset, GLint zoffset,
786 GLint width, GLint height, GLint depth,
787 GLenum format, GLenum type )
788{
789 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
790 struct gl_texture_image *destTex;
791
792 if (dimensions == 1) {
793 if (target != GL_TEXTURE_1D) {
794 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" );
795 return GL_TRUE;
796 }
797 }
798 else if (dimensions == 2) {
Keith Whitwella96308c2000-10-30 13:31:59 +0000799 if (ctx->Extensions.ARB_texture_cube_map) {
Brian Paulfc4b4432000-05-23 15:17:12 +0000800 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
801 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
802 target != GL_TEXTURE_2D) {
803 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
804 return GL_TRUE;
805 }
806 }
807 else if (target != GL_TEXTURE_2D) {
Brian Paulc3f0a511999-11-03 17:27:05 +0000808 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
809 return GL_TRUE;
810 }
811 }
812 else if (dimensions == 3) {
813 if (target != GL_TEXTURE_3D) {
814 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" );
815 return GL_TRUE;
816 }
817 }
818 else {
819 gl_problem( ctx, "bad dims in texture_error_check" );
820 return GL_TRUE;
821 }
822
823 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
Brian Paulec153982000-12-08 18:09:33 +0000824 char message[100];
825 sprintf(message, "glTexSubImage2D(level=%d)", level);
826 gl_error(ctx, GL_INVALID_ENUM, message);
Brian Paulc3f0a511999-11-03 17:27:05 +0000827 return GL_TRUE;
828 }
829
830 if (width < 0) {
831 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000832 sprintf(message, "glTexSubImage%dD(width=%d)", dimensions, width);
Brian Paulc3f0a511999-11-03 17:27:05 +0000833 gl_error(ctx, GL_INVALID_VALUE, message);
834 return GL_TRUE;
835 }
836 if (height < 0 && dimensions > 1) {
837 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000838 sprintf(message, "glTexSubImage%dD(height=%d)", dimensions, height);
Brian Paulc3f0a511999-11-03 17:27:05 +0000839 gl_error(ctx, GL_INVALID_VALUE, message);
840 return GL_TRUE;
841 }
842 if (depth < 0 && dimensions > 2) {
843 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000844 sprintf(message, "glTexSubImage%dD(depth=%d)", dimensions, depth);
Brian Paulc3f0a511999-11-03 17:27:05 +0000845 gl_error(ctx, GL_INVALID_VALUE, message);
846 return GL_TRUE;
847 }
848
Brian Paulf2718b02001-01-23 23:35:23 +0000849 destTex = _mesa_select_tex_image(ctx, texUnit, target, level);
850
Brian Paulc3f0a511999-11-03 17:27:05 +0000851 if (!destTex) {
852 gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D");
853 return GL_TRUE;
854 }
855
856 if (xoffset < -((GLint)destTex->Border)) {
857 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)");
858 return GL_TRUE;
859 }
860 if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
861 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)");
862 return GL_TRUE;
863 }
864 if (dimensions > 1) {
865 if (yoffset < -((GLint)destTex->Border)) {
866 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)");
867 return GL_TRUE;
868 }
869 if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
870 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)");
871 return GL_TRUE;
872 }
873 }
874 if (dimensions > 2) {
875 if (zoffset < -((GLint)destTex->Border)) {
876 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
877 return GL_TRUE;
878 }
879 if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) {
880 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
881 return GL_TRUE;
882 }
883 }
884
Brian Paul289d47e2000-08-29 23:31:23 +0000885 if (!is_compressed_format(ctx, destTex->IntFormat)) {
Brian Paul9540a1d2000-06-06 17:03:38 +0000886 if (!_mesa_is_legal_format_and_type(format, type)) {
887 char message[100];
888 sprintf(message, "glTexSubImage%dD(format or type)", dimensions);
889 gl_error(ctx, GL_INVALID_ENUM, message);
890 return GL_TRUE;
891 }
Brian Paulc3f0a511999-11-03 17:27:05 +0000892 }
893
894 return GL_FALSE;
895}
896
897
898/*
899 * Test glCopyTexImage[12]D() parameters for errors.
900 * Input: dimensions - must be 1 or 2 or 3
901 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
902 */
903static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +0000904copytexture_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +0000905 GLenum target, GLint level, GLint internalFormat,
906 GLint width, GLint height, GLint border )
907{
908 GLint iformat;
909
Brian Paulfc4b4432000-05-23 15:17:12 +0000910 if (dimensions == 1) {
911 if (target != GL_TEXTURE_1D) {
912 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" );
913 return GL_TRUE;
914 }
Brian Paulc3f0a511999-11-03 17:27:05 +0000915 }
Brian Paulfc4b4432000-05-23 15:17:12 +0000916 else if (dimensions == 2) {
Keith Whitwella96308c2000-10-30 13:31:59 +0000917 if (ctx->Extensions.ARB_texture_cube_map) {
Brian Paulfc4b4432000-05-23 15:17:12 +0000918 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
919 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
920 target != GL_TEXTURE_2D) {
921 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
922 return GL_TRUE;
923 }
924 }
925 else if (target != GL_TEXTURE_2D) {
926 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
927 return GL_TRUE;
928 }
Brian Paulc3f0a511999-11-03 17:27:05 +0000929 }
930
931 /* Border */
932 if (border!=0 && border!=1) {
933 char message[100];
934 sprintf(message, "glCopyTexImage%dD(border)", dimensions);
935 gl_error(ctx, GL_INVALID_VALUE, message);
936 return GL_TRUE;
937 }
938
939 /* Width */
940 if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
941 || logbase2( width - 2 * border ) < 0) {
942 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000943 sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width);
Brian Paulc3f0a511999-11-03 17:27:05 +0000944 gl_error(ctx, GL_INVALID_VALUE, message);
945 return GL_TRUE;
946 }
947
948 /* Height */
949 if (dimensions >= 2) {
950 if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
951 || logbase2( height - 2 * border ) < 0) {
952 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000953 sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height);
Brian Paulc3f0a511999-11-03 17:27:05 +0000954 gl_error(ctx, GL_INVALID_VALUE, message);
955 return GL_TRUE;
956 }
957 }
958
Brian Paulad817702000-05-30 00:27:24 +0000959 /* For cube map, width must equal height */
960 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
961 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
962 if (width != height) {
963 gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)");
964 return GL_TRUE;
965 }
966 }
967
Brian Paulc3f0a511999-11-03 17:27:05 +0000968 /* Level */
969 if (level<0 || level>=ctx->Const.MaxTextureLevels) {
970 char message[100];
Brian Paulec153982000-12-08 18:09:33 +0000971 sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level);
Brian Paulc3f0a511999-11-03 17:27:05 +0000972 gl_error(ctx, GL_INVALID_VALUE, message);
973 return GL_TRUE;
974 }
975
Brian Paulaea66b12000-05-24 14:04:06 +0000976 iformat = _mesa_base_tex_format( ctx, internalFormat );
Brian Paulc3f0a511999-11-03 17:27:05 +0000977 if (iformat < 0) {
978 char message[100];
979 sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions);
980 gl_error(ctx, GL_INVALID_VALUE, message);
981 return GL_TRUE;
982 }
983
984 /* if we get here, the parameters are OK */
985 return GL_FALSE;
986}
987
988
989static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +0000990copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +0000991 GLenum target, GLint level,
992 GLint xoffset, GLint yoffset, GLint zoffset,
Brian Paul5b37c321999-11-05 06:43:10 +0000993 GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +0000994{
995 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
996 struct gl_texture_image *teximage;
997
Brian Paulfc4b4432000-05-23 15:17:12 +0000998 if (dimensions == 1) {
999 if (target != GL_TEXTURE_1D) {
1000 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
1001 return GL_TRUE;
1002 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001003 }
Brian Paulfc4b4432000-05-23 15:17:12 +00001004 else if (dimensions == 2) {
Keith Whitwella96308c2000-10-30 13:31:59 +00001005 if (ctx->Extensions.ARB_texture_cube_map) {
Brian Paulfc4b4432000-05-23 15:17:12 +00001006 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
1007 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
1008 target != GL_TEXTURE_2D) {
1009 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1010 return GL_TRUE;
1011 }
1012 }
1013 else if (target != GL_TEXTURE_2D) {
1014 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1015 return GL_TRUE;
1016 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001017 }
Brian Paulfc4b4432000-05-23 15:17:12 +00001018 else if (dimensions == 3) {
1019 if (target != GL_TEXTURE_3D) {
1020 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" );
1021 return GL_TRUE;
1022 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001023 }
1024
1025 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
1026 char message[100];
Brian Paulec153982000-12-08 18:09:33 +00001027 sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level);
Brian Paulc3f0a511999-11-03 17:27:05 +00001028 gl_error(ctx, GL_INVALID_VALUE, message);
1029 return GL_TRUE;
1030 }
1031
1032 if (width < 0) {
1033 char message[100];
Brian Paulec153982000-12-08 18:09:33 +00001034 sprintf(message, "glCopyTexSubImage%dD(width=%d)", dimensions, width);
Brian Paulc3f0a511999-11-03 17:27:05 +00001035 gl_error(ctx, GL_INVALID_VALUE, message);
1036 return GL_TRUE;
1037 }
1038 if (dimensions > 1 && height < 0) {
1039 char message[100];
Brian Paulec153982000-12-08 18:09:33 +00001040 sprintf(message, "glCopyTexSubImage%dD(height=%d)", dimensions, height);
Brian Paulc3f0a511999-11-03 17:27:05 +00001041 gl_error(ctx, GL_INVALID_VALUE, message);
1042 return GL_TRUE;
1043 }
1044
Brian Paula8523782000-11-19 23:10:25 +00001045 teximage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulc3f0a511999-11-03 17:27:05 +00001046 if (!teximage) {
1047 char message[100];
1048 sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions);
1049 gl_error(ctx, GL_INVALID_OPERATION, message);
1050 return GL_TRUE;
1051 }
1052
1053 if (xoffset < -((GLint)teximage->Border)) {
1054 char message[100];
Brian Paulec153982000-12-08 18:09:33 +00001055 sprintf(message, "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
Brian Paulc3f0a511999-11-03 17:27:05 +00001056 gl_error(ctx, GL_INVALID_VALUE, message);
1057 return GL_TRUE;
1058 }
1059 if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) {
1060 char message[100];
1061 sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions);
1062 gl_error(ctx, GL_INVALID_VALUE, message);
1063 return GL_TRUE;
1064 }
1065 if (dimensions > 1) {
1066 if (yoffset < -((GLint)teximage->Border)) {
1067 char message[100];
Brian Paulec153982000-12-08 18:09:33 +00001068 sprintf(message, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset);
Brian Paulc3f0a511999-11-03 17:27:05 +00001069 gl_error(ctx, GL_INVALID_VALUE, message);
1070 return GL_TRUE;
1071 }
1072 /* NOTE: we're adding the border here, not subtracting! */
1073 if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) {
1074 char message[100];
1075 sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions);
1076 gl_error(ctx, GL_INVALID_VALUE, message);
1077 return GL_TRUE;
1078 }
1079 }
1080
1081 if (dimensions > 2) {
1082 if (zoffset < -((GLint)teximage->Border)) {
1083 char message[100];
1084 sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions);
1085 gl_error(ctx, GL_INVALID_VALUE, message);
1086 return GL_TRUE;
1087 }
1088 if (zoffset > (GLint) (teximage->Depth+teximage->Border)) {
1089 char message[100];
1090 sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
1091 gl_error(ctx, GL_INVALID_VALUE, message);
1092 return GL_TRUE;
1093 }
1094 }
1095
1096 /* if we get here, the parameters are OK */
1097 return GL_FALSE;
1098}
1099
1100
1101
Brian Paulfbd8f211999-11-11 01:22:25 +00001102void
1103_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
1104 GLenum type, GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001105{
Brian Paulfbd8f211999-11-11 01:22:25 +00001106 GET_CURRENT_CONTEXT(ctx);
Brian Paul01e54752000-09-05 15:40:34 +00001107 const struct gl_texture_unit *texUnit;
jtgafb833d1999-08-19 00:55:39 +00001108 const struct gl_texture_object *texObj;
Brian Paulf7b57072000-03-20 14:37:52 +00001109 struct gl_texture_image *texImage;
jtgafb833d1999-08-19 00:55:39 +00001110
Keith Whitwellcab974c2000-12-26 05:09:27 +00001111 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001112
1113 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
1114 gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
1115 return;
1116 }
1117
Brian Paulb7d076f2000-03-21 01:03:40 +00001118 if (_mesa_sizeof_type(type) <= 0) {
jtgafb833d1999-08-19 00:55:39 +00001119 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
1120 return;
1121 }
1122
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001123 if (_mesa_components_in_format(format) <= 0 ||
1124 format == GL_STENCIL_INDEX) {
jtgafb833d1999-08-19 00:55:39 +00001125 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
1126 return;
1127 }
1128
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001129 if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) {
1130 gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
1131 }
1132
1133 if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) {
1134 gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
1135 }
1136
1137 /* XXX what if format/type doesn't match texture format/type? */
1138
jtgafb833d1999-08-19 00:55:39 +00001139 if (!pixels)
Brian Paulf7b57072000-03-20 14:37:52 +00001140 return;
jtgafb833d1999-08-19 00:55:39 +00001141
Brian Paul01e54752000-09-05 15:40:34 +00001142 texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
1143 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul8e39ad22001-02-06 21:42:48 +00001144 if (!texObj || is_proxy_target(target)) {
Brian Paul01e54752000-09-05 15:40:34 +00001145 gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
1146 return;
jtgafb833d1999-08-19 00:55:39 +00001147 }
1148
Brian Paul8e3366f2000-11-10 15:32:07 +00001149 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulf7b57072000-03-20 14:37:52 +00001150 if (!texImage) {
Brian Paul7298e712000-11-07 16:40:37 +00001151 /* invalid mipmap level, not an error */
Brian Paulf7b57072000-03-20 14:37:52 +00001152 return;
1153 }
1154
1155 if (!texImage->Data) {
Brian Paul8e39ad22001-02-06 21:42:48 +00001156 /* no image data, not an error */
1157 return;
Brian Paulf7b57072000-03-20 14:37:52 +00001158 }
1159
Brian Paul8e39ad22001-02-06 21:42:48 +00001160 if (ctx->NewState & _NEW_PIXEL)
1161 gl_update_state(ctx);
1162
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001163 if (is_color_format(format) &&
1164 ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
Brian Paul8e39ad22001-02-06 21:42:48 +00001165 /* convert texture image to GL_RGBA, GL_FLOAT */
jtgafb833d1999-08-19 00:55:39 +00001166 GLint width = texImage->Width;
1167 GLint height = texImage->Height;
Brian Paulf96ce6a2000-09-06 15:15:43 +00001168 GLint depth = texImage->Depth;
1169 GLint img, row;
Brian Paul8e39ad22001-02-06 21:42:48 +00001170 GLfloat *tmpImage, *convImage;
1171 tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
1172 if (!tmpImage) {
1173 gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
1174 return;
1175 }
1176 convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
1177 if (!convImage) {
1178 FREE(tmpImage);
1179 gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
1180 return;
1181 }
1182
1183 for (img = 0; img < depth; img++) {
1184 GLint convWidth, convHeight;
1185
1186 /* convert texture data to GLfloat/GL_RGBA */
1187 for (row = 0; row < height; row++) {
1188 GLchan texels[1 << MAX_TEXTURE_LEVELS][4];
1189 GLint col;
1190 GLfloat *dst = tmpImage + row * width * 4;
1191 for (col = 0; col < width; col++) {
Brian Paule75d2422001-02-17 18:41:01 +00001192 (*texImage->FetchTexel)(texImage, col, row, img,
Brian Paul8e39ad22001-02-06 21:42:48 +00001193 texels[col]);
1194 }
1195 _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst,
1196 GL_RGBA, CHAN_TYPE, texels,
1197 &_mesa_native_packing,
1198 ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
1199 GL_FALSE);
1200 }
1201
1202 convWidth = width;
1203 convHeight = height;
1204
1205 /* convolve */
1206 if (target == GL_TEXTURE_1D) {
1207 if (ctx->Pixel.Convolution1DEnabled) {
1208 _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
1209 }
1210 }
1211 else {
1212 if (ctx->Pixel.Convolution2DEnabled) {
1213 _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
1214 tmpImage, convImage);
1215 }
1216 else if (ctx->Pixel.Separable2DEnabled) {
1217 _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
1218 tmpImage, convImage);
1219 }
1220 }
1221
1222 /* pack convolved image */
1223 for (row = 0; row < convHeight; row++) {
1224 const GLfloat *src = convImage + row * convWidth * 4;
1225 GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels,
1226 convWidth, convHeight,
1227 format, type, img, row, 0);
1228 _mesa_pack_float_rgba_span(ctx, convWidth,
1229 (const GLfloat(*)[4]) src,
1230 format, type, dest, &ctx->Pack,
1231 ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS);
1232 }
1233 }
1234
1235 FREE(tmpImage);
1236 FREE(convImage);
1237 }
1238 else {
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001239 /* no convolution, or non-rgba image */
Brian Paul8e39ad22001-02-06 21:42:48 +00001240 GLint width = texImage->Width;
1241 GLint height = texImage->Height;
1242 GLint depth = texImage->Depth;
1243 GLint img, row;
1244 for (img = 0; img < depth; img++) {
1245 for (row = 0; row < height; row++) {
1246 /* compute destination address in client memory */
1247 GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels,
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001248 width, height, format, type,
1249 img, row, 0);
Brian Paul8e39ad22001-02-06 21:42:48 +00001250 assert(dest);
1251
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001252 if (format == GL_COLOR_INDEX) {
1253 GLuint indexRow[MAX_WIDTH];
1254 GLint col;
1255 for (col = 0; col < width; col++) {
Brian Paule75d2422001-02-17 18:41:01 +00001256 (*texImage->FetchTexel)(texImage, col, row, img,
1257 (GLvoid *) &indexRow[col]);
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001258 }
1259 _mesa_pack_index_span(ctx, width, type, dest,
1260 indexRow, &ctx->Pack,
1261 ctx->_ImageTransferState);
1262 }
1263 else if (format == GL_DEPTH_COMPONENT) {
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001264 GLfloat depthRow[MAX_WIDTH];
1265 GLint col;
1266 for (col = 0; col < width; col++) {
Brian Paule75d2422001-02-17 18:41:01 +00001267 (*texImage->FetchTexel)(texImage, col, row, img,
1268 (GLvoid *) &depthRow[col]);
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001269 }
1270 _mesa_pack_depth_span(ctx, width, dest, type,
1271 depthRow, &ctx->Pack);
1272 }
1273 else {
Brian Paul8e39ad22001-02-06 21:42:48 +00001274 /* general case: convert row to RGBA format */
1275 GLchan rgba[MAX_WIDTH][4];
1276 GLint col;
1277 for (col = 0; col < width; col++) {
Brian Paule75d2422001-02-17 18:41:01 +00001278 (*texImage->FetchTexel)(texImage, col, row, img,
1279 (GLvoid *) rgba[col]);
Brian Paul8e39ad22001-02-06 21:42:48 +00001280 }
Brian Paule75d2422001-02-17 18:41:01 +00001281 _mesa_pack_rgba_span(ctx, width, (const GLchan (*)[4])rgba,
1282 format, type, dest, &ctx->Pack,
1283 ctx->_ImageTransferState);
Brian Paul8e39ad22001-02-06 21:42:48 +00001284 } /* format */
1285 } /* row */
1286 } /* img */
1287 } /* convolution */
1288}
1289
1290
1291
1292/*
1293 * Called from the API. Note that width includes the border.
1294 */
1295void
1296_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
1297 GLsizei width, GLint border, GLenum format,
1298 GLenum type, const GLvoid *pixels )
1299{
1300 GLsizei postConvWidth = width;
1301 GET_CURRENT_CONTEXT(ctx);
1302 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1303
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001304 if (is_color_format(internalFormat)) {
1305 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
1306 }
Brian Paul8e39ad22001-02-06 21:42:48 +00001307
1308 if (target == GL_TEXTURE_1D) {
1309 struct gl_texture_unit *texUnit;
1310 struct gl_texture_object *texObj;
1311 struct gl_texture_image *texImage;
1312
1313 if (texture_error_check(ctx, target, level, internalFormat,
1314 format, type, 1, postConvWidth, 1, 1, border)) {
1315 return; /* error was recorded */
1316 }
1317
1318 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1319 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1320 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1321
1322 if (!texImage) {
1323 texImage = _mesa_alloc_texture_image();
1324 texObj->Image[level] = texImage;
1325 if (!texImage) {
1326 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
1327 return;
1328 }
1329 }
1330 else if (texImage->Data) {
1331 /* free the old texture data */
1332 FREE(texImage->Data);
1333 texImage->Data = NULL;
1334 }
Brian Paulf378ab82001-02-06 23:35:26 +00001335 clear_teximage_fields(texImage); /* not really needed, but helpful */
Brian Paul6628bc92001-02-07 03:27:41 +00001336 init_teximage_fields(ctx, texImage, postConvWidth, 1, 1,
1337 border, internalFormat);
jtgafb833d1999-08-19 00:55:39 +00001338
Brian Paul9499e012000-10-30 16:32:42 +00001339 if (ctx->NewState & _NEW_PIXEL)
1340 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001341
Brian Paul8e39ad22001-02-06 21:42:48 +00001342 ASSERT(ctx->Driver.TexImage1D);
1343 if (pixels) {
1344 (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
1345 width, border, format, type, pixels,
1346 &ctx->Unpack, texObj, texImage);
jtgafb833d1999-08-19 00:55:39 +00001347 }
Brian Paulf96ce6a2000-09-06 15:15:43 +00001348 else {
Brian Paul8e39ad22001-02-06 21:42:48 +00001349 GLubyte *dummy = make_null_texture(width, 1, 1, format);
1350 if (dummy) {
1351 (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
1352 width, border,
1353 format, GL_UNSIGNED_BYTE, dummy,
1354 &_mesa_native_packing, texObj, texImage);
1355 FREE(dummy);
1356 }
1357 }
Brian Paulf7b57072000-03-20 14:37:52 +00001358
Brian Paulf378ab82001-02-06 23:35:26 +00001359 /* one of these has to be non-zero! */
1360 ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits ||
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001361 texImage->LuminanceBits || texImage->IntensityBits ||
1362 texImage->DepthBits);
Brian Paulf378ab82001-02-06 23:35:26 +00001363 ASSERT(texImage->FetchTexel);
1364
Brian Paul8e39ad22001-02-06 21:42:48 +00001365 /* state update */
1366 texObj->Complete = GL_FALSE;
1367 ctx->NewState |= _NEW_TEXTURE;
1368 }
1369 else if (target == GL_PROXY_TEXTURE_1D) {
1370 /* Proxy texture: check for errors and update proxy state */
1371 GLenum error = texture_error_check(ctx, target, level, internalFormat,
1372 format, type, 1,
1373 postConvWidth, 1, 1, border);
1374 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00001375 struct gl_texture_unit *texUnit;
1376 struct gl_texture_image *texImage;
1377 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1378 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1379 init_teximage_fields(ctx, texImage, postConvWidth, 1, 1,
1380 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00001381 ASSERT(ctx->Driver.TestProxyTexImage);
1382 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
1383 internalFormat, format, type,
1384 postConvWidth, 1, 1, border);
1385 }
1386 if (error) {
1387 /* if error, clear all proxy texture image parameters */
1388 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
Brian Paulf378ab82001-02-06 23:35:26 +00001389 clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]);
Brian Paul8e39ad22001-02-06 21:42:48 +00001390 }
1391 }
1392 }
1393 else {
1394 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
1395 return;
1396 }
1397}
1398
1399
1400void
1401_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
1402 GLsizei width, GLsizei height, GLint border,
1403 GLenum format, GLenum type,
1404 const GLvoid *pixels )
1405{
1406 GLsizei postConvWidth = width, postConvHeight = height;
1407 GET_CURRENT_CONTEXT(ctx);
1408 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1409
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001410 if (is_color_format(internalFormat)) {
1411 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
1412 &postConvHeight);
1413 }
Brian Paul8e39ad22001-02-06 21:42:48 +00001414
1415 if (target == GL_TEXTURE_2D ||
1416 (ctx->Extensions.ARB_texture_cube_map &&
1417 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1418 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
1419 /* non-proxy target */
1420 struct gl_texture_unit *texUnit;
1421 struct gl_texture_object *texObj;
1422 struct gl_texture_image *texImage;
1423
1424 if (texture_error_check(ctx, target, level, internalFormat,
1425 format, type, 2, postConvWidth, postConvHeight,
1426 1, border)) {
1427 return; /* error was recorded */
1428 }
1429
1430 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1431 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1432 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1433
1434 if (!texImage) {
1435 texImage = _mesa_alloc_texture_image();
1436 set_tex_image(texObj, target, level, texImage);
1437 if (!texImage) {
1438 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1439 return;
1440 }
1441 }
1442 else if (texImage->Data) {
1443 /* free the old texture data */
Brian Paulf7b57072000-03-20 14:37:52 +00001444 FREE(texImage->Data);
1445 texImage->Data = NULL;
1446 }
Brian Paulf378ab82001-02-06 23:35:26 +00001447 clear_teximage_fields(texImage); /* not really needed, but helpful */
Brian Paul6628bc92001-02-07 03:27:41 +00001448 init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1,
1449 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00001450
1451 if (ctx->NewState & _NEW_PIXEL)
1452 gl_update_state(ctx);
1453
1454 ASSERT(ctx->Driver.TexImage2D);
1455 if (pixels) {
1456 (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
1457 width, height, border, format, type, pixels,
1458 &ctx->Unpack, texObj, texImage);
1459 }
1460 else {
1461 GLubyte *dummy = make_null_texture(width, height, 1, format);
1462 if (dummy) {
1463 (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
1464 width, height, border,
1465 format, GL_UNSIGNED_BYTE, dummy,
1466 &_mesa_native_packing, texObj, texImage);
1467 FREE(dummy);
1468 }
1469 }
1470
Brian Paulf378ab82001-02-06 23:35:26 +00001471 /* one of these has to be non-zero! */
1472 ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits ||
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001473 texImage->LuminanceBits || texImage->IntensityBits ||
1474 texImage->DepthBits);
Brian Paulf378ab82001-02-06 23:35:26 +00001475 ASSERT(texImage->FetchTexel);
1476
Brian Paul8e39ad22001-02-06 21:42:48 +00001477 /* state update */
1478 texObj->Complete = GL_FALSE;
1479 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +00001480 }
Brian Paul8e39ad22001-02-06 21:42:48 +00001481 else if (target == GL_PROXY_TEXTURE_2D) {
1482 /* Proxy texture: check for errors and update proxy state */
1483 GLenum error = texture_error_check(ctx, target, level, internalFormat,
1484 format, type, 2,
1485 postConvWidth, postConvHeight, 1, border);
1486 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00001487 struct gl_texture_unit *texUnit;
1488 struct gl_texture_image *texImage;
1489 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1490 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1491 init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1,
1492 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00001493 ASSERT(ctx->Driver.TestProxyTexImage);
1494 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
1495 internalFormat, format, type,
1496 postConvWidth, postConvHeight, 1, border);
1497 }
1498 if (error) {
1499 /* if error, clear all proxy texture image parameters */
1500 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
Brian Paulf378ab82001-02-06 23:35:26 +00001501 clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]);
Brian Paul8e39ad22001-02-06 21:42:48 +00001502 }
1503 }
1504 }
1505 else {
1506 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
1507 return;
1508 }
1509}
1510
1511
1512/*
1513 * Called by the API or display list executor.
1514 * Note that width and height include the border.
1515 */
1516void
1517_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
1518 GLsizei width, GLsizei height, GLsizei depth,
1519 GLint border, GLenum format, GLenum type,
1520 const GLvoid *pixels )
1521{
1522 GET_CURRENT_CONTEXT(ctx);
1523 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1524
1525 if (target == GL_TEXTURE_3D) {
1526 struct gl_texture_unit *texUnit;
1527 struct gl_texture_object *texObj;
1528 struct gl_texture_image *texImage;
1529
1530 if (texture_error_check(ctx, target, level, internalFormat,
1531 format, type, 3, width, height, depth, border)) {
1532 return; /* error was recorded */
1533 }
1534
1535 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1536 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1537 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1538
1539 if (!texImage) {
1540 texImage = _mesa_alloc_texture_image();
1541 texObj->Image[level] = texImage;
1542 if (!texImage) {
1543 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
1544 return;
1545 }
1546 }
1547 else if (texImage->Data) {
1548 FREE(texImage->Data);
1549 texImage->Data = NULL;
1550 }
Brian Paulf378ab82001-02-06 23:35:26 +00001551 clear_teximage_fields(texImage); /* not really needed, but helpful */
Brian Paul6628bc92001-02-07 03:27:41 +00001552 init_teximage_fields(ctx, texImage, width, height, depth, border,
1553 internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00001554
1555 if (ctx->NewState & _NEW_PIXEL)
1556 gl_update_state(ctx);
1557
1558 ASSERT(ctx->Driver.TexImage3D);
1559 if (pixels) {
1560 (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat,
1561 width, height, depth, border,
1562 format, type, pixels,
1563 &ctx->Unpack, texObj, texImage);
1564 }
1565 else {
1566 GLubyte *dummy = make_null_texture(width, height, depth, format);
1567 if (dummy) {
1568 (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat,
1569 width, height, depth, border,
1570 format, GL_UNSIGNED_BYTE, dummy,
1571 &_mesa_native_packing, texObj, texImage);
1572 FREE(dummy);
1573 }
1574 }
1575
Brian Paulf378ab82001-02-06 23:35:26 +00001576 /* one of these has to be non-zero! */
1577 ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits ||
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001578 texImage->LuminanceBits || texImage->IntensityBits ||
1579 texImage->DepthBits);
Brian Paulf378ab82001-02-06 23:35:26 +00001580 ASSERT(texImage->FetchTexel);
1581
Brian Paul8e39ad22001-02-06 21:42:48 +00001582 /* state update */
1583 texObj->Complete = GL_FALSE;
1584 ctx->NewState |= _NEW_TEXTURE;
1585 }
1586 else if (target == GL_PROXY_TEXTURE_3D) {
1587 /* Proxy texture: check for errors and update proxy state */
1588 GLenum error = texture_error_check(ctx, target, level, internalFormat,
1589 format, type, 3, width, height, depth, border);
1590 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00001591 struct gl_texture_unit *texUnit;
1592 struct gl_texture_image *texImage;
1593 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1594 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1595 init_teximage_fields(ctx, texImage, width, height, 1,
1596 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00001597 ASSERT(ctx->Driver.TestProxyTexImage);
1598 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
1599 internalFormat, format, type,
1600 width, height, depth, border);
1601 }
1602 if (error) {
1603 /* if error, clear all proxy texture image parameters */
Brian Paulf378ab82001-02-06 23:35:26 +00001604 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
1605 clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]);
Brian Paul8e39ad22001-02-06 21:42:48 +00001606 }
1607 }
1608 }
1609 else {
1610 gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
1611 return;
1612 }
1613}
1614
1615
1616void
1617_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
1618 GLsizei width, GLsizei height, GLsizei depth,
1619 GLint border, GLenum format, GLenum type,
1620 const GLvoid *pixels )
1621{
1622 _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
1623 depth, border, format, type, pixels);
jtgafb833d1999-08-19 00:55:39 +00001624}
1625
1626
1627
Brian Paulfbd8f211999-11-11 01:22:25 +00001628void
1629_mesa_TexSubImage1D( GLenum target, GLint level,
1630 GLint xoffset, GLsizei width,
1631 GLenum format, GLenum type,
1632 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001633{
Brian Paulab6e78f2000-12-09 21:30:43 +00001634 GLsizei postConvWidth = width;
Brian Paulfbd8f211999-11-11 01:22:25 +00001635 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00001636 struct gl_texture_unit *texUnit;
1637 struct gl_texture_object *texObj;
1638 struct gl_texture_image *texImage;
Brian Paula805bb92000-09-02 17:52:21 +00001639
Brian Paul2aadbf42001-02-19 20:01:41 +00001640 if (ctx->NewState & _NEW_PIXEL)
1641 gl_update_state(ctx);
1642
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001643 /* XXX should test internal format */
1644 if (is_color_format(format)) {
1645 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
1646 }
jtgafb833d1999-08-19 00:55:39 +00001647
Brian Paulc3f0a511999-11-03 17:27:05 +00001648 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
Brian Paula805bb92000-09-02 17:52:21 +00001649 postConvWidth, 1, 1, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001650 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00001651 }
1652
Brian Paul02938782000-03-22 17:38:11 +00001653 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul8e39ad22001-02-06 21:42:48 +00001654 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1655 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul02938782000-03-22 17:38:11 +00001656 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00001657
Brian Paulc3f0a511999-11-03 17:27:05 +00001658 if (width == 0 || !pixels)
1659 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00001660
Brian Paul8e39ad22001-02-06 21:42:48 +00001661 ASSERT(ctx->Driver.TexSubImage1D);
1662 (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
1663 format, type, pixels, &ctx->Unpack,
1664 texObj, texImage);
jtgafb833d1999-08-19 00:55:39 +00001665}
1666
1667
Brian Paulfbd8f211999-11-11 01:22:25 +00001668void
1669_mesa_TexSubImage2D( GLenum target, GLint level,
1670 GLint xoffset, GLint yoffset,
1671 GLsizei width, GLsizei height,
1672 GLenum format, GLenum type,
1673 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001674{
Brian Paulab6e78f2000-12-09 21:30:43 +00001675 GLsizei postConvWidth = width, postConvHeight = height;
Brian Paulfbd8f211999-11-11 01:22:25 +00001676 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00001677 struct gl_texture_unit *texUnit;
1678 struct gl_texture_object *texObj;
1679 struct gl_texture_image *texImage;
Brian Paula805bb92000-09-02 17:52:21 +00001680
Brian Paul2aadbf42001-02-19 20:01:41 +00001681 if (ctx->NewState & _NEW_PIXEL)
1682 gl_update_state(ctx);
1683
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001684 /* XXX should test internal format */
1685 if (is_color_format(format)) {
1686 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
1687 &postConvHeight);
1688 }
jtgafb833d1999-08-19 00:55:39 +00001689
Brian Paulc3f0a511999-11-03 17:27:05 +00001690 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
Brian Paula805bb92000-09-02 17:52:21 +00001691 postConvWidth, postConvHeight, 1, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001692 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00001693 }
1694
Brian Paul02938782000-03-22 17:38:11 +00001695 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul35d53012000-05-23 17:14:49 +00001696 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul8e39ad22001-02-06 21:42:48 +00001697 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul02938782000-03-22 17:38:11 +00001698 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00001699
Brian Paulc3f0a511999-11-03 17:27:05 +00001700 if (width == 0 || height == 0 || !pixels)
1701 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00001702
Brian Paul8e39ad22001-02-06 21:42:48 +00001703 ASSERT(ctx->Driver.TexSubImage2D);
1704 (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset,
1705 width, height, format, type, pixels,
1706 &ctx->Unpack, texObj, texImage);
jtgafb833d1999-08-19 00:55:39 +00001707}
1708
1709
1710
Brian Paulfbd8f211999-11-11 01:22:25 +00001711void
1712_mesa_TexSubImage3D( GLenum target, GLint level,
1713 GLint xoffset, GLint yoffset, GLint zoffset,
1714 GLsizei width, GLsizei height, GLsizei depth,
1715 GLenum format, GLenum type,
1716 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001717{
Brian Paulfbd8f211999-11-11 01:22:25 +00001718 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00001719 struct gl_texture_unit *texUnit;
1720 struct gl_texture_object *texObj;
1721 struct gl_texture_image *texImage;
jtgafb833d1999-08-19 00:55:39 +00001722
Brian Paul2aadbf42001-02-19 20:01:41 +00001723 if (ctx->NewState & _NEW_PIXEL)
1724 gl_update_state(ctx);
1725
Brian Paulc3f0a511999-11-03 17:27:05 +00001726 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
1727 width, height, depth, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001728 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00001729 }
1730
Brian Paul02938782000-03-22 17:38:11 +00001731 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul8e39ad22001-02-06 21:42:48 +00001732 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1733 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul02938782000-03-22 17:38:11 +00001734 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00001735
Brian Paulc3f0a511999-11-03 17:27:05 +00001736 if (width == 0 || height == 0 || height == 0 || !pixels)
1737 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00001738
Brian Paul8e39ad22001-02-06 21:42:48 +00001739 ASSERT(ctx->Driver.TexSubImage3D);
1740 (*ctx->Driver.TexSubImage3D)(ctx, target, level,
1741 xoffset, yoffset, zoffset,
1742 width, height, depth,
1743 format, type, pixels,
1744 &ctx->Unpack, texObj, texImage );
jtgafb833d1999-08-19 00:55:39 +00001745}
1746
1747
1748
Brian Paulfbd8f211999-11-11 01:22:25 +00001749void
1750_mesa_CopyTexImage1D( GLenum target, GLint level,
1751 GLenum internalFormat,
1752 GLint x, GLint y,
1753 GLsizei width, GLint border )
jtgafb833d1999-08-19 00:55:39 +00001754{
Brian Paul2aadbf42001-02-19 20:01:41 +00001755 struct gl_texture_unit *texUnit;
1756 struct gl_texture_object *texObj;
1757 struct gl_texture_image *texImage;
Brian Paulab6e78f2000-12-09 21:30:43 +00001758 GLsizei postConvWidth = width;
Brian Paulfbd8f211999-11-11 01:22:25 +00001759 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001760 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001761
Brian Paul9499e012000-10-30 16:32:42 +00001762 if (ctx->NewState & _NEW_PIXEL)
1763 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001764
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001765 if (is_color_format(internalFormat)) {
1766 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
1767 }
Brian Paulab6e78f2000-12-09 21:30:43 +00001768
1769 if (copytexture_error_check(ctx, 1, target, level, internalFormat,
1770 postConvWidth, 1, border))
1771 return;
1772
Brian Paul2aadbf42001-02-19 20:01:41 +00001773 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1774 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1775 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1776 if (!texImage) {
1777 texImage = _mesa_alloc_texture_image();
1778 set_tex_image(texObj, target, level, texImage);
1779 if (!texImage) {
1780 gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
Brian Paulc3f0a511999-11-03 17:27:05 +00001781 return;
1782 }
jtgafb833d1999-08-19 00:55:39 +00001783 }
Brian Paul2aadbf42001-02-19 20:01:41 +00001784 else if (texImage->Data) {
1785 /* free the old texture data */
1786 FREE(texImage->Data);
1787 texImage->Data = NULL;
1788 }
1789
1790 clear_teximage_fields(texImage); /* not really needed, but helpful */
1791 init_teximage_fields(ctx, texImage, postConvWidth, 1, 1,
1792 border, internalFormat);
1793
1794
1795 ASSERT(ctx->Driver.CopyTexImage1D);
1796 (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat,
1797 x, y, width, border);
1798
1799 /* state update */
1800 texObj->Complete = GL_FALSE;
1801 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +00001802}
1803
1804
1805
Brian Paulfbd8f211999-11-11 01:22:25 +00001806void
1807_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
1808 GLint x, GLint y, GLsizei width, GLsizei height,
1809 GLint border )
jtgafb833d1999-08-19 00:55:39 +00001810{
Brian Paul2aadbf42001-02-19 20:01:41 +00001811 struct gl_texture_unit *texUnit;
1812 struct gl_texture_object *texObj;
1813 struct gl_texture_image *texImage;
Brian Paulab6e78f2000-12-09 21:30:43 +00001814 GLsizei postConvWidth = width, postConvHeight = height;
Brian Paulfbd8f211999-11-11 01:22:25 +00001815 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001816 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001817
Brian Paul9499e012000-10-30 16:32:42 +00001818 if (ctx->NewState & _NEW_PIXEL)
1819 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001820
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001821 if (is_color_format(internalFormat)) {
1822 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
1823 &postConvHeight);
1824 }
Brian Paulab6e78f2000-12-09 21:30:43 +00001825
1826 if (copytexture_error_check(ctx, 2, target, level, internalFormat,
1827 postConvWidth, postConvHeight, border))
1828 return;
1829
Brian Paul2aadbf42001-02-19 20:01:41 +00001830 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1831 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1832 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1833 if (!texImage) {
1834 texImage = _mesa_alloc_texture_image();
1835 set_tex_image(texObj, target, level, texImage);
1836 if (!texImage) {
1837 gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
Brian Paulc3f0a511999-11-03 17:27:05 +00001838 return;
1839 }
jtgafb833d1999-08-19 00:55:39 +00001840 }
Brian Paul2aadbf42001-02-19 20:01:41 +00001841 else if (texImage->Data) {
1842 /* free the old texture data */
1843 FREE(texImage->Data);
1844 texImage->Data = NULL;
1845 }
1846
1847 clear_teximage_fields(texImage); /* not really needed, but helpful */
1848 init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1,
1849 border, internalFormat);
1850
1851 ASSERT(ctx->Driver.CopyTexImage2D);
1852 (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat,
1853 x, y, width, height, border);
1854
1855 /* state update */
1856 texObj->Complete = GL_FALSE;
1857 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +00001858}
1859
1860
1861
Brian Paulfbd8f211999-11-11 01:22:25 +00001862void
1863_mesa_CopyTexSubImage1D( GLenum target, GLint level,
1864 GLint xoffset, GLint x, GLint y, GLsizei width )
jtgafb833d1999-08-19 00:55:39 +00001865{
Brian Paulab6e78f2000-12-09 21:30:43 +00001866 GLsizei postConvWidth = width;
Brian Paulfbd8f211999-11-11 01:22:25 +00001867 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001868 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001869
Brian Paul9499e012000-10-30 16:32:42 +00001870 if (ctx->NewState & _NEW_PIXEL)
1871 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001872
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001873 /* XXX should test internal format */
Brian Paul8e39ad22001-02-06 21:42:48 +00001874 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
Brian Paulab6e78f2000-12-09 21:30:43 +00001875
1876 if (copytexsubimage_error_check(ctx, 1, target, level,
1877 xoffset, 0, 0, postConvWidth, 1))
1878 return;
1879
Brian Paul2aadbf42001-02-19 20:01:41 +00001880 ASSERT(ctx->Driver.CopyTexSubImage1D);
1881 (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width);
Brian Paulc3f0a511999-11-03 17:27:05 +00001882}
1883
1884
1885
Brian Paulfbd8f211999-11-11 01:22:25 +00001886void
1887_mesa_CopyTexSubImage2D( GLenum target, GLint level,
1888 GLint xoffset, GLint yoffset,
1889 GLint x, GLint y, GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +00001890{
Brian Paulab6e78f2000-12-09 21:30:43 +00001891 GLsizei postConvWidth = width, postConvHeight = height;
Brian Paulfbd8f211999-11-11 01:22:25 +00001892 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001893 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulc3f0a511999-11-03 17:27:05 +00001894
Brian Paul9499e012000-10-30 16:32:42 +00001895 if (ctx->NewState & _NEW_PIXEL)
1896 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001897
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001898 /* XXX should test internal format */
1899 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight);
Brian Paulab6e78f2000-12-09 21:30:43 +00001900
1901 if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
1902 postConvWidth, postConvHeight))
1903 return;
1904
Brian Paul2aadbf42001-02-19 20:01:41 +00001905 ASSERT(ctx->Driver.CopyTexSubImage2D);
1906 (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level,
1907 xoffset, yoffset, x, y, width, height);
Brian Paulc3f0a511999-11-03 17:27:05 +00001908}
1909
1910
1911
Brian Paulfbd8f211999-11-11 01:22:25 +00001912void
1913_mesa_CopyTexSubImage3D( GLenum target, GLint level,
1914 GLint xoffset, GLint yoffset, GLint zoffset,
1915 GLint x, GLint y, GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +00001916{
Brian Paulab6e78f2000-12-09 21:30:43 +00001917 GLsizei postConvWidth = width, postConvHeight = height;
Brian Paulfbd8f211999-11-11 01:22:25 +00001918 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001919 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulc3f0a511999-11-03 17:27:05 +00001920
Brian Paul9499e012000-10-30 16:32:42 +00001921 if (ctx->NewState & _NEW_PIXEL)
1922 gl_update_state(ctx);
Brian Paulfa4525e2000-08-21 14:22:24 +00001923
Brian Paulf7e1dfe2001-02-17 00:15:39 +00001924 /* XXX should test internal format */
1925 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight);
Brian Paulab6e78f2000-12-09 21:30:43 +00001926
1927 if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset,
1928 zoffset, postConvWidth, postConvHeight))
1929 return;
1930
Brian Paul2aadbf42001-02-19 20:01:41 +00001931 ASSERT(ctx->Driver.CopyTexSubImage3D);
1932 (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level,
1933 xoffset, yoffset, zoffset,
1934 x, y, width, height);
jtgafb833d1999-08-19 00:55:39 +00001935}
Brian Paul1207bf02000-05-23 20:10:49 +00001936
1937
1938
1939void
1940_mesa_CompressedTexImage1DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00001941 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00001942 GLint border, GLsizei imageSize,
1943 const GLvoid *data)
1944{
Brian Paulaea66b12000-05-24 14:04:06 +00001945 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001946 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulaea66b12000-05-24 14:04:06 +00001947
Brian Paul289d47e2000-08-29 23:31:23 +00001948 switch (internalFormat) {
1949 case GL_COMPRESSED_ALPHA_ARB:
1950 case GL_COMPRESSED_LUMINANCE_ARB:
1951 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1952 case GL_COMPRESSED_INTENSITY_ARB:
1953 case GL_COMPRESSED_RGB_ARB:
1954 case GL_COMPRESSED_RGBA_ARB:
1955 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB");
1956 return;
1957 default:
1958 /* silence compiler warning */
1959 ;
1960 }
1961
Brian Paulaea66b12000-05-24 14:04:06 +00001962 if (target == GL_TEXTURE_1D) {
1963 struct gl_texture_unit *texUnit;
1964 struct gl_texture_object *texObj;
1965 struct gl_texture_image *texImage;
1966
1967 if (texture_error_check(ctx, target, level, internalFormat,
1968 GL_NONE, GL_NONE, 1, width, 1, 1, border)) {
1969 return; /* error in texture image was detected */
1970 }
1971
1972 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul8e39ad22001-02-06 21:42:48 +00001973 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1974 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulaea66b12000-05-24 14:04:06 +00001975
1976 if (!texImage) {
1977 texImage = _mesa_alloc_texture_image();
1978 texObj->Image[level] = texImage;
1979 if (!texImage) {
1980 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
1981 return;
1982 }
1983 }
1984 else if (texImage->Data) {
1985 FREE(texImage->Data);
1986 texImage->Data = NULL;
1987 }
1988
Brian Paul6628bc92001-02-07 03:27:41 +00001989 init_teximage_fields(ctx, texImage, width, 1, 1, border, internalFormat);
1990
Brian Paul8e39ad22001-02-06 21:42:48 +00001991 if (ctx->Extensions.ARB_texture_compression) {
1992 ASSERT(ctx->Driver.CompressedTexImage1D);
1993 (*ctx->Driver.CompressedTexImage1D)(ctx, target, level,
1994 internalFormat, width, border,
1995 imageSize, data,
1996 texObj, texImage);
1997 ASSERT(texImage->CompressedSize > 0); /* sanity */
Brian Paulaea66b12000-05-24 14:04:06 +00001998 }
1999
2000 /* state update */
Brian Paula8523782000-11-19 23:10:25 +00002001 texObj->Complete = GL_FALSE;
Keith Whitwella96308c2000-10-30 13:31:59 +00002002 ctx->NewState |= _NEW_TEXTURE;
Brian Paulaea66b12000-05-24 14:04:06 +00002003 }
2004 else if (target == GL_PROXY_TEXTURE_1D) {
2005 /* Proxy texture: check for errors and update proxy state */
Brian Paul38d3f3d2000-09-07 15:38:49 +00002006 GLenum error = texture_error_check(ctx, target, level, internalFormat,
2007 GL_NONE, GL_NONE, 1, width, 1, 1, border);
Brian Paul8e39ad22001-02-06 21:42:48 +00002008 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00002009 struct gl_texture_unit *texUnit;
2010 struct gl_texture_image *texImage;
2011 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2012 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
2013 init_teximage_fields(ctx, texImage, width, 1, 1,
2014 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00002015 ASSERT(ctx->Driver.TestProxyTexImage);
Brian Paul38d3f3d2000-09-07 15:38:49 +00002016 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
2017 internalFormat, GL_NONE, GL_NONE,
2018 width, 1, 1, border);
2019 }
2020 if (error) {
Brian Paulaea66b12000-05-24 14:04:06 +00002021 /* if error, clear all proxy texture image parameters */
Brian Paulf378ab82001-02-06 23:35:26 +00002022 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
2023 clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00002024 }
2025 }
Brian Paulaea66b12000-05-24 14:04:06 +00002026 }
2027 else {
2028 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" );
2029 return;
2030 }
Brian Paul1207bf02000-05-23 20:10:49 +00002031}
2032
2033
2034void
2035_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00002036 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00002037 GLsizei height, GLint border, GLsizei imageSize,
2038 const GLvoid *data)
2039{
Brian Paulaea66b12000-05-24 14:04:06 +00002040 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002041 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulaea66b12000-05-24 14:04:06 +00002042
Brian Paul289d47e2000-08-29 23:31:23 +00002043 switch (internalFormat) {
2044 case GL_COMPRESSED_ALPHA_ARB:
2045 case GL_COMPRESSED_LUMINANCE_ARB:
2046 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
2047 case GL_COMPRESSED_INTENSITY_ARB:
2048 case GL_COMPRESSED_RGB_ARB:
2049 case GL_COMPRESSED_RGBA_ARB:
2050 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB");
2051 return;
2052 default:
2053 /* silence compiler warning */
2054 ;
2055 }
2056
Brian Paul8e39ad22001-02-06 21:42:48 +00002057 if (target == GL_TEXTURE_2D ||
Keith Whitwella96308c2000-10-30 13:31:59 +00002058 (ctx->Extensions.ARB_texture_cube_map &&
Brian Paul9540a1d2000-06-06 17:03:38 +00002059 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
2060 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
Brian Paulaea66b12000-05-24 14:04:06 +00002061 struct gl_texture_unit *texUnit;
2062 struct gl_texture_object *texObj;
2063 struct gl_texture_image *texImage;
2064
2065 if (texture_error_check(ctx, target, level, internalFormat,
2066 GL_NONE, GL_NONE, 1, width, height, 1, border)) {
2067 return; /* error in texture image was detected */
2068 }
2069
2070 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul8e39ad22001-02-06 21:42:48 +00002071 texObj = _mesa_select_tex_object(ctx, texUnit, target);
2072 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulaea66b12000-05-24 14:04:06 +00002073
2074 if (!texImage) {
2075 texImage = _mesa_alloc_texture_image();
2076 texObj->Image[level] = texImage;
2077 if (!texImage) {
2078 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
2079 return;
2080 }
2081 }
2082 else if (texImage->Data) {
2083 FREE(texImage->Data);
2084 texImage->Data = NULL;
2085 }
2086
Brian Paul6628bc92001-02-07 03:27:41 +00002087 init_teximage_fields(ctx, texImage, width, height, 1, border,
2088 internalFormat);
2089
Brian Paul8e39ad22001-02-06 21:42:48 +00002090 if (ctx->Extensions.ARB_texture_compression) {
2091 ASSERT(ctx->Driver.CompressedTexImage2D);
2092 (*ctx->Driver.CompressedTexImage2D)(ctx, target, level,
2093 internalFormat, width, height,
2094 border, imageSize, data,
2095 texObj, texImage);
2096 ASSERT(texImage->CompressedSize > 0); /* sanity */
Brian Paulaea66b12000-05-24 14:04:06 +00002097 }
2098
2099 /* state update */
Brian Paula8523782000-11-19 23:10:25 +00002100 texObj->Complete = GL_FALSE;
Keith Whitwella96308c2000-10-30 13:31:59 +00002101 ctx->NewState |= _NEW_TEXTURE;
Brian Paulaea66b12000-05-24 14:04:06 +00002102 }
2103 else if (target == GL_PROXY_TEXTURE_2D) {
2104 /* Proxy texture: check for errors and update proxy state */
Brian Paul38d3f3d2000-09-07 15:38:49 +00002105 GLenum error = texture_error_check(ctx, target, level, internalFormat,
2106 GL_NONE, GL_NONE, 2, width, height, 1, border);
Brian Paul8e39ad22001-02-06 21:42:48 +00002107 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00002108 struct gl_texture_unit *texUnit;
2109 struct gl_texture_image *texImage;
2110 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2111 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
2112 init_teximage_fields(ctx, texImage, width, height, 1,
2113 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00002114 ASSERT(ctx->Driver.TestProxyTexImage);
Brian Paul38d3f3d2000-09-07 15:38:49 +00002115 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
2116 internalFormat, GL_NONE, GL_NONE,
2117 width, height, 1, border);
2118 }
2119 if (error) {
Brian Paulaea66b12000-05-24 14:04:06 +00002120 /* if error, clear all proxy texture image parameters */
Brian Paulf378ab82001-02-06 23:35:26 +00002121 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
2122 clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00002123 }
2124 }
Brian Paulaea66b12000-05-24 14:04:06 +00002125 }
2126 else {
2127 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" );
2128 return;
2129 }
Brian Paul1207bf02000-05-23 20:10:49 +00002130}
2131
2132
2133void
2134_mesa_CompressedTexImage3DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00002135 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00002136 GLsizei height, GLsizei depth, GLint border,
2137 GLsizei imageSize, const GLvoid *data)
2138{
Brian Paulaea66b12000-05-24 14:04:06 +00002139 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002140 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulaea66b12000-05-24 14:04:06 +00002141
Brian Paul289d47e2000-08-29 23:31:23 +00002142 switch (internalFormat) {
2143 case GL_COMPRESSED_ALPHA_ARB:
2144 case GL_COMPRESSED_LUMINANCE_ARB:
2145 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
2146 case GL_COMPRESSED_INTENSITY_ARB:
2147 case GL_COMPRESSED_RGB_ARB:
2148 case GL_COMPRESSED_RGBA_ARB:
2149 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB");
2150 return;
2151 default:
2152 /* silence compiler warning */
2153 ;
2154 }
2155
Brian Paul9540a1d2000-06-06 17:03:38 +00002156 if (target == GL_TEXTURE_3D) {
Brian Paulaea66b12000-05-24 14:04:06 +00002157 struct gl_texture_unit *texUnit;
2158 struct gl_texture_object *texObj;
2159 struct gl_texture_image *texImage;
2160
2161 if (texture_error_check(ctx, target, level, internalFormat,
2162 GL_NONE, GL_NONE, 1, width, height, depth, border)) {
2163 return; /* error in texture image was detected */
2164 }
2165
2166 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul8e39ad22001-02-06 21:42:48 +00002167 texObj = _mesa_select_tex_object(ctx, texUnit, target);
2168 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulaea66b12000-05-24 14:04:06 +00002169
2170 if (!texImage) {
2171 texImage = _mesa_alloc_texture_image();
2172 texObj->Image[level] = texImage;
2173 if (!texImage) {
2174 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
2175 return;
2176 }
2177 }
2178 else if (texImage->Data) {
2179 FREE(texImage->Data);
2180 texImage->Data = NULL;
2181 }
2182
Brian Paul6628bc92001-02-07 03:27:41 +00002183 init_teximage_fields(ctx, texImage, width, height, depth, border,
2184 internalFormat);
2185
Brian Paul8e39ad22001-02-06 21:42:48 +00002186 if (ctx->Extensions.ARB_texture_compression) {
2187 ASSERT(ctx->Driver.CompressedTexImage3D);
2188 (*ctx->Driver.CompressedTexImage3D)(ctx, target, level,
2189 internalFormat,
2190 width, height, depth,
2191 border, imageSize, data,
2192 texObj, texImage);
2193 ASSERT(texImage->CompressedSize > 0); /* sanity */
Brian Paulaea66b12000-05-24 14:04:06 +00002194 }
2195
2196 /* state update */
Brian Paula8523782000-11-19 23:10:25 +00002197 texObj->Complete = GL_FALSE;
Keith Whitwella96308c2000-10-30 13:31:59 +00002198 ctx->NewState |= _NEW_TEXTURE;
Brian Paulaea66b12000-05-24 14:04:06 +00002199 }
2200 else if (target == GL_PROXY_TEXTURE_3D) {
2201 /* Proxy texture: check for errors and update proxy state */
Brian Paul38d3f3d2000-09-07 15:38:49 +00002202 GLenum error = texture_error_check(ctx, target, level, internalFormat,
2203 GL_NONE, GL_NONE, 1, width, height, depth, border);
Brian Paul8e39ad22001-02-06 21:42:48 +00002204 if (!error) {
Brian Paula1f15862001-02-07 16:27:41 +00002205 struct gl_texture_unit *texUnit;
2206 struct gl_texture_image *texImage;
2207 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2208 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
2209 init_teximage_fields(ctx, texImage, width, height, depth,
2210 border, internalFormat);
Brian Paul8e39ad22001-02-06 21:42:48 +00002211 ASSERT(ctx->Driver.TestProxyTexImage);
Brian Paul38d3f3d2000-09-07 15:38:49 +00002212 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
2213 internalFormat, GL_NONE, GL_NONE,
2214 width, height, depth, border);
2215 }
2216 if (error) {
Brian Paulaea66b12000-05-24 14:04:06 +00002217 /* if error, clear all proxy texture image parameters */
Brian Paulf378ab82001-02-06 23:35:26 +00002218 if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
2219 clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00002220 }
2221 }
Brian Paulaea66b12000-05-24 14:04:06 +00002222 }
2223 else {
2224 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" );
2225 return;
2226 }
Brian Paul1207bf02000-05-23 20:10:49 +00002227}
2228
2229
2230void
2231_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
2232 GLsizei width, GLenum format,
2233 GLsizei imageSize, const GLvoid *data)
2234{
Brian Paul9540a1d2000-06-06 17:03:38 +00002235 struct gl_texture_unit *texUnit;
2236 struct gl_texture_object *texObj;
2237 struct gl_texture_image *texImage;
Brian Paula1f15862001-02-07 16:27:41 +00002238 GET_CURRENT_CONTEXT(ctx);
Brian Paul9540a1d2000-06-06 17:03:38 +00002239
2240 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
2241 width, 1, 1, format, GL_NONE)) {
2242 return; /* error was detected */
2243 }
2244
2245 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2246 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul8e39ad22001-02-06 21:42:48 +00002247 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul9540a1d2000-06-06 17:03:38 +00002248 assert(texImage);
2249
2250 if (width == 0 || !data)
2251 return; /* no-op, not an error */
2252
2253 if (ctx->Driver.CompressedTexSubImage1D) {
Brian Paul8e39ad22001-02-06 21:42:48 +00002254 (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level,
2255 xoffset, width,
2256 format, imageSize, data,
2257 texObj, texImage);
Brian Paul9540a1d2000-06-06 17:03:38 +00002258 }
Brian Paul1207bf02000-05-23 20:10:49 +00002259}
2260
2261
2262void
2263_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
2264 GLint yoffset, GLsizei width, GLsizei height,
2265 GLenum format, GLsizei imageSize,
2266 const GLvoid *data)
2267{
Brian Paul9540a1d2000-06-06 17:03:38 +00002268 struct gl_texture_unit *texUnit;
2269 struct gl_texture_object *texObj;
2270 struct gl_texture_image *texImage;
Brian Paula1f15862001-02-07 16:27:41 +00002271 GET_CURRENT_CONTEXT(ctx);
Brian Paul9540a1d2000-06-06 17:03:38 +00002272
2273 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
2274 width, height, 1, format, GL_NONE)) {
2275 return; /* error was detected */
2276 }
2277
2278 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2279 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul8e39ad22001-02-06 21:42:48 +00002280 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul9540a1d2000-06-06 17:03:38 +00002281 assert(texImage);
2282
2283 if (width == 0 || height == 0 || !data)
2284 return; /* no-op, not an error */
2285
2286 if (ctx->Driver.CompressedTexSubImage2D) {
Brian Paul8e39ad22001-02-06 21:42:48 +00002287 (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level,
2288 xoffset, yoffset, width, height,
2289 format, imageSize, data,
2290 texObj, texImage);
Brian Paul9540a1d2000-06-06 17:03:38 +00002291 }
Brian Paul1207bf02000-05-23 20:10:49 +00002292}
2293
2294
2295void
2296_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
2297 GLint yoffset, GLint zoffset, GLsizei width,
2298 GLsizei height, GLsizei depth, GLenum format,
2299 GLsizei imageSize, const GLvoid *data)
2300{
Brian Paul9540a1d2000-06-06 17:03:38 +00002301 struct gl_texture_unit *texUnit;
2302 struct gl_texture_object *texObj;
2303 struct gl_texture_image *texImage;
Brian Paula1f15862001-02-07 16:27:41 +00002304 GET_CURRENT_CONTEXT(ctx);
Brian Paul9540a1d2000-06-06 17:03:38 +00002305
2306 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
2307 width, height, depth, format, GL_NONE)) {
2308 return; /* error was detected */
2309 }
2310
2311 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2312 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul8e39ad22001-02-06 21:42:48 +00002313 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paul9540a1d2000-06-06 17:03:38 +00002314 assert(texImage);
2315
2316 if (width == 0 || height == 0 || depth == 0 || !data)
2317 return; /* no-op, not an error */
2318
2319 if (ctx->Driver.CompressedTexSubImage3D) {
Brian Paul8e39ad22001-02-06 21:42:48 +00002320 (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level,
2321 xoffset, yoffset, zoffset,
2322 width, height, depth,
2323 format, imageSize, data,
2324 texObj, texImage);
Brian Paul9540a1d2000-06-06 17:03:38 +00002325 }
Brian Paul1207bf02000-05-23 20:10:49 +00002326}
2327
2328
2329void
Brian Paul9540a1d2000-06-06 17:03:38 +00002330_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
Brian Paul1207bf02000-05-23 20:10:49 +00002331{
Brian Paul8e39ad22001-02-06 21:42:48 +00002332 const struct gl_texture_unit *texUnit;
Brian Paul9540a1d2000-06-06 17:03:38 +00002333 const struct gl_texture_object *texObj;
2334 struct gl_texture_image *texImage;
Brian Paula1f15862001-02-07 16:27:41 +00002335 GET_CURRENT_CONTEXT(ctx);
Brian Paul9540a1d2000-06-06 17:03:38 +00002336
Keith Whitwellcab974c2000-12-26 05:09:27 +00002337 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paul9540a1d2000-06-06 17:03:38 +00002338
2339 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
2340 gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" );
2341 return;
2342 }
2343
Brian Paul8e39ad22001-02-06 21:42:48 +00002344 if (is_proxy_target(target)) {
2345 gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
2346 return;
Brian Paul9540a1d2000-06-06 17:03:38 +00002347 }
2348
Brian Paul8e39ad22001-02-06 21:42:48 +00002349 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2350 texObj = _mesa_select_tex_object(ctx, texUnit, target);
2351 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
2352
Brian Paul9540a1d2000-06-06 17:03:38 +00002353 if (!texImage) {
2354 /* invalid mipmap level */
2355 gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)");
2356 return;
2357 }
2358
2359 if (!texImage->IsCompressed) {
2360 gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB");
2361 return;
2362 }
2363
2364 if (!img)
2365 return;
2366
Brian Paul8e39ad22001-02-06 21:42:48 +00002367 if (ctx->Extensions.ARB_texture_compression) {
2368 ASSERT(ctx->Driver.GetCompressedTexImage);
Brian Paul9540a1d2000-06-06 17:03:38 +00002369 (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj,
2370 texImage);
2371 }
Brian Paul1207bf02000-05-23 20:10:49 +00002372}