blob: b24344d85cd30d088661da0a7a9c7d974b93a81a [file] [log] [blame]
Brian Paulf96ce6a2000-09-06 15:15:43 +00001/* $Id: teximage.c,v 1.49 2000/09/06 15:15:43 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
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paul663049a2000-01-31 23:10:16 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * 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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * 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 Paulfbd8f211999-11-11 01:22:25 +000035#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "mmath.h"
37#include "span.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"
41#include "types.h"
jtgafb833d1999-08-19 00:55:39 +000042#endif
43
44
45/*
46 * NOTES:
47 *
Brian Paulc3f0a511999-11-03 17:27:05 +000048 * Mesa's native texture datatype is GLubyte. Native formats are
49 * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA,
50 * and GL_COLOR_INDEX.
51 * Device drivers are free to implement any internal format they want.
jtgafb833d1999-08-19 00:55:39 +000052 */
53
54
Brian Paul48271792000-03-29 18:13:59 +000055#ifdef DEBUG
Brian Paule5d68a22000-03-30 18:37:51 +000056static void PrintTexture(const struct gl_texture_image *img)
Brian Paul48271792000-03-29 18:13:59 +000057{
Brian Paule5d68a22000-03-30 18:37:51 +000058 int i, j, c;
59 GLubyte *data = img->Data;
60
61 if (!data) {
62 printf("No texture data\n");
63 return;
64 }
65
66 switch (img->Format) {
67 case GL_ALPHA:
68 case GL_LUMINANCE:
69 case GL_INTENSITY:
70 case GL_COLOR_INDEX:
71 c = 1;
72 break;
73 case GL_LUMINANCE_ALPHA:
74 c = 2;
75 break;
76 case GL_RGB:
77 c = 3;
78 break;
79 case GL_RGBA:
80 c = 4;
81 break;
82 default:
83 gl_problem(NULL, "error in PrintTexture\n");
84 return;
85 }
86
87
88 for (i = 0; i < img->Height; i++) {
89 for (j = 0; j < img->Width; j++) {
Brian Paul48271792000-03-29 18:13:59 +000090 if (c==1)
91 printf("%02x ", data[0]);
92 else if (c==2)
Brian Paule5d68a22000-03-30 18:37:51 +000093 printf("%02x%02x ", data[0], data[1]);
Brian Paul48271792000-03-29 18:13:59 +000094 else if (c==3)
Brian Paule5d68a22000-03-30 18:37:51 +000095 printf("%02x%02x%02x ", data[0], data[1], data[2]);
Brian Paul48271792000-03-29 18:13:59 +000096 else if (c==4)
Brian Paule5d68a22000-03-30 18:37:51 +000097 printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]);
Brian Paul48271792000-03-29 18:13:59 +000098 data += c;
99 }
100 printf("\n");
101 }
102}
103#endif
104
105
106
Brian Paulf7b57072000-03-20 14:37:52 +0000107/*
jtgafb833d1999-08-19 00:55:39 +0000108 * Compute log base 2 of n.
109 * If n isn't an exact power of two return -1.
110 * If n<0 return -1.
111 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000112static int
113logbase2( int n )
jtgafb833d1999-08-19 00:55:39 +0000114{
115 GLint i = 1;
116 GLint log2 = 0;
117
118 if (n<0) {
119 return -1;
120 }
121
122 while ( n > i ) {
123 i *= 2;
124 log2++;
125 }
126 if (i != n) {
127 return -1;
128 }
129 else {
130 return log2;
131 }
132}
133
134
135
136/*
137 * Given an internal texture format enum or 1, 2, 3, 4 return the
138 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
Brian Paulc3f0a511999-11-03 17:27:05 +0000139 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA.
140 * Return -1 if invalid enum.
jtgafb833d1999-08-19 00:55:39 +0000141 */
Brian Paulb132e8d2000-03-23 16:23:14 +0000142GLint
Brian Paulaea66b12000-05-24 14:04:06 +0000143_mesa_base_tex_format( GLcontext *ctx, GLint format )
jtgafb833d1999-08-19 00:55:39 +0000144{
Brian Paul289d47e2000-08-29 23:31:23 +0000145 /*
146 * Ask the driver for the base format, if it doesn't
147 * know, it will return -1;
148 */
149 if (ctx->Driver.BaseCompressedTexFormat) {
150 GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format);
151 if (ifmt >= 0) {
152 return ifmt;
153 }
154 }
jtgafb833d1999-08-19 00:55:39 +0000155 switch (format) {
156 case GL_ALPHA:
157 case GL_ALPHA4:
158 case GL_ALPHA8:
159 case GL_ALPHA12:
160 case GL_ALPHA16:
161 return GL_ALPHA;
162 case 1:
163 case GL_LUMINANCE:
164 case GL_LUMINANCE4:
165 case GL_LUMINANCE8:
166 case GL_LUMINANCE12:
167 case GL_LUMINANCE16:
168 return GL_LUMINANCE;
169 case 2:
170 case GL_LUMINANCE_ALPHA:
171 case GL_LUMINANCE4_ALPHA4:
172 case GL_LUMINANCE6_ALPHA2:
173 case GL_LUMINANCE8_ALPHA8:
174 case GL_LUMINANCE12_ALPHA4:
175 case GL_LUMINANCE12_ALPHA12:
176 case GL_LUMINANCE16_ALPHA16:
177 return GL_LUMINANCE_ALPHA;
178 case GL_INTENSITY:
179 case GL_INTENSITY4:
180 case GL_INTENSITY8:
181 case GL_INTENSITY12:
182 case GL_INTENSITY16:
183 return GL_INTENSITY;
184 case 3:
185 case GL_RGB:
186 case GL_R3_G3_B2:
187 case GL_RGB4:
188 case GL_RGB5:
189 case GL_RGB8:
190 case GL_RGB10:
191 case GL_RGB12:
192 case GL_RGB16:
193 return GL_RGB;
194 case 4:
195 case GL_RGBA:
196 case GL_RGBA2:
197 case GL_RGBA4:
198 case GL_RGB5_A1:
199 case GL_RGBA8:
200 case GL_RGB10_A2:
201 case GL_RGBA12:
202 case GL_RGBA16:
203 return GL_RGBA;
204 case GL_COLOR_INDEX:
205 case GL_COLOR_INDEX1_EXT:
206 case GL_COLOR_INDEX2_EXT:
207 case GL_COLOR_INDEX4_EXT:
208 case GL_COLOR_INDEX8_EXT:
209 case GL_COLOR_INDEX12_EXT:
210 case GL_COLOR_INDEX16_EXT:
211 return GL_COLOR_INDEX;
212 default:
213 return -1; /* error */
214 }
215}
216
217
218
219/*
220 * Given an internal texture format enum or 1, 2, 3, 4 return the
221 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
222 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the
223 * number of components for the format. Return -1 if invalid enum.
224 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000225static GLint
226components_in_intformat( GLint format )
jtgafb833d1999-08-19 00:55:39 +0000227{
228 switch (format) {
229 case GL_ALPHA:
230 case GL_ALPHA4:
231 case GL_ALPHA8:
232 case GL_ALPHA12:
233 case GL_ALPHA16:
234 return 1;
235 case 1:
236 case GL_LUMINANCE:
237 case GL_LUMINANCE4:
238 case GL_LUMINANCE8:
239 case GL_LUMINANCE12:
240 case GL_LUMINANCE16:
241 return 1;
242 case 2:
243 case GL_LUMINANCE_ALPHA:
244 case GL_LUMINANCE4_ALPHA4:
245 case GL_LUMINANCE6_ALPHA2:
246 case GL_LUMINANCE8_ALPHA8:
247 case GL_LUMINANCE12_ALPHA4:
248 case GL_LUMINANCE12_ALPHA12:
249 case GL_LUMINANCE16_ALPHA16:
250 return 2;
251 case GL_INTENSITY:
252 case GL_INTENSITY4:
253 case GL_INTENSITY8:
254 case GL_INTENSITY12:
255 case GL_INTENSITY16:
256 return 1;
257 case 3:
258 case GL_RGB:
259 case GL_R3_G3_B2:
260 case GL_RGB4:
261 case GL_RGB5:
262 case GL_RGB8:
263 case GL_RGB10:
264 case GL_RGB12:
265 case GL_RGB16:
266 return 3;
267 case 4:
268 case GL_RGBA:
269 case GL_RGBA2:
270 case GL_RGBA4:
271 case GL_RGB5_A1:
272 case GL_RGBA8:
273 case GL_RGB10_A2:
274 case GL_RGBA12:
275 case GL_RGBA16:
276 return 4;
277 case GL_COLOR_INDEX:
278 case GL_COLOR_INDEX1_EXT:
279 case GL_COLOR_INDEX2_EXT:
280 case GL_COLOR_INDEX4_EXT:
281 case GL_COLOR_INDEX8_EXT:
282 case GL_COLOR_INDEX12_EXT:
283 case GL_COLOR_INDEX16_EXT:
284 return 1;
285 default:
286 return -1; /* error */
287 }
288}
289
290
Brian Paulaea66b12000-05-24 14:04:06 +0000291/*
292 * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE
293 * otherwise.
294 */
295static GLboolean
Brian Paul289d47e2000-08-29 23:31:23 +0000296is_compressed_format(GLcontext *ctx, GLenum internalFormat)
Brian Paulaea66b12000-05-24 14:04:06 +0000297{
Brian Paul289d47e2000-08-29 23:31:23 +0000298 if (ctx->Driver.IsCompressedFormat) {
299 return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat);
300 }
301 return GL_FALSE;
Brian Paulaea66b12000-05-24 14:04:06 +0000302}
303
304
jtgafb833d1999-08-19 00:55:39 +0000305
jtgafb833d1999-08-19 00:55:39 +0000306/*
307 * Examine the texImage->Format field and set the Red, Green, Blue, etc
308 * texel component sizes to default values.
309 * These fields are set only here by core Mesa but device drivers may
310 * overwritting these fields to indicate true texel resolution.
311 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000312static void
313set_teximage_component_sizes( struct gl_texture_image *texImage )
jtgafb833d1999-08-19 00:55:39 +0000314{
315 switch (texImage->Format) {
316 case GL_ALPHA:
317 texImage->RedBits = 0;
318 texImage->GreenBits = 0;
319 texImage->BlueBits = 0;
320 texImage->AlphaBits = 8;
321 texImage->IntensityBits = 0;
322 texImage->LuminanceBits = 0;
323 texImage->IndexBits = 0;
324 break;
325 case GL_LUMINANCE:
326 texImage->RedBits = 0;
327 texImage->GreenBits = 0;
328 texImage->BlueBits = 0;
329 texImage->AlphaBits = 0;
330 texImage->IntensityBits = 0;
331 texImage->LuminanceBits = 8;
332 texImage->IndexBits = 0;
333 break;
334 case GL_LUMINANCE_ALPHA:
335 texImage->RedBits = 0;
336 texImage->GreenBits = 0;
337 texImage->BlueBits = 0;
338 texImage->AlphaBits = 8;
339 texImage->IntensityBits = 0;
340 texImage->LuminanceBits = 8;
341 texImage->IndexBits = 0;
342 break;
343 case GL_INTENSITY:
344 texImage->RedBits = 0;
345 texImage->GreenBits = 0;
346 texImage->BlueBits = 0;
347 texImage->AlphaBits = 0;
348 texImage->IntensityBits = 8;
349 texImage->LuminanceBits = 0;
350 texImage->IndexBits = 0;
351 break;
Brian Paul91baaa31999-10-17 23:24:16 +0000352 case GL_RED:
353 texImage->RedBits = 8;
354 texImage->GreenBits = 0;
355 texImage->BlueBits = 0;
356 texImage->AlphaBits = 0;
357 texImage->IntensityBits = 0;
358 texImage->LuminanceBits = 0;
359 texImage->IndexBits = 0;
360 break;
361 case GL_GREEN:
362 texImage->RedBits = 0;
363 texImage->GreenBits = 8;
364 texImage->BlueBits = 0;
365 texImage->AlphaBits = 0;
366 texImage->IntensityBits = 0;
367 texImage->LuminanceBits = 0;
368 texImage->IndexBits = 0;
369 break;
370 case GL_BLUE:
371 texImage->RedBits = 0;
372 texImage->GreenBits = 0;
373 texImage->BlueBits = 8;
374 texImage->AlphaBits = 0;
375 texImage->IntensityBits = 0;
376 texImage->LuminanceBits = 0;
377 texImage->IndexBits = 0;
378 break;
jtgafb833d1999-08-19 00:55:39 +0000379 case GL_RGB:
Brian Pauld53573d1999-10-19 20:36:20 +0000380 case GL_BGR:
jtgafb833d1999-08-19 00:55:39 +0000381 texImage->RedBits = 8;
382 texImage->GreenBits = 8;
383 texImage->BlueBits = 8;
384 texImage->AlphaBits = 0;
385 texImage->IntensityBits = 0;
386 texImage->LuminanceBits = 0;
387 texImage->IndexBits = 0;
388 break;
389 case GL_RGBA:
Brian Pauld53573d1999-10-19 20:36:20 +0000390 case GL_BGRA:
391 case GL_ABGR_EXT:
jtgafb833d1999-08-19 00:55:39 +0000392 texImage->RedBits = 8;
393 texImage->GreenBits = 8;
394 texImage->BlueBits = 8;
395 texImage->AlphaBits = 8;
396 texImage->IntensityBits = 0;
397 texImage->LuminanceBits = 0;
398 texImage->IndexBits = 0;
399 break;
400 case GL_COLOR_INDEX:
401 texImage->RedBits = 0;
402 texImage->GreenBits = 0;
403 texImage->BlueBits = 0;
404 texImage->AlphaBits = 0;
405 texImage->IntensityBits = 0;
406 texImage->LuminanceBits = 0;
407 texImage->IndexBits = 8;
408 break;
409 default:
410 gl_problem(NULL, "unexpected format in set_teximage_component_sizes");
411 }
412}
413
414
Brian Paulfc4b4432000-05-23 15:17:12 +0000415static void
416set_tex_image(struct gl_texture_object *tObj,
417 GLenum target, GLint level,
418 struct gl_texture_image *texImage)
419{
420 ASSERT(tObj);
421 ASSERT(texImage);
422 switch (target) {
423 case GL_TEXTURE_2D:
424 tObj->Image[level] = texImage;
425 return;
426 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
Brian Paul413d6a22000-05-26 14:44:59 +0000427 tObj->Image[level] = texImage;
Brian Paulfc4b4432000-05-23 15:17:12 +0000428 return;
429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
430 tObj->NegX[level] = texImage;
431 return;
432 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
433 tObj->PosY[level] = texImage;
434 return;
435 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
436 tObj->NegY[level] = texImage;
437 return;
438 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
439 tObj->PosZ[level] = texImage;
440 return;
441 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
442 tObj->NegZ[level] = texImage;
443 return;
444 default:
445 gl_problem(NULL, "bad target in set_tex_image()");
446 return;
447 }
448}
449
450
Brian Paul77ce6da2000-03-20 23:40:12 +0000451/*
452 * Return new gl_texture_image struct with all fields initialized to zero.
453 */
454struct gl_texture_image *
Brian Paul021a5252000-03-27 17:54:17 +0000455_mesa_alloc_texture_image( void )
Brian Paul77ce6da2000-03-20 23:40:12 +0000456{
457 return CALLOC_STRUCT(gl_texture_image);
458}
459
460
461
462/*
Brian Paul02938782000-03-22 17:38:11 +0000463 * Initialize most fields of a gl_texture_image struct.
Brian Paul77ce6da2000-03-20 23:40:12 +0000464 */
Brian Paul02938782000-03-22 17:38:11 +0000465static void
Brian Paul289d47e2000-08-29 23:31:23 +0000466init_texture_image( GLcontext *ctx,
467 struct gl_texture_image *img,
Brian Paul02938782000-03-22 17:38:11 +0000468 GLsizei width, GLsizei height, GLsizei depth,
469 GLint border, GLenum internalFormat )
Brian Paul77ce6da2000-03-20 23:40:12 +0000470{
Brian Paul02938782000-03-22 17:38:11 +0000471 ASSERT(img);
472 ASSERT(!img->Data);
Brian Paul289d47e2000-08-29 23:31:23 +0000473 img->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat);
Brian Paul77ce6da2000-03-20 23:40:12 +0000474 set_teximage_component_sizes( img );
475 img->IntFormat = (GLenum) internalFormat;
476 img->Border = border;
477 img->Width = width;
478 img->Height = height;
479 img->Depth = depth;
480 img->WidthLog2 = logbase2(width - 2 * border);
481 if (height == 1) /* 1-D texture */
482 img->HeightLog2 = 0;
483 else
484 img->HeightLog2 = logbase2(height - 2 * border);
485 if (depth == 1) /* 2-D texture */
486 img->DepthLog2 = 0;
487 else
488 img->DepthLog2 = logbase2(depth - 2 * border);
489 img->Width2 = 1 << img->WidthLog2;
490 img->Height2 = 1 << img->HeightLog2;
491 img->Depth2 = 1 << img->DepthLog2;
492 img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
Brian Paul289d47e2000-08-29 23:31:23 +0000493 img->IsCompressed = is_compressed_format(ctx, internalFormat);
Brian Paul77ce6da2000-03-20 23:40:12 +0000494}
495
496
497
498void
Brian Paul021a5252000-03-27 17:54:17 +0000499_mesa_free_texture_image( struct gl_texture_image *teximage )
Brian Paul77ce6da2000-03-20 23:40:12 +0000500{
501 if (teximage->Data) {
502 FREE( teximage->Data );
503 teximage->Data = NULL;
504 }
505 FREE( teximage );
506}
507
508
509
Brian Paulfc4b4432000-05-23 15:17:12 +0000510/*
Brian Paulaea66b12000-05-24 14:04:06 +0000511 * Return number of bytes of storage needed to store a compressed texture
Brian Paul289d47e2000-08-29 23:31:23 +0000512 * image. Only the driver knows for sure. If the driver can't help us,
513 * we must return 0.
Brian Paulaea66b12000-05-24 14:04:06 +0000514 */
515GLuint
Brian Paul289d47e2000-08-29 23:31:23 +0000516_mesa_compressed_image_size(GLcontext *ctx,
517 GLenum internalFormat,
518 GLint numDimensions,
519 GLint width,
520 GLint height,
521 GLint depth)
Brian Paulaea66b12000-05-24 14:04:06 +0000522{
Brian Paul289d47e2000-08-29 23:31:23 +0000523 if (ctx->Driver.CompressedImageSize) {
524 return (*ctx->Driver.CompressedImageSize)(ctx, internalFormat,
525 numDimensions,
526 width, height, depth);
527 }
528 else {
529 /* Shouldn't this be an internal error of some sort? */
530 return 0;
531 }
Brian Paulaea66b12000-05-24 14:04:06 +0000532}
533
534
535
536/*
Brian Paul35d53012000-05-23 17:14:49 +0000537 * Given a texture unit and a texture target, return the corresponding
538 * texture object.
539 */
540struct gl_texture_object *
Brian Paul01e54752000-09-05 15:40:34 +0000541_mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
Brian Paul35d53012000-05-23 17:14:49 +0000542 GLenum target)
543{
544 switch (target) {
545 case GL_TEXTURE_1D:
546 return texUnit->CurrentD[1];
547 case GL_PROXY_TEXTURE_1D:
548 return ctx->Texture.Proxy1D;
549 case GL_TEXTURE_2D:
550 return texUnit->CurrentD[2];
551 case GL_PROXY_TEXTURE_2D:
552 return ctx->Texture.Proxy2D;
553 case GL_TEXTURE_3D:
554 return texUnit->CurrentD[3];
555 case GL_PROXY_TEXTURE_3D:
556 return ctx->Texture.Proxy3D;
557 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
558 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
559 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
560 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
561 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
562 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
563 return ctx->Extensions.HaveTextureCubeMap
564 ? texUnit->CurrentCubeMap : NULL;
565 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
566 return ctx->Extensions.HaveTextureCubeMap
567 ? ctx->Texture.ProxyCubeMap : NULL;
568 default:
569 gl_problem(NULL, "bad target in _mesa_select_tex_object()");
570 return NULL;
571 }
572}
573
574
575/*
Brian Paulfc4b4432000-05-23 15:17:12 +0000576 * Return the texture image struct which corresponds to target and level
577 * for the given texture unit.
578 */
579struct gl_texture_image *
580_mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit,
581 GLenum target, GLint level)
582{
583 ASSERT(texUnit);
584 switch (target) {
585 case GL_TEXTURE_1D:
586 return texUnit->CurrentD[1]->Image[level];
587 case GL_PROXY_TEXTURE_1D:
588 return ctx->Texture.Proxy1D->Image[level];
589 case GL_TEXTURE_2D:
590 return texUnit->CurrentD[2]->Image[level];
591 case GL_PROXY_TEXTURE_2D:
592 return ctx->Texture.Proxy2D->Image[level];
593 case GL_TEXTURE_3D:
594 return texUnit->CurrentD[3]->Image[level];
595 case GL_PROXY_TEXTURE_3D:
596 return ctx->Texture.Proxy3D->Image[level];
597 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
598 if (ctx->Extensions.HaveTextureCubeMap)
Brian Paul413d6a22000-05-26 14:44:59 +0000599 return texUnit->CurrentCubeMap->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000600 else
601 return NULL;
602 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
603 if (ctx->Extensions.HaveTextureCubeMap)
604 return texUnit->CurrentCubeMap->NegX[level];
605 else
606 return NULL;
607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
608 if (ctx->Extensions.HaveTextureCubeMap)
609 return texUnit->CurrentCubeMap->PosY[level];
610 else
611 return NULL;
612 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
613 if (ctx->Extensions.HaveTextureCubeMap)
614 return texUnit->CurrentCubeMap->NegY[level];
615 else
616 return NULL;
617 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
618 if (ctx->Extensions.HaveTextureCubeMap)
619 return texUnit->CurrentCubeMap->PosZ[level];
620 else
621 return NULL;
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
623 if (ctx->Extensions.HaveTextureCubeMap)
624 return texUnit->CurrentCubeMap->NegZ[level];
625 else
626 return NULL;
627 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
628 if (ctx->Extensions.HaveTextureCubeMap)
Brian Paul413d6a22000-05-26 14:44:59 +0000629 return ctx->Texture.ProxyCubeMap->Image[level];
Brian Paulfc4b4432000-05-23 15:17:12 +0000630 else
631 return NULL;
632 default:
633 gl_problem(ctx, "bad target in _mesa_select_tex_image()");
634 return NULL;
635 }
636}
637
638
639
Brian Paulf93b3dd2000-08-30 18:22:28 +0000640/*
641 * Calling glTexImage and related functions when convolution is enabled
642 * with GL_REDUCE border mode causes some complications.
643 * The incoming image must be extra large so that the post-convolution
644 * image size is reduced to a power of two size (plus 2 * border).
645 * This function adjusts a texture width and height accordingly if
646 * convolution with GL_REDUCE is enabled.
647 */
648static void
649adjust_texture_size_for_convolution(const GLcontext *ctx, GLuint dimensions,
650 GLsizei *width, GLsizei *height)
651{
652 if (ctx->Pixel.Convolution1DEnabled
653 && dimensions == 1
654 && ctx->Pixel.ConvolutionBorderMode[0] == GL_REDUCE) {
655 *width = *width - (MAX2(ctx->Convolution1D.Width, 1) - 1);
656 }
657 else if (ctx->Pixel.Convolution2DEnabled
658 && dimensions > 1
659 && ctx->Pixel.ConvolutionBorderMode[1] == GL_REDUCE) {
660 *width = *width - (MAX2(ctx->Convolution2D.Width, 1) - 1);
661 *height = *height - (MAX2(ctx->Convolution2D.Height, 1) - 1);
662 }
663 else if (ctx->Pixel.Separable2DEnabled
664 && dimensions > 1
665 && ctx->Pixel.ConvolutionBorderMode[2] == GL_REDUCE) {
666 *width = *width - (MAX2(ctx->Separable2D.Width, 1) - 1);
667 *height = *height - (MAX2(ctx->Separable2D.Height, 1) - 1);
668 }
669}
670
671
672
Brian Paula805bb92000-09-02 17:52:21 +0000673/*
674 * This function is used to move user image data into a texture image.
675 * We handle full texture images and subtexture images. We also take
676 * care of all image transfer operations here, including convolution.
677 * Input:
678 * dstXoffset, dstYoffset, dstZoffset - offsets in pixels
679 * dstRowStride, dstImageStride - strides in bytes
680 */
681static void
682fill_texture_image( GLcontext *ctx, GLuint dimensions,
683 GLenum texFormat, GLubyte *texAddr,
684 GLint srcWidth, GLint srcHeight, GLint srcDepth,
685 GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
686 GLint dstRowStride, GLint dstImageStride,
687 GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr,
688 const struct gl_pixelstore_attrib *srcPacking)
689{
690 GLint texComponents;
691
692 ASSERT(ctx);
693 ASSERT(dimensions >= 1 && dimensions <= 3);
694 ASSERT(texAddr);
695 ASSERT(srcWidth >= 1);
696 ASSERT(srcHeight >= 1);
697 ASSERT(srcDepth >= 1);
698 ASSERT(dstXoffset >= 0);
699 ASSERT(dstYoffset >= 0);
700 ASSERT(dstZoffset >= 0);
701 ASSERT(dstRowStride >= 0);
702 ASSERT(dstImageStride >= 0);
703 ASSERT(srcAddr);
704 ASSERT(srcPacking);
705
706 texComponents = components_in_intformat(texFormat);
707
708 /* try common 2D texture cases first */
709 if (!ctx->ImageTransferState && dimensions == 2
710 && srcType == GL_UNSIGNED_BYTE) {
711
712 if (srcFormat == texFormat) {
713 /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
714 * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy().
715 */
716 const GLubyte *src = (const GLubyte *) _mesa_image_address(
717 srcPacking, srcAddr, srcWidth, srcHeight,
718 srcFormat, srcType, 0, 0, 0);
719 const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
720 srcWidth, srcFormat, srcType);
721 const GLint widthInBytes = srcWidth * texComponents;
722 GLubyte *dst = texAddr + dstYoffset * dstRowStride
723 + dstXoffset * texComponents * sizeof(GLubyte);
724 if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) {
725 MEMCPY(dst, src, srcHeight * widthInBytes);
726 }
727 else {
728 GLint i;
729 for (i = 0; i < srcHeight; i++) {
730 MEMCPY(dst, src, widthInBytes);
731 src += srcRowStride;
732 dst += dstRowStride;
733 }
734 }
735 return; /* all done */
736 }
737 else if (srcFormat == GL_RGBA && texFormat == GL_RGB) {
738 /* commonly used by Quake */
739 const GLubyte *src = (const GLubyte *) _mesa_image_address(
740 srcPacking, srcAddr, srcWidth, srcHeight,
741 srcFormat, srcType, 0, 0, 0);
742 const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
743 srcWidth, srcFormat, srcType);
744 GLubyte *dst = texAddr + dstYoffset * dstRowStride
745 + dstXoffset * texComponents * sizeof(GLubyte);
746 GLint i, j;
747 for (i = 0; i < srcHeight; i++) {
748 const GLubyte *s = src;
749 GLubyte *d = dst;
750 for (j = 0; j < srcWidth; j++) {
751 *d++ = *s++; /*red*/
752 *d++ = *s++; /*green*/
753 *d++ = *s++; /*blue*/
754 s++; /*alpha*/
755 }
756 src += srcRowStride;
757 dst += dstRowStride;
758 }
759 return; /* all done */
760 }
761 }
762
763 /*
764 * General case solutions
765 */
766 if (texFormat == GL_COLOR_INDEX) {
767 /* color index texture */
768 const GLenum texType = GL_UNSIGNED_BYTE;
769 GLint img, row;
770 GLubyte *dest = texAddr + dstZoffset * dstImageStride
771 + dstYoffset * dstRowStride
772 + dstXoffset * texComponents * sizeof(GLubyte);
773 for (img = 0; img < srcDepth; img++) {
774 GLubyte *destRow = dest;
775 for (row = 0; row < srcHeight; row++) {
776 const GLvoid *src = _mesa_image_address(srcPacking,
777 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
778 _mesa_unpack_index_span(ctx, srcWidth, texType, destRow,
779 srcType, src, srcPacking,
780 ctx->ImageTransferState);
781 destRow += dstRowStride;
782 }
783 dest += dstImageStride;
784 }
785 }
786 else {
787 /* regular, color texture */
788 if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) ||
789 (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) ||
790 (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) {
791 /*
792 * Fill texture image with convolution
793 */
794 GLint img, row;
795 GLint convWidth = srcWidth, convHeight = srcHeight;
796 GLfloat *tmpImage, *convImage;
797 tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
798 if (!tmpImage) {
799 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
800 return;
801 }
802 convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
803 if (!convImage) {
804 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
805 FREE(tmpImage);
806 return;
807 }
808
809 for (img = 0; img < srcDepth; img++) {
810 const GLfloat *srcf;
811 GLfloat *dstf = tmpImage;
812 GLubyte *dest;
813
814 /* unpack and do transfer ops up to convolution */
815 for (row = 0; row < srcHeight; row++) {
816 const GLvoid *src = _mesa_image_address(srcPacking,
817 srcAddr, srcWidth, srcHeight,
818 srcFormat, srcType, img, row, 0);
819 _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf,
820 srcFormat, srcType, src, srcPacking,
821 ctx->ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
822 GL_TRUE);
823 dstf += srcWidth * 4;
824 }
825
826 /* convolve */
827 if (dimensions == 1) {
828 ASSERT(ctx->Pixel.Convolution1DEnabled);
829 _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
830 }
831 else {
832 if (ctx->Pixel.Convolution2DEnabled) {
833 _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
834 tmpImage, convImage);
835 }
836 else {
837 ASSERT(ctx->Pixel.Separable2DEnabled);
838 _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
839 tmpImage, convImage);
840 }
841 }
842
843 /* packing and transfer ops after convolution */
844 srcf = convImage;
845 dest = texAddr + (dstZoffset + img) * dstImageStride
846 + dstYoffset * dstRowStride;
847 for (row = 0; row < convHeight; row++) {
848 _mesa_pack_float_rgba_span(ctx, convWidth,
849 (const GLfloat (*)[4]) srcf,
850 texFormat, GL_UNSIGNED_BYTE,
851 dest, &_mesa_native_packing,
852 ctx->ImageTransferState
853 & IMAGE_POST_CONVOLUTION_BITS);
854 srcf += convWidth * 4;
855 dest += dstRowStride;
856 }
857 }
858
859 FREE(convImage);
860 FREE(tmpImage);
861 }
862 else {
863 /*
864 * no convolution
865 */
866 GLint img, row;
867 GLubyte *dest = texAddr + dstZoffset * dstImageStride
868 + dstYoffset * dstRowStride
869 + dstXoffset * texComponents * sizeof(GLubyte);
870 for (img = 0; img < srcDepth; img++) {
871 GLubyte *destRow = dest;
872 for (row = 0; row < srcHeight; row++) {
Brian Paul01e54752000-09-05 15:40:34 +0000873 const GLvoid *srcRow = _mesa_image_address(srcPacking,
Brian Paula805bb92000-09-02 17:52:21 +0000874 srcAddr, srcWidth, srcHeight,
875 srcFormat, srcType, img, row, 0);
876 _mesa_unpack_ubyte_color_span(ctx, srcWidth, texFormat, destRow,
Brian Paul01e54752000-09-05 15:40:34 +0000877 srcFormat, srcType, srcRow, srcPacking,
Brian Paula805bb92000-09-02 17:52:21 +0000878 ctx->ImageTransferState);
879 destRow += dstRowStride;
880 }
881 dest += dstImageStride;
882 }
883 }
884 }
885}
886
887
888
jtgafb833d1999-08-19 00:55:39 +0000889/* Need this to prevent an out-of-bounds memory access when using
890 * X86 optimized code.
891 */
892#ifdef USE_X86_ASM
893# define EXTRA_BYTE 1
894#else
895# define EXTRA_BYTE 0
896#endif
897
898
Brian Paulc3f0a511999-11-03 17:27:05 +0000899
jtgafb833d1999-08-19 00:55:39 +0000900/*
Brian Paul43911c82000-03-21 00:49:33 +0000901 * Called by glTexImage[123]D. Fill in a texture image with data given
902 * by the client. All pixel transfer and unpack modes are handled here.
Brian Paul5a0d3dc2000-08-31 15:24:39 +0000903 * Input: dimensions (1, 2, or 3)
904 * texImage - destination texture image (we'll malloc the memory)
905 * width, height, depth - size of source image
906 * srcFormat, srcType - source image format and type
907 * pixels - source image data
908 * srcPacking - source image packing parameters
909 *
Brian Paul43911c82000-03-21 00:49:33 +0000910 * NOTE: All texture image parameters should have already been error checked.
Brian Paul5a0d3dc2000-08-31 15:24:39 +0000911 *
912 * NOTE: the texImage dimensions and source image dimensions must be correct
913 * with respect to convolution with border mode = reduce.
jtgafb833d1999-08-19 00:55:39 +0000914 */
Brian Paul43911c82000-03-21 00:49:33 +0000915static void
Brian Paulf93b3dd2000-08-30 18:22:28 +0000916make_texture_image( GLcontext *ctx, GLuint dimensions,
Brian Paul43911c82000-03-21 00:49:33 +0000917 struct gl_texture_image *texImage,
Brian Paul5a0d3dc2000-08-31 15:24:39 +0000918 GLint width, GLint height, GLint depth,
Brian Paulc3f0a511999-11-03 17:27:05 +0000919 GLenum srcFormat, GLenum srcType, const GLvoid *pixels,
Brian Paulf93b3dd2000-08-30 18:22:28 +0000920 const struct gl_pixelstore_attrib *srcPacking)
jtgafb833d1999-08-19 00:55:39 +0000921{
Brian Paula805bb92000-09-02 17:52:21 +0000922 const GLint internalFormat = texImage->IntFormat;
923 const GLint components = components_in_intformat(internalFormat);
924 GLint convWidth = width, convHeight = height;
jtgafb833d1999-08-19 00:55:39 +0000925
Brian Paula805bb92000-09-02 17:52:21 +0000926 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE) {
927 _mesa_update_image_transfer_state(ctx);
928 }
jtgafb833d1999-08-19 00:55:39 +0000929
Brian Paula805bb92000-09-02 17:52:21 +0000930 if (ctx->ImageTransferState & IMAGE_CONVOLUTION_BIT) {
931 adjust_texture_size_for_convolution(ctx, dimensions,
932 &convWidth, &convHeight);
933 }
Brian Paul43911c82000-03-21 00:49:33 +0000934
Brian Paula805bb92000-09-02 17:52:21 +0000935 texImage->Data = (GLubyte *) MALLOC(convWidth * convHeight * depth
936 * components + EXTRA_BYTE);
Brian Paul43911c82000-03-21 00:49:33 +0000937 if (!texImage->Data)
938 return; /* out of memory */
Brian Paulc3f0a511999-11-03 17:27:05 +0000939
Brian Paula805bb92000-09-02 17:52:21 +0000940 fill_texture_image(ctx, dimensions, texImage->Format, texImage->Data,
941 width, height, depth, 0, 0, 0,
942 convWidth * components * sizeof(GLubyte),
943 convWidth * convHeight * components * sizeof(GLubyte),
944 srcFormat, srcType, pixels, srcPacking);
jtgafb833d1999-08-19 00:55:39 +0000945}
946
947
948
949/*
950 * glTexImage[123]D can accept a NULL image pointer. In this case we
951 * create a texture image with unspecified image contents per the OpenGL
Brian Paul43911c82000-03-21 00:49:33 +0000952 * spec. This function creates an empty image for the given texture image.
jtgafb833d1999-08-19 00:55:39 +0000953 */
Brian Paul43911c82000-03-21 00:49:33 +0000954static void
955make_null_texture( struct gl_texture_image *texImage )
jtgafb833d1999-08-19 00:55:39 +0000956{
957 GLint components;
jtgafb833d1999-08-19 00:55:39 +0000958 GLint numPixels;
jtgafb833d1999-08-19 00:55:39 +0000959
Brian Paul43911c82000-03-21 00:49:33 +0000960 ASSERT(texImage);
961 ASSERT(!texImage->Data);
jtgafb833d1999-08-19 00:55:39 +0000962
Brian Paul43911c82000-03-21 00:49:33 +0000963 components = components_in_intformat(texImage->IntFormat);
964 numPixels = texImage->Width * texImage->Height * texImage->Depth;
jtgafb833d1999-08-19 00:55:39 +0000965
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000966 texImage->Data = (GLubyte *) MALLOC( numPixels * components + EXTRA_BYTE );
jtgafb833d1999-08-19 00:55:39 +0000967
968 /*
969 * Let's see if anyone finds this. If glTexImage2D() is called with
970 * a NULL image pointer then load the texture image with something
971 * interesting instead of leaving it indeterminate.
972 */
973 if (texImage->Data) {
Brian Paul65d54602000-03-01 23:28:20 +0000974 static const char message[8][32] = {
jtgafb833d1999-08-19 00:55:39 +0000975 " X X XXXXX XXX X ",
976 " XX XX X X X X X ",
977 " X X X X X X X ",
978 " X X XXXX XXX XXXXX ",
979 " X X X X X X ",
980 " X X X X X X X ",
981 " X X XXXXX XXX X X ",
982 " "
983 };
984
985 GLubyte *imgPtr = texImage->Data;
986 GLint i, j, k;
Brian Paul43911c82000-03-21 00:49:33 +0000987 for (i = 0; i < texImage->Height; i++) {
jtgafb833d1999-08-19 00:55:39 +0000988 GLint srcRow = 7 - i % 8;
Brian Paul43911c82000-03-21 00:49:33 +0000989 for (j = 0; j < texImage->Width; j++) {
jtgafb833d1999-08-19 00:55:39 +0000990 GLint srcCol = j % 32;
Brian Paul5b37c321999-11-05 06:43:10 +0000991 GLint texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
jtgafb833d1999-08-19 00:55:39 +0000992 for (k=0;k<components;k++) {
Brian Paul5b37c321999-11-05 06:43:10 +0000993 *imgPtr++ = (GLubyte) texel;
jtgafb833d1999-08-19 00:55:39 +0000994 }
995 }
996 }
997 }
jtgafb833d1999-08-19 00:55:39 +0000998}
999
1000
1001
1002/*
Brian Paul9c272782000-09-05 22:04:30 +00001003 * This is called when a proxy texture test fails, we set all the
1004 * image members (except DriverData) to zero.
1005 */
1006static void
1007clear_proxy_teximage(struct gl_texture_image *img)
1008{
1009 ASSERT(img);
1010 img->Format = 0;
1011 img->IntFormat = 0;
1012 img->RedBits = 0;
1013 img->GreenBits = 0;
1014 img->BlueBits = 0;
1015 img->AlphaBits = 0;
1016 img->IntensityBits = 0;
1017 img->LuminanceBits = 0;
1018 img->IndexBits = 0;
1019 img->Border = 0;
1020 img->Width = 0;
1021 img->Height = 0;
1022 img->Depth = 0;
1023 img->Width2 = 0;
1024 img->Height2 = 0;
1025 img->Depth2 = 0;
1026 img->WidthLog2 = 0;
1027 img->HeightLog2 = 0;
1028 img->DepthLog2 = 0;
1029 img->Data = NULL;
1030 img->IsCompressed = 0;
1031 img->CompressedSize = 0;
1032}
1033
1034
1035
1036/*
Brian Paulc3f0a511999-11-03 17:27:05 +00001037 * Test glTexImage[123]D() parameters for errors.
jtgafb833d1999-08-19 00:55:39 +00001038 * Input:
1039 * dimensions - must be 1 or 2 or 3
1040 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
1041 */
Brian Paulc3f0a511999-11-03 17:27:05 +00001042static GLboolean
1043texture_error_check( GLcontext *ctx, GLenum target,
1044 GLint level, GLint internalFormat,
1045 GLenum format, GLenum type,
Brian Paul5b37c321999-11-05 06:43:10 +00001046 GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +00001047 GLint width, GLint height,
1048 GLint depth, GLint border )
jtgafb833d1999-08-19 00:55:39 +00001049{
1050 GLboolean isProxy;
1051 GLint iformat;
1052
1053 if (dimensions == 1) {
Brian Paul5b37c321999-11-05 06:43:10 +00001054 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D);
jtgafb833d1999-08-19 00:55:39 +00001055 if (target != GL_TEXTURE_1D && !isProxy) {
1056 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
1057 return GL_TRUE;
1058 }
1059 }
1060 else if (dimensions == 2) {
Brian Paul5b37c321999-11-05 06:43:10 +00001061 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D);
Brian Paul413d6a22000-05-26 14:44:59 +00001062 if (target != GL_TEXTURE_2D && !isProxy &&
1063 !(ctx->Extensions.HaveTextureCubeMap &&
1064 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1065 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
jtgafb833d1999-08-19 00:55:39 +00001066 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
1067 return GL_TRUE;
1068 }
1069 }
1070 else if (dimensions == 3) {
Brian Paul5b37c321999-11-05 06:43:10 +00001071 isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D);
jtgafb833d1999-08-19 00:55:39 +00001072 if (target != GL_TEXTURE_3D && !isProxy) {
1073 gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
1074 return GL_TRUE;
1075 }
1076 }
1077 else {
1078 gl_problem( ctx, "bad dims in texture_error_check" );
1079 return GL_TRUE;
1080 }
1081
1082 /* Border */
Brian Paul9fd2b0a2000-03-24 23:59:06 +00001083 if (border != 0 && border != 1) {
jtgafb833d1999-08-19 00:55:39 +00001084 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001085 char message[100];
1086 sprintf(message, "glTexImage%dD(border)", dimensions);
1087 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +00001088 }
1089 return GL_TRUE;
1090 }
1091
1092 /* Width */
1093 if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
1094 || logbase2( width - 2 * border ) < 0) {
1095 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001096 char message[100];
1097 sprintf(message, "glTexImage%dD(width)", dimensions);
1098 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +00001099 }
1100 return GL_TRUE;
1101 }
1102
1103 /* Height */
1104 if (dimensions >= 2) {
1105 if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
1106 || logbase2( height - 2 * border ) < 0) {
1107 if (!isProxy) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001108 char message[100];
1109 sprintf(message, "glTexImage%dD(height)", dimensions);
1110 gl_error(ctx, GL_INVALID_VALUE, message);
jtgafb833d1999-08-19 00:55:39 +00001111 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001112 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001113 }
1114 }
1115
Brian Paulad817702000-05-30 00:27:24 +00001116 /* For cube map, width must equal height */
1117 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1118 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
1119 if (width != height) {
1120 if (!isProxy) {
1121 gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)");
1122 }
1123 return GL_TRUE;
1124 }
1125 }
1126
jtgafb833d1999-08-19 00:55:39 +00001127 /* Depth */
1128 if (dimensions >= 3) {
1129 if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize
1130 || logbase2( depth - 2 * border ) < 0) {
1131 if (!isProxy) {
1132 gl_error( ctx, GL_INVALID_VALUE, "glTexImage3D(depth)" );
1133 }
1134 return GL_TRUE;
1135 }
1136 }
1137
1138 /* Level */
Brian Paul9fd2b0a2000-03-24 23:59:06 +00001139 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001140 if (!isProxy) {
1141 char message[100];
1142 sprintf(message, "glTexImage%dD(level)", dimensions);
1143 gl_error(ctx, GL_INVALID_VALUE, message);
1144 }
jtgafb833d1999-08-19 00:55:39 +00001145 return GL_TRUE;
1146 }
1147
Brian Paulaea66b12000-05-24 14:04:06 +00001148 iformat = _mesa_base_tex_format( ctx, internalFormat );
jtgafb833d1999-08-19 00:55:39 +00001149 if (iformat < 0) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001150 if (!isProxy) {
1151 char message[100];
1152 sprintf(message, "glTexImage%dD(internalFormat)", dimensions);
1153 gl_error(ctx, GL_INVALID_VALUE, message);
1154 }
jtgafb833d1999-08-19 00:55:39 +00001155 return GL_TRUE;
1156 }
1157
Brian Paul289d47e2000-08-29 23:31:23 +00001158 if (!is_compressed_format(ctx, internalFormat)) {
Brian Paulaea66b12000-05-24 14:04:06 +00001159 if (!_mesa_is_legal_format_and_type( format, type )) {
1160 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1161 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1162 */
1163 if (!isProxy) {
1164 char message[100];
1165 sprintf(message, "glTexImage%dD(format or type)", dimensions);
1166 gl_error(ctx, GL_INVALID_OPERATION, message);
1167 }
1168 return GL_TRUE;
Brian Paulc3f0a511999-11-03 17:27:05 +00001169 }
jtgafb833d1999-08-19 00:55:39 +00001170 }
1171
1172 /* if we get here, the parameters are OK */
1173 return GL_FALSE;
1174}
1175
1176
1177
1178/*
Brian Paulc3f0a511999-11-03 17:27:05 +00001179 * Test glTexSubImage[123]D() parameters for errors.
1180 * Input:
1181 * dimensions - must be 1 or 2 or 3
1182 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
1183 */
1184static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +00001185subtexture_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +00001186 GLenum target, GLint level,
1187 GLint xoffset, GLint yoffset, GLint zoffset,
1188 GLint width, GLint height, GLint depth,
1189 GLenum format, GLenum type )
1190{
1191 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1192 struct gl_texture_image *destTex;
1193
1194 if (dimensions == 1) {
1195 if (target != GL_TEXTURE_1D) {
1196 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" );
1197 return GL_TRUE;
1198 }
1199 }
1200 else if (dimensions == 2) {
Brian Paulfc4b4432000-05-23 15:17:12 +00001201 if (ctx->Extensions.HaveTextureCubeMap) {
1202 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
1203 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
1204 target != GL_TEXTURE_2D) {
1205 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1206 return GL_TRUE;
1207 }
1208 }
1209 else if (target != GL_TEXTURE_2D) {
Brian Paulc3f0a511999-11-03 17:27:05 +00001210 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1211 return GL_TRUE;
1212 }
1213 }
1214 else if (dimensions == 3) {
1215 if (target != GL_TEXTURE_3D) {
1216 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" );
1217 return GL_TRUE;
1218 }
1219 }
1220 else {
1221 gl_problem( ctx, "bad dims in texture_error_check" );
1222 return GL_TRUE;
1223 }
1224
1225 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
1226 gl_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level)");
1227 return GL_TRUE;
1228 }
1229
1230 if (width < 0) {
1231 char message[100];
1232 sprintf(message, "glTexSubImage%dD(width)", dimensions);
1233 gl_error(ctx, GL_INVALID_VALUE, message);
1234 return GL_TRUE;
1235 }
1236 if (height < 0 && dimensions > 1) {
1237 char message[100];
1238 sprintf(message, "glTexSubImage%dD(height)", dimensions);
1239 gl_error(ctx, GL_INVALID_VALUE, message);
1240 return GL_TRUE;
1241 }
1242 if (depth < 0 && dimensions > 2) {
1243 char message[100];
1244 sprintf(message, "glTexSubImage%dD(depth)", dimensions);
1245 gl_error(ctx, GL_INVALID_VALUE, message);
1246 return GL_TRUE;
1247 }
1248
1249 destTex = texUnit->CurrentD[2]->Image[level];
1250 if (!destTex) {
1251 gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D");
1252 return GL_TRUE;
1253 }
1254
1255 if (xoffset < -((GLint)destTex->Border)) {
1256 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)");
1257 return GL_TRUE;
1258 }
1259 if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
1260 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)");
1261 return GL_TRUE;
1262 }
1263 if (dimensions > 1) {
1264 if (yoffset < -((GLint)destTex->Border)) {
1265 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)");
1266 return GL_TRUE;
1267 }
1268 if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
1269 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)");
1270 return GL_TRUE;
1271 }
1272 }
1273 if (dimensions > 2) {
1274 if (zoffset < -((GLint)destTex->Border)) {
1275 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
1276 return GL_TRUE;
1277 }
1278 if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) {
1279 gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
1280 return GL_TRUE;
1281 }
1282 }
1283
Brian Paul289d47e2000-08-29 23:31:23 +00001284 if (!is_compressed_format(ctx, destTex->IntFormat)) {
Brian Paul9540a1d2000-06-06 17:03:38 +00001285 if (!_mesa_is_legal_format_and_type(format, type)) {
1286 char message[100];
1287 sprintf(message, "glTexSubImage%dD(format or type)", dimensions);
1288 gl_error(ctx, GL_INVALID_ENUM, message);
1289 return GL_TRUE;
1290 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001291 }
1292
1293 return GL_FALSE;
1294}
1295
1296
1297/*
1298 * Test glCopyTexImage[12]D() parameters for errors.
1299 * Input: dimensions - must be 1 or 2 or 3
1300 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
1301 */
1302static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +00001303copytexture_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +00001304 GLenum target, GLint level, GLint internalFormat,
1305 GLint width, GLint height, GLint border )
1306{
1307 GLint iformat;
1308
Brian Paulfc4b4432000-05-23 15:17:12 +00001309 if (dimensions == 1) {
1310 if (target != GL_TEXTURE_1D) {
1311 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" );
1312 return GL_TRUE;
1313 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001314 }
Brian Paulfc4b4432000-05-23 15:17:12 +00001315 else if (dimensions == 2) {
1316 if (ctx->Extensions.HaveTextureCubeMap) {
1317 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
1318 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
1319 target != GL_TEXTURE_2D) {
1320 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1321 return GL_TRUE;
1322 }
1323 }
1324 else if (target != GL_TEXTURE_2D) {
1325 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1326 return GL_TRUE;
1327 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001328 }
1329
1330 /* Border */
1331 if (border!=0 && border!=1) {
1332 char message[100];
1333 sprintf(message, "glCopyTexImage%dD(border)", dimensions);
1334 gl_error(ctx, GL_INVALID_VALUE, message);
1335 return GL_TRUE;
1336 }
1337
1338 /* Width */
1339 if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
1340 || logbase2( width - 2 * border ) < 0) {
1341 char message[100];
1342 sprintf(message, "glCopyTexImage%dD(width)", dimensions);
1343 gl_error(ctx, GL_INVALID_VALUE, message);
1344 return GL_TRUE;
1345 }
1346
1347 /* Height */
1348 if (dimensions >= 2) {
1349 if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
1350 || logbase2( height - 2 * border ) < 0) {
1351 char message[100];
1352 sprintf(message, "glCopyTexImage%dD(height)", dimensions);
1353 gl_error(ctx, GL_INVALID_VALUE, message);
1354 return GL_TRUE;
1355 }
1356 }
1357
Brian Paulad817702000-05-30 00:27:24 +00001358 /* For cube map, width must equal height */
1359 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1360 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
1361 if (width != height) {
1362 gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)");
1363 return GL_TRUE;
1364 }
1365 }
1366
Brian Paulc3f0a511999-11-03 17:27:05 +00001367 /* Level */
1368 if (level<0 || level>=ctx->Const.MaxTextureLevels) {
1369 char message[100];
1370 sprintf(message, "glCopyTexImage%dD(level)", dimensions);
1371 gl_error(ctx, GL_INVALID_VALUE, message);
1372 return GL_TRUE;
1373 }
1374
Brian Paulaea66b12000-05-24 14:04:06 +00001375 iformat = _mesa_base_tex_format( ctx, internalFormat );
Brian Paulc3f0a511999-11-03 17:27:05 +00001376 if (iformat < 0) {
1377 char message[100];
1378 sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions);
1379 gl_error(ctx, GL_INVALID_VALUE, message);
1380 return GL_TRUE;
1381 }
1382
1383 /* if we get here, the parameters are OK */
1384 return GL_FALSE;
1385}
1386
1387
1388static GLboolean
Brian Paulfbd8f211999-11-11 01:22:25 +00001389copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
Brian Paulc3f0a511999-11-03 17:27:05 +00001390 GLenum target, GLint level,
1391 GLint xoffset, GLint yoffset, GLint zoffset,
Brian Paul5b37c321999-11-05 06:43:10 +00001392 GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +00001393{
1394 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1395 struct gl_texture_image *teximage;
1396
Brian Paulfc4b4432000-05-23 15:17:12 +00001397 if (dimensions == 1) {
1398 if (target != GL_TEXTURE_1D) {
1399 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
1400 return GL_TRUE;
1401 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001402 }
Brian Paulfc4b4432000-05-23 15:17:12 +00001403 else if (dimensions == 2) {
1404 if (ctx->Extensions.HaveTextureCubeMap) {
1405 if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ||
1406 target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) &&
1407 target != GL_TEXTURE_2D) {
1408 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1409 return GL_TRUE;
1410 }
1411 }
1412 else if (target != GL_TEXTURE_2D) {
1413 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1414 return GL_TRUE;
1415 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001416 }
Brian Paulfc4b4432000-05-23 15:17:12 +00001417 else if (dimensions == 3) {
1418 if (target != GL_TEXTURE_3D) {
1419 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" );
1420 return GL_TRUE;
1421 }
Brian Paulc3f0a511999-11-03 17:27:05 +00001422 }
1423
1424 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
1425 char message[100];
1426 sprintf(message, "glCopyTexSubImage%dD(level)", dimensions);
1427 gl_error(ctx, GL_INVALID_VALUE, message);
1428 return GL_TRUE;
1429 }
1430
1431 if (width < 0) {
1432 char message[100];
1433 sprintf(message, "glCopyTexSubImage%dD(width)", dimensions );
1434 gl_error(ctx, GL_INVALID_VALUE, message);
1435 return GL_TRUE;
1436 }
1437 if (dimensions > 1 && height < 0) {
1438 char message[100];
1439 sprintf(message, "glCopyTexSubImage%dD(height)", dimensions );
1440 gl_error(ctx, GL_INVALID_VALUE, message);
1441 return GL_TRUE;
1442 }
1443
Brian Pauldf6a28d2000-02-21 16:34:21 +00001444 teximage = texUnit->CurrentD[dimensions]->Image[level];
Brian Paulc3f0a511999-11-03 17:27:05 +00001445 if (!teximage) {
1446 char message[100];
1447 sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions);
1448 gl_error(ctx, GL_INVALID_OPERATION, message);
1449 return GL_TRUE;
1450 }
1451
1452 if (xoffset < -((GLint)teximage->Border)) {
1453 char message[100];
1454 sprintf(message, "glCopyTexSubImage%dD(xoffset)", dimensions);
1455 gl_error(ctx, GL_INVALID_VALUE, message);
1456 return GL_TRUE;
1457 }
1458 if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) {
1459 char message[100];
1460 sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions);
1461 gl_error(ctx, GL_INVALID_VALUE, message);
1462 return GL_TRUE;
1463 }
1464 if (dimensions > 1) {
1465 if (yoffset < -((GLint)teximage->Border)) {
1466 char message[100];
1467 sprintf(message, "glCopyTexSubImage%dD(yoffset)", dimensions);
1468 gl_error(ctx, GL_INVALID_VALUE, message);
1469 return GL_TRUE;
1470 }
1471 /* NOTE: we're adding the border here, not subtracting! */
1472 if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) {
1473 char message[100];
1474 sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions);
1475 gl_error(ctx, GL_INVALID_VALUE, message);
1476 return GL_TRUE;
1477 }
1478 }
1479
1480 if (dimensions > 2) {
1481 if (zoffset < -((GLint)teximage->Border)) {
1482 char message[100];
1483 sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions);
1484 gl_error(ctx, GL_INVALID_VALUE, message);
1485 return GL_TRUE;
1486 }
1487 if (zoffset > (GLint) (teximage->Depth+teximage->Border)) {
1488 char message[100];
1489 sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
1490 gl_error(ctx, GL_INVALID_VALUE, message);
1491 return GL_TRUE;
1492 }
1493 }
1494
1495 /* if we get here, the parameters are OK */
1496 return GL_FALSE;
1497}
1498
1499
1500
1501
1502/*
Brian Paul289d47e2000-08-29 23:31:23 +00001503 * Turn generic compressed formats into specific compressed format.
1504 * Some of the compressed formats we don't support, so we
1505 * fall back to the uncompressed format. (See issue 15 of
1506 * the GL_ARB_texture_compression specification.)
1507 */
1508static GLint
1509get_specific_compressed_tex_format(GLcontext *ctx,
1510 GLint ifmt, GLint numDimensions)
1511{
1512 char message[100];
1513 GLint internalFormat = ifmt;
1514
1515 if (ctx->Extensions.HaveTextureCompression
1516 && ctx->Driver.SpecificCompressedTexFormat) {
1517 /*
1518 * First, ask the driver for the specific format.
1519 */
1520 switch (internalFormat) {
1521 case GL_COMPRESSED_ALPHA_ARB:
1522 case GL_COMPRESSED_LUMINANCE_ARB:
1523 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1524 case GL_COMPRESSED_INTENSITY_ARB:
1525 case GL_COMPRESSED_RGB_ARB:
1526 case GL_COMPRESSED_RGBA_ARB:
1527 internalFormat = (*ctx->Driver.SpecificCompressedTexFormat)
1528 (ctx, internalFormat, numDimensions);
1529 /* XXX shouldn't we return now? */
1530 break;
1531 default:
1532 /* silence compiler warnings */
1533 ;
1534 }
1535 }
1536
1537 /*
1538 * Now, convert any generic format left to an uncompressed
1539 * specific format. If the driver does not support compression
1540 * of the format, we must drop back to the uncompressed format.
1541 * See issue 15 of the GL_ARB_texture_compression specification.
1542 */
1543 switch (internalFormat) {
1544 case GL_COMPRESSED_ALPHA_ARB:
1545 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1546 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1547 gl_error(ctx, GL_INVALID_VALUE, message);
1548 return -1;
1549 }
1550 internalFormat = GL_ALPHA;
1551 break;
1552 case GL_COMPRESSED_LUMINANCE_ARB:
1553 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1554 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1555 gl_error(ctx, GL_INVALID_VALUE, message);
1556 return -1;
1557 }
1558 internalFormat = GL_LUMINANCE;
1559 break;
1560 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1561 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1562 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1563 gl_error(ctx, GL_INVALID_VALUE, message);
1564 return -1;
1565 }
1566 internalFormat = GL_LUMINANCE_ALPHA;
1567 break;
1568 case GL_COMPRESSED_INTENSITY_ARB:
1569 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1570 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1571 gl_error(ctx, GL_INVALID_VALUE, message);
1572 return -1;
1573 }
1574 internalFormat = GL_INTENSITY;
1575 break;
1576 case GL_COMPRESSED_RGB_ARB:
1577 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1578 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1579 gl_error(ctx, GL_INVALID_VALUE, message);
1580 return -1;
1581 }
1582 internalFormat = GL_RGB;
1583 break;
1584 case GL_COMPRESSED_RGBA_ARB:
1585 if (ctx && !ctx->Extensions.HaveTextureCompression) {
1586 sprintf(message, "glTexImage%dD(internalFormat)", numDimensions);
1587 gl_error(ctx, GL_INVALID_VALUE, message);
1588 return -1;
1589 }
1590 internalFormat = GL_RGBA;
1591 break;
1592 default:
Brian Paulf93b3dd2000-08-30 18:22:28 +00001593 /* silence compiler warning */
1594 ;
Brian Paul289d47e2000-08-29 23:31:23 +00001595 }
1596 return internalFormat;
1597}
1598
1599
1600
1601/*
jtgafb833d1999-08-19 00:55:39 +00001602 * Called from the API. Note that width includes the border.
1603 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001604void
Brian Paul43911c82000-03-21 00:49:33 +00001605_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
Brian Paulfbd8f211999-11-11 01:22:25 +00001606 GLsizei width, GLint border, GLenum format,
1607 GLenum type, const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001608{
Brian Paulf93b3dd2000-08-30 18:22:28 +00001609 GLsizei postConvWidth;
Brian Paulfbd8f211999-11-11 01:22:25 +00001610 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001611 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage1D");
1612
Brian Paulf93b3dd2000-08-30 18:22:28 +00001613 postConvWidth = width;
1614 adjust_texture_size_for_convolution(ctx, 1, &postConvWidth, NULL);
1615
jtgafb833d1999-08-19 00:55:39 +00001616 if (target==GL_TEXTURE_1D) {
Brian Paulf7b57072000-03-20 14:37:52 +00001617 struct gl_texture_unit *texUnit;
Brian Paul02938782000-03-22 17:38:11 +00001618 struct gl_texture_object *texObj;
1619 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00001620 GLint ifmt;
1621
1622 ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 1);
1623 if (ifmt < 0) {
1624 /*
1625 * The error here is that we were sent a generic compressed
1626 * format, but the extension is not supported.
1627 */
1628 return;
1629 }
1630 else {
1631 internalFormat = ifmt;
1632 }
Brian Paulf7b57072000-03-20 14:37:52 +00001633
Brian Paulaea66b12000-05-24 14:04:06 +00001634 if (texture_error_check(ctx, target, level, internalFormat,
Brian Paulf93b3dd2000-08-30 18:22:28 +00001635 format, type, 1, postConvWidth, 1, 1, border)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001636 return; /* error in texture image was detected */
jtgafb833d1999-08-19 00:55:39 +00001637 }
1638
Brian Paulf7b57072000-03-20 14:37:52 +00001639 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul02938782000-03-22 17:38:11 +00001640 texObj = texUnit->CurrentD[1];
1641 texImage = texObj->Image[level];
Brian Paulf7b57072000-03-20 14:37:52 +00001642
Brian Paul02938782000-03-22 17:38:11 +00001643 if (!texImage) {
Brian Paul021a5252000-03-27 17:54:17 +00001644 texImage = _mesa_alloc_texture_image();
Brian Paul02938782000-03-22 17:38:11 +00001645 texObj->Image[level] = texImage;
1646 if (!texImage) {
1647 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
1648 return;
1649 }
1650 }
1651 else if (texImage->Data) {
1652 FREE(texImage->Data);
1653 texImage->Data = NULL;
jtgafb833d1999-08-19 00:55:39 +00001654 }
1655
Brian Paul02938782000-03-22 17:38:11 +00001656 /* setup the teximage struct's fields */
Brian Paulf93b3dd2000-08-30 18:22:28 +00001657 init_texture_image(ctx, texImage, postConvWidth, 1, 1, border, internalFormat);
Brian Paul43911c82000-03-21 00:49:33 +00001658
Brian Paulfa4525e2000-08-21 14:22:24 +00001659 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
1660 _mesa_update_image_transfer_state(ctx);
1661
Brian Paul02938782000-03-22 17:38:11 +00001662 /* process the texture image */
Brian Paulc3f0a511999-11-03 17:27:05 +00001663 if (pixels) {
Brian Paul02938782000-03-22 17:38:11 +00001664 GLboolean retain = GL_TRUE;
1665 GLboolean success = GL_FALSE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001666 if (!ctx->ImageTransferState && ctx->Driver.TexImage1D) {
Brian Paul02938782000-03-22 17:38:11 +00001667 /* let device driver try to use raw image */
1668 success = (*ctx->Driver.TexImage1D)( ctx, target, level, format,
1669 type, pixels, &ctx->Unpack,
1670 texObj, texImage, &retain);
1671 }
1672 if (retain || !success) {
1673 /* make internal copy of the texture image */
Brian Paul5a0d3dc2000-08-31 15:24:39 +00001674 make_texture_image(ctx, 1, texImage, width, 1, 1,
1675 format, type, pixels, &ctx->Unpack);
Brian Paul02938782000-03-22 17:38:11 +00001676 if (!success && ctx->Driver.TexImage1D) {
1677 /* let device driver try to use unpacked image */
1678 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
1679 GL_UNSIGNED_BYTE, texImage->Data,
1680 &_mesa_native_packing,
1681 texObj, texImage, &retain);
1682 }
1683 }
1684 if (!retain && texImage->Data) {
1685 FREE(texImage->Data);
1686 texImage->Data = NULL;
1687 }
jtgafb833d1999-08-19 00:55:39 +00001688 }
1689 else {
Brian Paul02938782000-03-22 17:38:11 +00001690 make_null_texture(texImage);
1691 if (ctx->Driver.TexImage1D) {
1692 GLboolean retain;
1693 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
1694 GL_UNSIGNED_BYTE, texImage->Data,
1695 &_mesa_native_packing,
1696 texObj, texImage, &retain);
1697 }
jtgafb833d1999-08-19 00:55:39 +00001698 }
1699
Brian Paul02938782000-03-22 17:38:11 +00001700 /* state update */
1701 gl_put_texobj_on_dirty_list( ctx, texObj );
jtgafb833d1999-08-19 00:55:39 +00001702 ctx->NewState |= NEW_TEXTURING;
jtgafb833d1999-08-19 00:55:39 +00001703 }
1704 else if (target==GL_PROXY_TEXTURE_1D) {
1705 /* Proxy texture: check for errors and update proxy state */
Brian Paulaea66b12000-05-24 14:04:06 +00001706 if (texture_error_check(ctx, target, level, internalFormat,
Brian Paulf93b3dd2000-08-30 18:22:28 +00001707 format, type, 1, postConvWidth, 1, 1, border)) {
Brian Paulaea66b12000-05-24 14:04:06 +00001708 /* if error, clear all proxy texture image parameters */
jtgafb833d1999-08-19 00:55:39 +00001709 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00001710 clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]);
jtgafb833d1999-08-19 00:55:39 +00001711 }
1712 }
1713 else {
Brian Paulaea66b12000-05-24 14:04:06 +00001714 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00001715 init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00001716 width, 1, 1, border, internalFormat);
jtgafb833d1999-08-19 00:55:39 +00001717 }
jtgafb833d1999-08-19 00:55:39 +00001718 }
1719 else {
1720 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
1721 return;
1722 }
1723}
1724
1725
Brian Paulfbd8f211999-11-11 01:22:25 +00001726void
Brian Paul43911c82000-03-21 00:49:33 +00001727_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
Brian Paulfbd8f211999-11-11 01:22:25 +00001728 GLsizei width, GLsizei height, GLint border,
1729 GLenum format, GLenum type,
1730 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001731{
Brian Paulf93b3dd2000-08-30 18:22:28 +00001732 GLsizei postConvWidth, postConvHeight;
Brian Paulfbd8f211999-11-11 01:22:25 +00001733 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00001734 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage2D");
1735
Brian Paulf93b3dd2000-08-30 18:22:28 +00001736 postConvWidth = width;
1737 postConvHeight = height;
1738 adjust_texture_size_for_convolution(ctx, 2, &postConvWidth,&postConvHeight);
1739
Brian Paulfc4b4432000-05-23 15:17:12 +00001740 if (target==GL_TEXTURE_2D ||
1741 (ctx->Extensions.HaveTextureCubeMap &&
1742 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1743 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001744 struct gl_texture_unit *texUnit;
Brian Paul02938782000-03-22 17:38:11 +00001745 struct gl_texture_object *texObj;
1746 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00001747 GLint ifmt;
1748
1749 ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 2);
1750 if (ifmt < 0) {
1751 /*
1752 * The error here is that we were sent a generic compressed
1753 * format, but the extension is not supported.
1754 */
1755 return;
1756 }
1757 else {
1758 internalFormat = ifmt;
1759 }
Brian Paulf7b57072000-03-20 14:37:52 +00001760
Brian Paulaea66b12000-05-24 14:04:06 +00001761 if (texture_error_check(ctx, target, level, internalFormat,
Brian Paulf93b3dd2000-08-30 18:22:28 +00001762 format, type, 2, postConvWidth, postConvHeight,
1763 1, border)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001764 return; /* error in texture image was detected */
jtgafb833d1999-08-19 00:55:39 +00001765 }
1766
Brian Paulf7b57072000-03-20 14:37:52 +00001767 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul35d53012000-05-23 17:14:49 +00001768 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paulfc4b4432000-05-23 15:17:12 +00001769 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulf7b57072000-03-20 14:37:52 +00001770
Brian Paul02938782000-03-22 17:38:11 +00001771 if (!texImage) {
Brian Paul021a5252000-03-27 17:54:17 +00001772 texImage = _mesa_alloc_texture_image();
Brian Paulfc4b4432000-05-23 15:17:12 +00001773 set_tex_image(texObj, target, level, texImage);
1774 /*texObj->Image[level] = texImage;*/
Brian Paul02938782000-03-22 17:38:11 +00001775 if (!texImage) {
1776 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1777 return;
1778 }
1779 }
1780 else if (texImage->Data) {
1781 FREE(texImage->Data);
1782 texImage->Data = NULL;
jtgafb833d1999-08-19 00:55:39 +00001783 }
1784
Brian Paul02938782000-03-22 17:38:11 +00001785 /* setup the teximage struct's fields */
Brian Paulf93b3dd2000-08-30 18:22:28 +00001786 init_texture_image(ctx, texImage, postConvWidth, postConvHeight,
Brian Paul289d47e2000-08-29 23:31:23 +00001787 1, border, internalFormat);
Brian Paul43911c82000-03-21 00:49:33 +00001788
Brian Paulfa4525e2000-08-21 14:22:24 +00001789 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
1790 _mesa_update_image_transfer_state(ctx);
1791
Brian Paul02938782000-03-22 17:38:11 +00001792 /* process the texture image */
Brian Paulc3f0a511999-11-03 17:27:05 +00001793 if (pixels) {
Brian Paul02938782000-03-22 17:38:11 +00001794 GLboolean retain = GL_TRUE;
1795 GLboolean success = GL_FALSE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001796 if (!ctx->ImageTransferState && ctx->Driver.TexImage2D) {
Brian Paul02938782000-03-22 17:38:11 +00001797 /* let device driver try to use raw image */
1798 success = (*ctx->Driver.TexImage2D)( ctx, target, level, format,
1799 type, pixels, &ctx->Unpack,
1800 texObj, texImage, &retain);
1801 }
1802 if (retain || !success) {
1803 /* make internal copy of the texture image */
Brian Paul5a0d3dc2000-08-31 15:24:39 +00001804 make_texture_image(ctx, 2, texImage, width, height, 1,
1805 format, type, pixels, &ctx->Unpack);
Brian Paul02938782000-03-22 17:38:11 +00001806 if (!success && ctx->Driver.TexImage2D) {
1807 /* let device driver try to use unpacked image */
1808 (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format,
1809 GL_UNSIGNED_BYTE, texImage->Data,
1810 &_mesa_native_packing,
1811 texObj, texImage, &retain);
1812 }
1813 }
1814 if (!retain && texImage->Data) {
1815 FREE(texImage->Data);
1816 texImage->Data = NULL;
1817 }
jtgafb833d1999-08-19 00:55:39 +00001818 }
1819 else {
Brian Paul02938782000-03-22 17:38:11 +00001820 make_null_texture(texImage);
1821 if (ctx->Driver.TexImage2D) {
1822 GLboolean retain;
1823 (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format,
1824 GL_UNSIGNED_BYTE, texImage->Data,
1825 &_mesa_native_packing,
1826 texObj, texImage, &retain);
1827 }
jtgafb833d1999-08-19 00:55:39 +00001828 }
1829
Brian Paul02938782000-03-22 17:38:11 +00001830#define OLD_DD_TEXTURE
1831#ifdef OLD_DD_TEXTURE
1832 /* XXX this will be removed in the future */
jtgafb833d1999-08-19 00:55:39 +00001833 if (ctx->Driver.TexImage) {
Brian Paul02938782000-03-22 17:38:11 +00001834 (*ctx->Driver.TexImage)( ctx, target, texObj, level, internalFormat,
1835 texImage );
jtgafb833d1999-08-19 00:55:39 +00001836 }
Brian Paul02938782000-03-22 17:38:11 +00001837#endif
1838
1839 /* state update */
1840 gl_put_texobj_on_dirty_list( ctx, texObj );
1841 ctx->NewState |= NEW_TEXTURING;
jtgafb833d1999-08-19 00:55:39 +00001842 }
1843 else if (target==GL_PROXY_TEXTURE_2D) {
1844 /* Proxy texture: check for errors and update proxy state */
Brian Paulaea66b12000-05-24 14:04:06 +00001845 if (texture_error_check(ctx, target, level, internalFormat,
Brian Paulf93b3dd2000-08-30 18:22:28 +00001846 format, type, 2, postConvWidth, height, 1, border)) {
Brian Paulaea66b12000-05-24 14:04:06 +00001847 /* if error, clear all proxy texture image parameters */
jtgafb833d1999-08-19 00:55:39 +00001848 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00001849 clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]);
jtgafb833d1999-08-19 00:55:39 +00001850 }
1851 }
1852 else {
Brian Paulaea66b12000-05-24 14:04:06 +00001853 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00001854 init_texture_image(ctx,
1855 ctx->Texture.Proxy2D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00001856 width, height, 1, border, internalFormat);
jtgafb833d1999-08-19 00:55:39 +00001857 }
jtgafb833d1999-08-19 00:55:39 +00001858 }
1859 else {
1860 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
1861 return;
1862 }
1863}
1864
1865
1866
1867/*
1868 * Called by the API or display list executor.
1869 * Note that width and height include the border.
1870 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001871void
Brian Paul43911c82000-03-21 00:49:33 +00001872_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
Brian Paulfbd8f211999-11-11 01:22:25 +00001873 GLsizei width, GLsizei height, GLsizei depth,
1874 GLint border, GLenum format, GLenum type,
1875 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00001876{
Brian Paulfbd8f211999-11-11 01:22:25 +00001877 GET_CURRENT_CONTEXT(ctx);
Brian Paulf7b57072000-03-20 14:37:52 +00001878 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage3D");
jtgafb833d1999-08-19 00:55:39 +00001879
Brian Paulfbd8f211999-11-11 01:22:25 +00001880 if (target==GL_TEXTURE_3D_EXT) {
Brian Paulf7b57072000-03-20 14:37:52 +00001881 struct gl_texture_unit *texUnit;
Brian Paul02938782000-03-22 17:38:11 +00001882 struct gl_texture_object *texObj;
1883 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00001884 GLint ifmt;
1885
1886 ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 3);
1887 if (ifmt < 0) {
1888 /*
1889 * The error here is that we were sent a generic compressed
1890 * format, but the extension is not supported.
1891 */
1892 return;
1893 }
1894 else {
1895 internalFormat = ifmt;
1896 }
1897
Brian Paulaea66b12000-05-24 14:04:06 +00001898 if (texture_error_check(ctx, target, level, internalFormat,
1899 format, type, 3, width, height, depth, border)) {
Brian Paulf7b57072000-03-20 14:37:52 +00001900 return; /* error in texture image was detected */
jtgafb833d1999-08-19 00:55:39 +00001901 }
1902
Brian Paulf7b57072000-03-20 14:37:52 +00001903 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul02938782000-03-22 17:38:11 +00001904 texObj = texUnit->CurrentD[3];
1905 texImage = texObj->Image[level];
Brian Paulf7b57072000-03-20 14:37:52 +00001906
Brian Paul02938782000-03-22 17:38:11 +00001907 if (!texImage) {
Brian Paul021a5252000-03-27 17:54:17 +00001908 texImage = _mesa_alloc_texture_image();
Brian Paul02938782000-03-22 17:38:11 +00001909 texObj->Image[level] = texImage;
1910 if (!texImage) {
1911 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
1912 return;
1913 }
1914 }
1915 else if (texImage->Data) {
1916 FREE(texImage->Data);
1917 texImage->Data = NULL;
jtgafb833d1999-08-19 00:55:39 +00001918 }
1919
Brian Paul02938782000-03-22 17:38:11 +00001920 /* setup the teximage struct's fields */
Brian Paul289d47e2000-08-29 23:31:23 +00001921 init_texture_image(ctx, texImage, width, height, depth,
Brian Paul02938782000-03-22 17:38:11 +00001922 border, internalFormat);
Brian Paul43911c82000-03-21 00:49:33 +00001923
Brian Paulfa4525e2000-08-21 14:22:24 +00001924 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
1925 _mesa_update_image_transfer_state(ctx);
1926
Brian Paul02938782000-03-22 17:38:11 +00001927 /* process the texture image */
Brian Paulc3f0a511999-11-03 17:27:05 +00001928 if (pixels) {
Brian Paul02938782000-03-22 17:38:11 +00001929 GLboolean retain = GL_TRUE;
1930 GLboolean success = GL_FALSE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001931 if (!ctx->ImageTransferState && ctx->Driver.TexImage3D) {
Brian Paul02938782000-03-22 17:38:11 +00001932 /* let device driver try to use raw image */
1933 success = (*ctx->Driver.TexImage3D)( ctx, target, level, format,
1934 type, pixels, &ctx->Unpack,
1935 texObj, texImage, &retain);
1936 }
1937 if (retain || !success) {
1938 /* make internal copy of the texture image */
Brian Paul5a0d3dc2000-08-31 15:24:39 +00001939 make_texture_image(ctx, 3, texImage, width, height, depth,
1940 format, type, pixels, &ctx->Unpack);
Brian Paul02938782000-03-22 17:38:11 +00001941 if (!success && ctx->Driver.TexImage3D) {
1942 /* let device driver try to use unpacked image */
1943 (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format,
1944 GL_UNSIGNED_BYTE, texImage->Data,
1945 &_mesa_native_packing,
1946 texObj, texImage, &retain);
1947 }
1948 }
1949 if (!retain && texImage->Data) {
1950 FREE(texImage->Data);
1951 texImage->Data = NULL;
1952 }
jtgafb833d1999-08-19 00:55:39 +00001953 }
1954 else {
Brian Paul02938782000-03-22 17:38:11 +00001955 make_null_texture(texImage);
1956 if (ctx->Driver.TexImage3D) {
1957 GLboolean retain;
1958 (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format,
1959 GL_UNSIGNED_BYTE, texImage->Data,
1960 &_mesa_native_packing,
1961 texObj, texImage, &retain);
1962 }
jtgafb833d1999-08-19 00:55:39 +00001963 }
1964
Brian Paul02938782000-03-22 17:38:11 +00001965 /* state update */
1966 gl_put_texobj_on_dirty_list( ctx, texObj );
jtgafb833d1999-08-19 00:55:39 +00001967 ctx->NewState |= NEW_TEXTURING;
jtgafb833d1999-08-19 00:55:39 +00001968 }
Brian Paulaea66b12000-05-24 14:04:06 +00001969 else if (target==GL_PROXY_TEXTURE_3D) {
jtgafb833d1999-08-19 00:55:39 +00001970 /* Proxy texture: check for errors and update proxy state */
Brian Paulaea66b12000-05-24 14:04:06 +00001971 if (texture_error_check(ctx, target, level, internalFormat,
1972 format, type, 3, width, height, depth, border)) {
1973 /* if error, clear all proxy texture image parameters */
jtgafb833d1999-08-19 00:55:39 +00001974 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00001975 clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]);
jtgafb833d1999-08-19 00:55:39 +00001976 }
1977 }
1978 else {
Brian Paulaea66b12000-05-24 14:04:06 +00001979 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00001980 init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00001981 width, height, depth, border, internalFormat);
jtgafb833d1999-08-19 00:55:39 +00001982 }
jtgafb833d1999-08-19 00:55:39 +00001983 }
1984 else {
Brian Paulc3f0a511999-11-03 17:27:05 +00001985 gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
jtgafb833d1999-08-19 00:55:39 +00001986 return;
1987 }
1988}
1989
1990
Brian Paul663049a2000-01-31 23:10:16 +00001991void
Brian Paul43911c82000-03-21 00:49:33 +00001992_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
Brian Paul663049a2000-01-31 23:10:16 +00001993 GLsizei width, GLsizei height, GLsizei depth,
1994 GLint border, GLenum format, GLenum type,
1995 const GLvoid *pixels )
1996{
Brian Paul43911c82000-03-21 00:49:33 +00001997 _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
Brian Paul663049a2000-01-31 23:10:16 +00001998 depth, border, format, type, pixels);
1999}
2000
2001
Brian Paulf7b57072000-03-20 14:37:52 +00002002/*
2003 * Fetch a texture image from the device driver.
2004 * Store the results in the given texture object at the given mipmap level.
2005 */
Brian Paul021a5252000-03-27 17:54:17 +00002006void
2007_mesa_get_teximage_from_driver( GLcontext *ctx, GLenum target, GLint level,
2008 const struct gl_texture_object *texObj )
Brian Paulf7b57072000-03-20 14:37:52 +00002009{
2010 GLvoid *image;
2011 GLenum imgFormat, imgType;
2012 GLboolean freeImage;
2013 struct gl_texture_image *texImage;
2014 GLint destComponents, numPixels, srcBytesPerTexel;
2015
2016 if (!ctx->Driver.GetTexImage)
2017 return;
2018
Brian Paul48271792000-03-29 18:13:59 +00002019 image = (*ctx->Driver.GetTexImage)( ctx, target, level, texObj,
Brian Paulf7b57072000-03-20 14:37:52 +00002020 &imgFormat, &imgType, &freeImage);
2021 if (!image)
2022 return;
2023
2024 texImage = texObj->Image[level];
2025 ASSERT(texImage);
2026 if (!texImage)
2027 return;
2028
2029 destComponents = components_in_intformat(texImage->Format);
2030 assert(destComponents > 0);
2031 numPixels = texImage->Width * texImage->Height * texImage->Depth;
2032 assert(numPixels > 0);
Brian Paulb7d076f2000-03-21 01:03:40 +00002033 srcBytesPerTexel = _mesa_bytes_per_pixel(imgFormat, imgType);
Brian Paulf7b57072000-03-20 14:37:52 +00002034 assert(srcBytesPerTexel > 0);
2035
2036 if (!texImage->Data) {
2037 /* Allocate memory for the texture image data */
2038 texImage->Data = (GLubyte *) MALLOC(numPixels * destComponents + EXTRA_BYTE);
2039 }
2040
2041 if (imgFormat == texImage->Format && imgType == GL_UNSIGNED_BYTE) {
2042 /* We got lucky! The driver's format and type match Mesa's format. */
2043 if (texImage->Data) {
2044 MEMCPY(texImage->Data, image, numPixels * destComponents);
2045 }
2046 }
2047 else {
2048 /* Convert the texture image from the driver's format to Mesa's
2049 * internal format.
2050 */
2051 const GLint width = texImage->Width;
2052 const GLint height = texImage->Height;
2053 const GLint depth = texImage->Depth;
2054 const GLint destBytesPerRow = width * destComponents * sizeof(GLchan);
2055 const GLint srcBytesPerRow = width * srcBytesPerTexel;
2056 const GLenum dstType = GL_UNSIGNED_BYTE;
2057 const GLenum dstFormat = texImage->Format;
2058 const GLubyte *srcPtr = (const GLubyte *) image;
2059 GLubyte *destPtr = texImage->Data;
2060
2061 if (texImage->Format == GL_COLOR_INDEX) {
2062 /* color index texture */
2063 GLint img, row;
2064 assert(imgFormat == GL_COLOR_INDEX);
2065 for (img = 0; img < depth; img++) {
2066 for (row = 0; row < height; row++) {
2067 _mesa_unpack_index_span(ctx, width, dstType, destPtr,
Brian Paul289d47e2000-08-29 23:31:23 +00002068 imgType, srcPtr, &_mesa_native_packing, GL_FALSE);
Brian Paulf7b57072000-03-20 14:37:52 +00002069 destPtr += destBytesPerRow;
2070 srcPtr += srcBytesPerRow;
2071 }
2072 }
2073 }
2074 else {
2075 /* color texture */
2076 GLint img, row;
2077 for (img = 0; img < depth; img++) {
2078 for (row = 0; row < height; row++) {
2079 _mesa_unpack_ubyte_color_span(ctx, width, dstFormat, destPtr,
Brian Paul289d47e2000-08-29 23:31:23 +00002080 imgFormat, imgType, srcPtr, &_mesa_native_packing, GL_FALSE);
Brian Paulf7b57072000-03-20 14:37:52 +00002081 destPtr += destBytesPerRow;
2082 srcPtr += srcBytesPerRow;
2083 }
2084 }
2085 }
2086 }
2087
2088 if (freeImage)
2089 FREE(image);
2090}
2091
jtgafb833d1999-08-19 00:55:39 +00002092
Brian Paulfbd8f211999-11-11 01:22:25 +00002093void
2094_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
2095 GLenum type, GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00002096{
Brian Paulfbd8f211999-11-11 01:22:25 +00002097 GET_CURRENT_CONTEXT(ctx);
Brian Paul01e54752000-09-05 15:40:34 +00002098 const struct gl_texture_unit *texUnit;
jtgafb833d1999-08-19 00:55:39 +00002099 const struct gl_texture_object *texObj;
Brian Paulf7b57072000-03-20 14:37:52 +00002100 struct gl_texture_image *texImage;
2101 GLboolean discardImage;
jtgafb833d1999-08-19 00:55:39 +00002102
2103 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexImage");
2104
2105 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
2106 gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
2107 return;
2108 }
2109
Brian Paulb7d076f2000-03-21 01:03:40 +00002110 if (_mesa_sizeof_type(type) <= 0) {
jtgafb833d1999-08-19 00:55:39 +00002111 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
2112 return;
2113 }
2114
Brian Paulb7d076f2000-03-21 01:03:40 +00002115 if (_mesa_components_in_format(format) <= 0) {
jtgafb833d1999-08-19 00:55:39 +00002116 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
2117 return;
2118 }
2119
2120 if (!pixels)
Brian Paulf7b57072000-03-20 14:37:52 +00002121 return;
jtgafb833d1999-08-19 00:55:39 +00002122
Brian Paul01e54752000-09-05 15:40:34 +00002123 texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
2124 texObj = _mesa_select_tex_object(ctx, texUnit, target);
2125 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
Brian Paulc52fc9b2000-09-05 22:11:38 +00002126 if (!texObj || !texImage ||
2127 target == GL_PROXY_TEXTURE_1D ||
2128 target == GL_PROXY_TEXTURE_2D ||
2129 target == GL_PROXY_TEXTURE_3D) {
Brian Paul01e54752000-09-05 15:40:34 +00002130 gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
2131 return;
jtgafb833d1999-08-19 00:55:39 +00002132 }
2133
Brian Paulf7b57072000-03-20 14:37:52 +00002134 if (!texImage) {
2135 /* invalid mipmap level */
2136 return;
2137 }
2138
2139 if (!texImage->Data) {
2140 /* try to get the texture image from the device driver */
Brian Paul021a5252000-03-27 17:54:17 +00002141 _mesa_get_teximage_from_driver(ctx, target, level, texObj);
Brian Paulf7b57072000-03-20 14:37:52 +00002142 discardImage = GL_TRUE;
2143 }
2144 else {
2145 discardImage = GL_FALSE;
2146 }
2147
2148 if (texImage->Data) {
jtgafb833d1999-08-19 00:55:39 +00002149 GLint width = texImage->Width;
2150 GLint height = texImage->Height;
Brian Paulf96ce6a2000-09-06 15:15:43 +00002151 GLint depth = texImage->Depth;
2152 GLint img, row;
jtgafb833d1999-08-19 00:55:39 +00002153
Brian Paulfa4525e2000-08-21 14:22:24 +00002154 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2155 _mesa_update_image_transfer_state(ctx);
2156
Brian Paulf96ce6a2000-09-06 15:15:43 +00002157 if (ctx->ImageTransferState & IMAGE_CONVOLUTION_BIT) {
2158 /* convert texture image to GL_RGBA, GL_FLOAT */
2159 GLfloat *tmpImage, *convImage;
2160 const GLint comps = components_in_intformat(texImage->Format);
jtgafb833d1999-08-19 00:55:39 +00002161
Brian Paulf96ce6a2000-09-06 15:15:43 +00002162 tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
2163 if (!tmpImage) {
2164 gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
2165 return;
jtgafb833d1999-08-19 00:55:39 +00002166 }
Brian Paulf96ce6a2000-09-06 15:15:43 +00002167 convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
2168 if (!convImage) {
2169 FREE(tmpImage);
2170 gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
2171 return;
2172 }
2173
2174 for (img = 0; img < depth; img++) {
2175 GLint convWidth, convHeight;
2176
2177 /* convert to GL_RGBA */
2178 for (row = 0; row < height; row++) {
2179 const GLubyte *src = texImage->Data
2180 + (img * height + row ) * width * comps;
2181 GLfloat *dst = tmpImage + row * width * 4;
2182 _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst,
2183 texImage->Format, GL_UNSIGNED_BYTE,
2184 src, &_mesa_native_packing,
2185 ctx->ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
2186 GL_FALSE);
jtgafb833d1999-08-19 00:55:39 +00002187 }
Brian Paulf96ce6a2000-09-06 15:15:43 +00002188
2189 convWidth = width;
2190 convHeight = height;
2191
2192 /* convolve */
2193 if (target == GL_TEXTURE_1D) {
2194 if (ctx->Pixel.Convolution1DEnabled) {
2195 _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
2196 }
2197 }
2198 else {
2199 if (ctx->Pixel.Convolution2DEnabled) {
2200 _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
2201 tmpImage, convImage);
2202 }
2203 else if (ctx->Pixel.Separable2DEnabled) {
2204 _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
2205 tmpImage, convImage);
2206 }
2207 }
2208
2209 /* pack convolved image */
2210 for (row = 0; row < convHeight; row++) {
2211 const GLfloat *src = convImage + row * convWidth * 4;
2212 GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels,
2213 convWidth, convHeight,
2214 format, type, img, row, 0);
2215 _mesa_pack_float_rgba_span(ctx, convWidth,
2216 (const GLfloat(*)[4]) src,
2217 format, type, dest, &ctx->Pack,
2218 ctx->ImageTransferState & IMAGE_POST_CONVOLUTION_BITS);
2219 }
jtgafb833d1999-08-19 00:55:39 +00002220 }
Brian Paulf96ce6a2000-09-06 15:15:43 +00002221
2222 FREE(tmpImage);
2223 FREE(convImage);
jtgafb833d1999-08-19 00:55:39 +00002224 }
Brian Paulf96ce6a2000-09-06 15:15:43 +00002225 else {
2226 /* no convolution */
2227 for (img = 0; img < depth; img++) {
2228 for (row = 0; row < height; row++) {
2229 /* compute destination address in client memory */
2230 GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels,
2231 width, height, format, type, img, row, 0);
2232 assert(dest);
2233 if (texImage->Format == GL_RGBA) {
2234 /* simple case */
2235 const GLubyte *src = texImage->Data
2236 + (img * height + row ) * width * 4;
2237 _mesa_pack_rgba_span( ctx, width, (CONST GLubyte (*)[4]) src,
2238 format, type, dest, &ctx->Pack,
2239 ctx->ImageTransferState );
2240 }
2241 else {
2242 /* general case: convert row to RGBA format */
2243 GLubyte rgba[MAX_WIDTH][4];
2244 GLint i;
2245 const GLubyte *src;
2246 switch (texImage->Format) {
2247 case GL_ALPHA:
2248 src = texImage->Data + row * width * sizeof(GLubyte);
2249 for (i = 0; i < width; i++) {
2250 rgba[i][RCOMP] = 255;
2251 rgba[i][GCOMP] = 255;
2252 rgba[i][BCOMP] = 255;
2253 rgba[i][ACOMP] = src[i];
2254 }
2255 break;
2256 case GL_LUMINANCE:
2257 src = texImage->Data + row * width * sizeof(GLubyte);
2258 for (i = 0; i < width; i++) {
2259 rgba[i][RCOMP] = src[i];
2260 rgba[i][GCOMP] = src[i];
2261 rgba[i][BCOMP] = src[i];
2262 rgba[i][ACOMP] = 255;
2263 }
2264 break;
2265 case GL_LUMINANCE_ALPHA:
2266 src = texImage->Data + row * 2 * width * sizeof(GLubyte);
2267 for (i = 0; i < width; i++) {
2268 rgba[i][RCOMP] = src[i*2+0];
2269 rgba[i][GCOMP] = src[i*2+0];
2270 rgba[i][BCOMP] = src[i*2+0];
2271 rgba[i][ACOMP] = src[i*2+1];
2272 }
2273 break;
2274 case GL_INTENSITY:
2275 src = texImage->Data + row * width * sizeof(GLubyte);
2276 for (i = 0; i < width; i++) {
2277 rgba[i][RCOMP] = src[i];
2278 rgba[i][GCOMP] = src[i];
2279 rgba[i][BCOMP] = src[i];
2280 rgba[i][ACOMP] = 255;
2281 }
2282 break;
2283 case GL_RGB:
2284 src = texImage->Data + row * 3 * width * sizeof(GLubyte);
2285 for (i = 0; i < width; i++) {
2286 rgba[i][RCOMP] = src[i*3+0];
2287 rgba[i][GCOMP] = src[i*3+1];
2288 rgba[i][BCOMP] = src[i*3+2];
2289 rgba[i][ACOMP] = 255;
2290 }
2291 break;
2292 case GL_COLOR_INDEX:
2293 gl_problem( ctx, "GL_COLOR_INDEX not implemented in gl_GetTexImage" );
2294 break;
2295 case GL_RGBA:
2296 default:
2297 gl_problem( ctx, "bad format in gl_GetTexImage" );
2298 }
2299 _mesa_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba,
2300 format, type, dest, &ctx->Pack,
2301 ctx->ImageTransferState );
2302 } /* format */
2303 } /* row */
2304 } /* img */
2305 } /* convolution */
Brian Paulf7b57072000-03-20 14:37:52 +00002306
2307 /* if we got the teximage from the device driver we'll discard it now */
2308 if (discardImage) {
2309 FREE(texImage->Data);
2310 texImage->Data = NULL;
2311 }
jtgafb833d1999-08-19 00:55:39 +00002312 }
2313}
2314
2315
2316
Brian Paulfbd8f211999-11-11 01:22:25 +00002317void
2318_mesa_TexSubImage1D( GLenum target, GLint level,
2319 GLint xoffset, GLsizei width,
2320 GLenum format, GLenum type,
2321 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00002322{
Brian Paulfbd8f211999-11-11 01:22:25 +00002323 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00002324 struct gl_texture_unit *texUnit;
2325 struct gl_texture_object *texObj;
2326 struct gl_texture_image *texImage;
2327 GLboolean success = GL_FALSE;
Brian Paula805bb92000-09-02 17:52:21 +00002328 GLsizei postConvWidth;
2329
2330 postConvWidth = width;
2331 adjust_texture_size_for_convolution(ctx, 1, &postConvWidth, NULL);
jtgafb833d1999-08-19 00:55:39 +00002332
Brian Paulc3f0a511999-11-03 17:27:05 +00002333 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
Brian Paula805bb92000-09-02 17:52:21 +00002334 postConvWidth, 1, 1, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00002335 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00002336 }
2337
Brian Paul02938782000-03-22 17:38:11 +00002338 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2339 texObj = texUnit->CurrentD[1];
2340 texImage = texObj->Image[level];
2341 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00002342
Brian Paulc3f0a511999-11-03 17:27:05 +00002343 if (width == 0 || !pixels)
2344 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00002345
Brian Paulfa4525e2000-08-21 14:22:24 +00002346 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2347 _mesa_update_image_transfer_state(ctx);
Brian Paulc3f0a511999-11-03 17:27:05 +00002348
Brian Paulfa4525e2000-08-21 14:22:24 +00002349 if (!ctx->ImageTransferState && ctx->Driver.TexSubImage1D) {
Brian Paul02938782000-03-22 17:38:11 +00002350 success = (*ctx->Driver.TexSubImage1D)( ctx, target, level, xoffset,
2351 width, format, type, pixels,
2352 &ctx->Unpack, texObj, texImage );
2353 }
2354 if (!success) {
2355 /* XXX if Driver.TexSubImage1D, unpack image and try again? */
Brian Paul02938782000-03-22 17:38:11 +00002356 GLboolean retain = GL_TRUE;
2357 if (!texImage->Data) {
Brian Paul021a5252000-03-27 17:54:17 +00002358 _mesa_get_teximage_from_driver( ctx, target, level, texObj );
Brian Paul02938782000-03-22 17:38:11 +00002359 if (!texImage->Data) {
2360 make_null_texture(texImage);
2361 }
2362 if (!texImage->Data)
2363 return; /* we're really out of luck! */
2364 }
2365
Brian Paula805bb92000-09-02 17:52:21 +00002366 fill_texture_image(ctx, 1, texImage->Format, texImage->Data,
2367 width, 1, 1, xoffset, 0, 0, /* size and offsets */
2368 0, 0, /* strides */
2369 format, type, pixels, &ctx->Unpack);
Brian Paul02938782000-03-22 17:38:11 +00002370
2371 if (ctx->Driver.TexImage1D) {
2372 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
2373 GL_UNSIGNED_BYTE, texImage->Data,
2374 &_mesa_native_packing, texObj, texImage,
2375 &retain );
2376 }
2377
2378 if (!retain && texImage->Data) {
2379 FREE(texImage->Data);
2380 texImage->Data = NULL;
jtgafb833d1999-08-19 00:55:39 +00002381 }
Brian Paulc3f0a511999-11-03 17:27:05 +00002382 }
jtgafb833d1999-08-19 00:55:39 +00002383}
2384
2385
Brian Paulfbd8f211999-11-11 01:22:25 +00002386void
2387_mesa_TexSubImage2D( GLenum target, GLint level,
2388 GLint xoffset, GLint yoffset,
2389 GLsizei width, GLsizei height,
2390 GLenum format, GLenum type,
2391 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00002392{
Brian Paulfbd8f211999-11-11 01:22:25 +00002393 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00002394 struct gl_texture_unit *texUnit;
2395 struct gl_texture_object *texObj;
2396 struct gl_texture_image *texImage;
2397 GLboolean success = GL_FALSE;
Brian Paula805bb92000-09-02 17:52:21 +00002398 GLsizei postConvWidth, postConvHeight;
2399
2400 postConvWidth = width;
2401 postConvHeight = height;
2402 adjust_texture_size_for_convolution(ctx, 2, &postConvWidth,&postConvHeight);
jtgafb833d1999-08-19 00:55:39 +00002403
Brian Paulc3f0a511999-11-03 17:27:05 +00002404 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
Brian Paula805bb92000-09-02 17:52:21 +00002405 postConvWidth, postConvHeight, 1, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00002406 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00002407 }
2408
Brian Paul02938782000-03-22 17:38:11 +00002409 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul35d53012000-05-23 17:14:49 +00002410 texObj = _mesa_select_tex_object(ctx, texUnit, target);
Brian Paul02938782000-03-22 17:38:11 +00002411 texImage = texObj->Image[level];
2412 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00002413
Brian Paulc3f0a511999-11-03 17:27:05 +00002414 if (width == 0 || height == 0 || !pixels)
2415 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00002416
Brian Paulfa4525e2000-08-21 14:22:24 +00002417 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2418 _mesa_update_image_transfer_state(ctx);
2419
2420 if (!ctx->ImageTransferState && ctx->Driver.TexSubImage2D) {
Brian Paul02938782000-03-22 17:38:11 +00002421 success = (*ctx->Driver.TexSubImage2D)( ctx, target, level, xoffset,
2422 yoffset, width, height, format, type,
2423 pixels, &ctx->Unpack, texObj, texImage );
2424 }
2425 if (!success) {
2426 /* XXX if Driver.TexSubImage2D, unpack image and try again? */
Brian Paula805bb92000-09-02 17:52:21 +00002427 const GLint texComps = components_in_intformat(texImage->Format);
2428 const GLint texRowStride = texImage->Width * texComps * sizeof(GLubyte);
Brian Paul02938782000-03-22 17:38:11 +00002429 GLboolean retain = GL_TRUE;
2430
2431 if (!texImage->Data) {
Brian Paul021a5252000-03-27 17:54:17 +00002432 _mesa_get_teximage_from_driver( ctx, target, level, texObj );
Brian Paul02938782000-03-22 17:38:11 +00002433 if (!texImage->Data) {
2434 make_null_texture(texImage);
2435 }
2436 if (!texImage->Data)
2437 return; /* we're really out of luck! */
2438 }
2439
Brian Paula805bb92000-09-02 17:52:21 +00002440 fill_texture_image(ctx, 2, texImage->Format, texImage->Data,
2441 width, height, 1, xoffset, yoffset, 0,
2442 texRowStride, 0,
2443 format, type, pixels, &ctx->Unpack);
jtgafb833d1999-08-19 00:55:39 +00002444
Brian Paul02938782000-03-22 17:38:11 +00002445 if (ctx->Driver.TexImage2D) {
2446 (*ctx->Driver.TexImage2D)(ctx, target, level, texImage->Format,
2447 GL_UNSIGNED_BYTE, texImage->Data,
2448 &_mesa_native_packing, texObj, texImage,
2449 &retain);
jtgafb833d1999-08-19 00:55:39 +00002450 }
Brian Paul02938782000-03-22 17:38:11 +00002451
2452 if (!retain && texImage->Data) {
2453 FREE(texImage->Data);
2454 texImage->Data = NULL;
2455 }
2456
2457#ifdef OLD_DD_TEXTURE
2458 /* XXX this will be removed in the future */
2459 if (ctx->Driver.TexSubImage) {
2460 (*ctx->Driver.TexSubImage)(ctx, target, texObj, level,
2461 xoffset, yoffset, width, height,
2462 texImage->IntFormat, texImage);
2463 }
2464 else if (ctx->Driver.TexImage) {
Brian Paul9fd2b0a2000-03-24 23:59:06 +00002465 (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texObj,
Brian Paul02938782000-03-22 17:38:11 +00002466 level, texImage->IntFormat, texImage );
2467 }
2468#endif
jtgafb833d1999-08-19 00:55:39 +00002469 }
2470}
2471
2472
2473
Brian Paulfbd8f211999-11-11 01:22:25 +00002474void
2475_mesa_TexSubImage3D( GLenum target, GLint level,
2476 GLint xoffset, GLint yoffset, GLint zoffset,
2477 GLsizei width, GLsizei height, GLsizei depth,
2478 GLenum format, GLenum type,
2479 const GLvoid *pixels )
jtgafb833d1999-08-19 00:55:39 +00002480{
Brian Paulfbd8f211999-11-11 01:22:25 +00002481 GET_CURRENT_CONTEXT(ctx);
Brian Paul02938782000-03-22 17:38:11 +00002482 struct gl_texture_unit *texUnit;
2483 struct gl_texture_object *texObj;
2484 struct gl_texture_image *texImage;
2485 GLboolean success = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002486
Brian Paulc3f0a511999-11-03 17:27:05 +00002487 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
2488 width, height, depth, format, type)) {
Brian Paulf7b57072000-03-20 14:37:52 +00002489 return; /* error was detected */
jtgafb833d1999-08-19 00:55:39 +00002490 }
2491
Brian Paul02938782000-03-22 17:38:11 +00002492 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2493 texObj = texUnit->CurrentD[3];
2494 texImage = texObj->Image[level];
2495 assert(texImage);
jtgafb833d1999-08-19 00:55:39 +00002496
Brian Paulc3f0a511999-11-03 17:27:05 +00002497 if (width == 0 || height == 0 || height == 0 || !pixels)
2498 return; /* no-op, not an error */
jtgafb833d1999-08-19 00:55:39 +00002499
Brian Paulfa4525e2000-08-21 14:22:24 +00002500 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2501 _mesa_update_image_transfer_state(ctx);
2502
2503 if (!ctx->ImageTransferState && ctx->Driver.TexSubImage3D) {
Brian Paul02938782000-03-22 17:38:11 +00002504 success = (*ctx->Driver.TexSubImage3D)( ctx, target, level, xoffset,
2505 yoffset, zoffset, width, height, depth, format,
2506 type, pixels, &ctx->Unpack, texObj, texImage );
2507 }
2508 if (!success) {
2509 /* XXX if Driver.TexSubImage3D, unpack image and try again? */
Brian Paula805bb92000-09-02 17:52:21 +00002510 const GLint texComps = components_in_intformat(texImage->Format);
2511 const GLint texRowStride = texImage->Width * texComps * sizeof(GLubyte);
2512 const GLint texImgStride = texRowStride * texImage->Height;
Brian Paul02938782000-03-22 17:38:11 +00002513 GLboolean retain = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00002514
Brian Paula805bb92000-09-02 17:52:21 +00002515 if (!texImage->Data) {
2516 _mesa_get_teximage_from_driver( ctx, target, level, texObj );
2517 if (!texImage->Data) {
2518 make_null_texture(texImage);
jtgafb833d1999-08-19 00:55:39 +00002519 }
Brian Paula805bb92000-09-02 17:52:21 +00002520 if (!texImage->Data)
2521 return; /* we're really out of luck! */
jtgafb833d1999-08-19 00:55:39 +00002522 }
Brian Paula805bb92000-09-02 17:52:21 +00002523
2524 fill_texture_image(ctx, 3, texImage->Format, texImage->Data,
2525 width, height, depth, xoffset, yoffset, zoffset,
2526 texRowStride, texImgStride,
2527 format, type, pixels, &ctx->Unpack);
Brian Paul02938782000-03-22 17:38:11 +00002528
2529 if (ctx->Driver.TexImage3D) {
2530 (*ctx->Driver.TexImage3D)(ctx, target, level, texImage->Format,
2531 GL_UNSIGNED_BYTE, texImage->Data,
2532 &_mesa_native_packing, texObj, texImage,
2533 &retain);
2534 }
2535
2536 if (!retain && texImage->Data) {
2537 FREE(texImage->Data);
2538 texImage->Data = NULL;
2539 }
jtgafb833d1999-08-19 00:55:39 +00002540 }
jtgafb833d1999-08-19 00:55:39 +00002541}
2542
2543
2544
2545/*
2546 * Read an RGBA image from the frame buffer.
Brian Paula805bb92000-09-02 17:52:21 +00002547 * This is used by glCopyTex[Sub]Image[12]D().
jtgafb833d1999-08-19 00:55:39 +00002548 * Input: ctx - the context
2549 * x, y - lower left corner
2550 * width, height - size of region to read
Brian Paulc3f0a511999-11-03 17:27:05 +00002551 * Return: pointer to block of GL_RGBA, GLubyte data.
jtgafb833d1999-08-19 00:55:39 +00002552 */
Brian Paulc3f0a511999-11-03 17:27:05 +00002553static GLubyte *
2554read_color_image( GLcontext *ctx, GLint x, GLint y,
2555 GLsizei width, GLsizei height )
jtgafb833d1999-08-19 00:55:39 +00002556{
Brian Paulc3f0a511999-11-03 17:27:05 +00002557 GLint stride, i;
2558 GLubyte *image, *dst;
jtgafb833d1999-08-19 00:55:39 +00002559
Brian Paul959f8022000-03-19 01:10:11 +00002560 image = (GLubyte *) MALLOC(width * height * 4 * sizeof(GLubyte));
Brian Paulc3f0a511999-11-03 17:27:05 +00002561 if (!image)
jtgafb833d1999-08-19 00:55:39 +00002562 return NULL;
jtgafb833d1999-08-19 00:55:39 +00002563
2564 /* Select buffer to read from */
Brian Paulcea0e8e1999-11-25 17:36:48 +00002565 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
2566 ctx->Pixel.DriverReadBuffer );
jtgafb833d1999-08-19 00:55:39 +00002567
Brian Paulc3f0a511999-11-03 17:27:05 +00002568 dst = image;
2569 stride = width * 4 * sizeof(GLubyte);
2570 for (i = 0; i < height; i++) {
Brian Paul3f02f901999-11-24 18:48:30 +00002571 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
2572 (GLubyte (*)[4]) dst );
Brian Paulc3f0a511999-11-03 17:27:05 +00002573 dst += stride;
2574 }
jtgafb833d1999-08-19 00:55:39 +00002575
Brian Paulcea0e8e1999-11-25 17:36:48 +00002576 /* Read from draw buffer (the default) */
2577 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
2578 ctx->Color.DriverDrawBuffer );
jtgafb833d1999-08-19 00:55:39 +00002579
2580 return image;
2581}
2582
2583
2584
Brian Paulfbd8f211999-11-11 01:22:25 +00002585void
2586_mesa_CopyTexImage1D( GLenum target, GLint level,
2587 GLenum internalFormat,
2588 GLint x, GLint y,
2589 GLsizei width, GLint border )
jtgafb833d1999-08-19 00:55:39 +00002590{
Brian Paulfbd8f211999-11-11 01:22:25 +00002591 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00002592 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage1D");
jtgafb833d1999-08-19 00:55:39 +00002593
Brian Paulf7b57072000-03-20 14:37:52 +00002594 if (copytexture_error_check(ctx, 1, target, level, internalFormat,
2595 width, 1, border))
2596 return;
2597
Brian Paulfa4525e2000-08-21 14:22:24 +00002598 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2599 _mesa_update_image_transfer_state(ctx);
2600
2601 if (ctx->ImageTransferState || !ctx->Driver.CopyTexImage1D
Brian Paulf7b57072000-03-20 14:37:52 +00002602 || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level,
Brian Paula805bb92000-09-02 17:52:21 +00002603 internalFormat, x, y, width, border)) {
Brian Paul7dac1322000-06-15 19:57:14 +00002604 struct gl_pixelstore_attrib unpackSave;
2605
2606 /* get image from framebuffer */
Brian Paula805bb92000-09-02 17:52:21 +00002607 GLubyte *image = read_color_image( ctx, x, y, width, 1 );
Brian Paulc3f0a511999-11-03 17:27:05 +00002608 if (!image) {
2609 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" );
2610 return;
2611 }
Brian Paul7dac1322000-06-15 19:57:14 +00002612
2613 /* call glTexImage1D to redefine the texture */
2614 unpackSave = ctx->Unpack;
2615 ctx->Unpack = _mesa_native_packing;
Brian Paul3ab6bbe2000-02-12 17:26:15 +00002616 (*ctx->Exec->TexImage1D)( target, level, internalFormat, width,
Brian Paulf7b57072000-03-20 14:37:52 +00002617 border, GL_RGBA, GL_UNSIGNED_BYTE, image );
Brian Paul7dac1322000-06-15 19:57:14 +00002618 ctx->Unpack = unpackSave;
2619
Brian Paulc3f0a511999-11-03 17:27:05 +00002620 FREE(image);
jtgafb833d1999-08-19 00:55:39 +00002621 }
jtgafb833d1999-08-19 00:55:39 +00002622}
2623
2624
2625
Brian Paulfbd8f211999-11-11 01:22:25 +00002626void
2627_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
2628 GLint x, GLint y, GLsizei width, GLsizei height,
2629 GLint border )
jtgafb833d1999-08-19 00:55:39 +00002630{
Brian Paulfbd8f211999-11-11 01:22:25 +00002631 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00002632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage2D");
jtgafb833d1999-08-19 00:55:39 +00002633
Brian Paulf7b57072000-03-20 14:37:52 +00002634 if (copytexture_error_check(ctx, 2, target, level, internalFormat,
2635 width, height, border))
2636 return;
2637
Brian Paulfa4525e2000-08-21 14:22:24 +00002638 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2639 _mesa_update_image_transfer_state(ctx);
2640
2641 if (ctx->ImageTransferState || !ctx->Driver.CopyTexImage2D
Brian Paulf7b57072000-03-20 14:37:52 +00002642 || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level,
Brian Paula805bb92000-09-02 17:52:21 +00002643 internalFormat, x, y, width, height, border)) {
Brian Paul7dac1322000-06-15 19:57:14 +00002644 struct gl_pixelstore_attrib unpackSave;
2645
2646 /* get image from framebuffer */
Brian Paula805bb92000-09-02 17:52:21 +00002647 GLubyte *image = read_color_image( ctx, x, y, width, height );
Brian Paulc3f0a511999-11-03 17:27:05 +00002648 if (!image) {
2649 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" );
2650 return;
2651 }
Brian Paul7dac1322000-06-15 19:57:14 +00002652
2653 /* call glTexImage2D to redefine the texture */
2654 unpackSave = ctx->Unpack;
2655 ctx->Unpack = _mesa_native_packing;
Brian Paul3ab6bbe2000-02-12 17:26:15 +00002656 (ctx->Exec->TexImage2D)( target, level, internalFormat, width,
Brian Paulf7b57072000-03-20 14:37:52 +00002657 height, border, GL_RGBA, GL_UNSIGNED_BYTE, image );
Brian Paul7dac1322000-06-15 19:57:14 +00002658 ctx->Unpack = unpackSave;
2659
Brian Paulc3f0a511999-11-03 17:27:05 +00002660 FREE(image);
jtgafb833d1999-08-19 00:55:39 +00002661 }
jtgafb833d1999-08-19 00:55:39 +00002662}
2663
2664
2665
Brian Paulfbd8f211999-11-11 01:22:25 +00002666void
2667_mesa_CopyTexSubImage1D( GLenum target, GLint level,
2668 GLint xoffset, GLint x, GLint y, GLsizei width )
jtgafb833d1999-08-19 00:55:39 +00002669{
Brian Paulfbd8f211999-11-11 01:22:25 +00002670 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +00002671 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage1D");
jtgafb833d1999-08-19 00:55:39 +00002672
Brian Paulf7b57072000-03-20 14:37:52 +00002673 if (copytexsubimage_error_check(ctx, 1, target, level,
2674 xoffset, 0, 0, width, 1))
2675 return;
2676
Brian Paulfa4525e2000-08-21 14:22:24 +00002677 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2678 _mesa_update_image_transfer_state(ctx);
2679
2680 if (ctx->ImageTransferState || !ctx->Driver.CopyTexSubImage1D
Brian Paulf7b57072000-03-20 14:37:52 +00002681 || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level,
2682 xoffset, x, y, width)) {
Brian Paulc3f0a511999-11-03 17:27:05 +00002683 struct gl_texture_unit *texUnit;
2684 struct gl_texture_image *teximage;
Brian Paul7dac1322000-06-15 19:57:14 +00002685 struct gl_pixelstore_attrib unpackSave;
2686 GLubyte *image;
2687
Brian Paulc3f0a511999-11-03 17:27:05 +00002688 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2689 teximage = texUnit->CurrentD[1]->Image[level];
2690 assert(teximage);
Brian Paul7dac1322000-06-15 19:57:14 +00002691
2692 /* get image from frame buffer */
2693 image = read_color_image(ctx, x, y, width, 1);
2694 if (!image) {
2695 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
2696 return;
jtgafb833d1999-08-19 00:55:39 +00002697 }
Brian Paul7dac1322000-06-15 19:57:14 +00002698
2699 /* now call glTexSubImage1D to do the real work */
2700 unpackSave = ctx->Unpack;
2701 ctx->Unpack = _mesa_native_packing;
2702 _mesa_TexSubImage1D(target, level, xoffset, width,
2703 GL_RGBA, GL_UNSIGNED_BYTE, image);
2704 ctx->Unpack = unpackSave;
2705
2706 FREE(image);
jtgafb833d1999-08-19 00:55:39 +00002707 }
Brian Paulc3f0a511999-11-03 17:27:05 +00002708}
2709
2710
2711
Brian Paulfbd8f211999-11-11 01:22:25 +00002712void
2713_mesa_CopyTexSubImage2D( GLenum target, GLint level,
2714 GLint xoffset, GLint yoffset,
2715 GLint x, GLint y, GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +00002716{
Brian Paulfbd8f211999-11-11 01:22:25 +00002717 GET_CURRENT_CONTEXT(ctx);
Brian Paulc3f0a511999-11-03 17:27:05 +00002718 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage2D");
2719
Brian Paulf7b57072000-03-20 14:37:52 +00002720 if (copytexsubimage_error_check(ctx, 2, target, level,
2721 xoffset, yoffset, 0, width, height))
2722 return;
2723
Brian Paulfa4525e2000-08-21 14:22:24 +00002724 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2725 _mesa_update_image_transfer_state(ctx);
2726
2727 if (ctx->ImageTransferState || !ctx->Driver.CopyTexSubImage2D
Brian Paulf7b57072000-03-20 14:37:52 +00002728 || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level,
2729 xoffset, yoffset, x, y, width, height )) {
Brian Paulc3f0a511999-11-03 17:27:05 +00002730 struct gl_texture_unit *texUnit;
2731 struct gl_texture_image *teximage;
Brian Paul7dac1322000-06-15 19:57:14 +00002732 struct gl_pixelstore_attrib unpackSave;
2733 GLubyte *image;
2734
Brian Paulc3f0a511999-11-03 17:27:05 +00002735 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2736 teximage = texUnit->CurrentD[2]->Image[level];
2737 assert(teximage);
Brian Paul7dac1322000-06-15 19:57:14 +00002738
2739 /* get image from frame buffer */
2740 image = read_color_image(ctx, x, y, width, height);
2741 if (!image) {
2742 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
2743 return;
Brian Paulc3f0a511999-11-03 17:27:05 +00002744 }
Brian Paul7dac1322000-06-15 19:57:14 +00002745
2746 /* now call glTexSubImage2D to do the real work */
2747 unpackSave = ctx->Unpack;
2748 ctx->Unpack = _mesa_native_packing;
2749 _mesa_TexSubImage2D(target, level, xoffset, yoffset, width, height,
2750 GL_RGBA, GL_UNSIGNED_BYTE, image);
2751 ctx->Unpack = unpackSave;
2752
2753 FREE(image);
Brian Paulc3f0a511999-11-03 17:27:05 +00002754 }
2755}
2756
2757
2758
Brian Paulfbd8f211999-11-11 01:22:25 +00002759void
2760_mesa_CopyTexSubImage3D( GLenum target, GLint level,
2761 GLint xoffset, GLint yoffset, GLint zoffset,
2762 GLint x, GLint y, GLsizei width, GLsizei height )
Brian Paulc3f0a511999-11-03 17:27:05 +00002763{
Brian Paulfbd8f211999-11-11 01:22:25 +00002764 GET_CURRENT_CONTEXT(ctx);
Brian Paulc3f0a511999-11-03 17:27:05 +00002765 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage3D");
2766
Brian Paulf7b57072000-03-20 14:37:52 +00002767 if (copytexsubimage_error_check(ctx, 3, target, level,
2768 xoffset, yoffset, zoffset, width, height))
2769 return;
2770
Brian Paulfa4525e2000-08-21 14:22:24 +00002771 if (ctx->ImageTransferState == UPDATE_IMAGE_TRANSFER_STATE)
2772 _mesa_update_image_transfer_state(ctx);
2773
2774 if (ctx->ImageTransferState || !ctx->Driver.CopyTexSubImage3D
Brian Paulf7b57072000-03-20 14:37:52 +00002775 || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level,
Brian Paul02938782000-03-22 17:38:11 +00002776 xoffset, yoffset, zoffset, x, y, width, height )) {
2777 struct gl_texture_unit *texUnit;
2778 struct gl_texture_image *teximage;
Brian Paul7dac1322000-06-15 19:57:14 +00002779 struct gl_pixelstore_attrib unpackSave;
2780 GLubyte *image;
2781
Brian Paul02938782000-03-22 17:38:11 +00002782 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2783 teximage = texUnit->CurrentD[3]->Image[level];
2784 assert(teximage);
Brian Paul7dac1322000-06-15 19:57:14 +00002785
2786 /* get image from frame buffer */
2787 image = read_color_image(ctx, x, y, width, height);
2788 if (!image) {
2789 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
2790 return;
Brian Paulc3f0a511999-11-03 17:27:05 +00002791 }
Brian Paul7dac1322000-06-15 19:57:14 +00002792
2793 /* now call glTexSubImage2D to do the real work */
2794 unpackSave = ctx->Unpack;
2795 ctx->Unpack = _mesa_native_packing;
2796 _mesa_TexSubImage3D(target, level, xoffset, yoffset, zoffset,
2797 width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
2798 ctx->Unpack = unpackSave;
2799
2800 FREE(image);
jtgafb833d1999-08-19 00:55:39 +00002801 }
2802}
Brian Paul1207bf02000-05-23 20:10:49 +00002803
2804
2805
2806void
2807_mesa_CompressedTexImage1DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00002808 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00002809 GLint border, GLsizei imageSize,
2810 const GLvoid *data)
2811{
Brian Paulaea66b12000-05-24 14:04:06 +00002812 GET_CURRENT_CONTEXT(ctx);
2813 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage1DARB");
2814
Brian Paul289d47e2000-08-29 23:31:23 +00002815 switch (internalFormat) {
2816 case GL_COMPRESSED_ALPHA_ARB:
2817 case GL_COMPRESSED_LUMINANCE_ARB:
2818 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
2819 case GL_COMPRESSED_INTENSITY_ARB:
2820 case GL_COMPRESSED_RGB_ARB:
2821 case GL_COMPRESSED_RGBA_ARB:
2822 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB");
2823 return;
2824 default:
2825 /* silence compiler warning */
2826 ;
2827 }
2828
Brian Paulaea66b12000-05-24 14:04:06 +00002829 if (target == GL_TEXTURE_1D) {
2830 struct gl_texture_unit *texUnit;
2831 struct gl_texture_object *texObj;
2832 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00002833 GLsizei computedImageSize;
Brian Paulaea66b12000-05-24 14:04:06 +00002834
2835 if (texture_error_check(ctx, target, level, internalFormat,
2836 GL_NONE, GL_NONE, 1, width, 1, 1, border)) {
2837 return; /* error in texture image was detected */
2838 }
2839
2840 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2841 texObj = texUnit->CurrentD[1];
2842 texImage = texObj->Image[level];
2843
2844 if (!texImage) {
2845 texImage = _mesa_alloc_texture_image();
2846 texObj->Image[level] = texImage;
2847 if (!texImage) {
2848 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
2849 return;
2850 }
2851 }
2852 else if (texImage->Data) {
2853 FREE(texImage->Data);
2854 texImage->Data = NULL;
2855 }
2856
2857 /* setup the teximage struct's fields */
Brian Paul289d47e2000-08-29 23:31:23 +00002858 init_texture_image(ctx, texImage, width, 1, 1,
2859 border, internalFormat);
Brian Paulaea66b12000-05-24 14:04:06 +00002860
2861 /* process the texture image */
2862 if (data) {
2863 GLboolean retain = GL_TRUE;
2864 GLboolean success = GL_FALSE;
2865 if (ctx->Driver.CompressedTexImage1D) {
Brian Paul289d47e2000-08-29 23:31:23 +00002866 success = (*ctx->Driver.CompressedTexImage1D)(ctx, target, level,
2867 imageSize, data, texObj, texImage, &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00002868 }
2869 if (retain || !success) {
2870 /* make internal copy of the texture image */
Brian Paul289d47e2000-08-29 23:31:23 +00002871 computedImageSize = _mesa_compressed_image_size(ctx,
2872 internalFormat,
2873 1, /* num dims */
2874 width,
2875 1, /* height */
2876 1); /* depth */
2877 if (computedImageSize != imageSize) {
2878 gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage1DARB(imageSize)");
2879 return;
2880 }
2881 texImage->Data = MALLOC(computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00002882 if (texImage->Data) {
Brian Paul289d47e2000-08-29 23:31:23 +00002883 MEMCPY(texImage->Data, data, computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00002884 }
2885 }
2886 if (!retain && texImage->Data) {
2887 FREE(texImage->Data);
2888 texImage->Data = NULL;
2889 }
2890 }
2891 else {
2892 make_null_texture(texImage);
2893 if (ctx->Driver.CompressedTexImage1D) {
2894 GLboolean retain;
Brian Paul289d47e2000-08-29 23:31:23 +00002895 (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 0,
2896 texImage->Data, texObj,
2897 texImage, &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00002898 }
2899 }
2900
2901 /* state update */
2902 gl_put_texobj_on_dirty_list( ctx, texObj );
2903 ctx->NewState |= NEW_TEXTURING;
2904 }
2905 else if (target == GL_PROXY_TEXTURE_1D) {
2906 /* Proxy texture: check for errors and update proxy state */
2907 if (texture_error_check(ctx, target, level, internalFormat,
2908 GL_NONE, GL_NONE, 1, width, 1, 1, border)) {
2909 /* if error, clear all proxy texture image parameters */
2910 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00002911 clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00002912 }
2913 }
2914 else {
2915 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00002916 init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00002917 width, 1, 1, border, internalFormat);
2918 }
2919 }
2920 else {
2921 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" );
2922 return;
2923 }
Brian Paul1207bf02000-05-23 20:10:49 +00002924}
2925
2926
2927void
2928_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00002929 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00002930 GLsizei height, GLint border, GLsizei imageSize,
2931 const GLvoid *data)
2932{
Brian Paulaea66b12000-05-24 14:04:06 +00002933 GET_CURRENT_CONTEXT(ctx);
2934 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage2DARB");
2935
Brian Paul289d47e2000-08-29 23:31:23 +00002936 switch (internalFormat) {
2937 case GL_COMPRESSED_ALPHA_ARB:
2938 case GL_COMPRESSED_LUMINANCE_ARB:
2939 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
2940 case GL_COMPRESSED_INTENSITY_ARB:
2941 case GL_COMPRESSED_RGB_ARB:
2942 case GL_COMPRESSED_RGBA_ARB:
2943 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB");
2944 return;
2945 default:
2946 /* silence compiler warning */
2947 ;
2948 }
2949
Brian Paul9540a1d2000-06-06 17:03:38 +00002950 if (target==GL_TEXTURE_2D ||
2951 (ctx->Extensions.HaveTextureCubeMap &&
2952 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
2953 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
Brian Paulaea66b12000-05-24 14:04:06 +00002954 struct gl_texture_unit *texUnit;
2955 struct gl_texture_object *texObj;
2956 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00002957 GLsizei computedImageSize;
Brian Paulaea66b12000-05-24 14:04:06 +00002958
2959 if (texture_error_check(ctx, target, level, internalFormat,
2960 GL_NONE, GL_NONE, 1, width, height, 1, border)) {
2961 return; /* error in texture image was detected */
2962 }
2963
2964 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2965 texObj = texUnit->CurrentD[2];
2966 texImage = texObj->Image[level];
2967
2968 if (!texImage) {
2969 texImage = _mesa_alloc_texture_image();
2970 texObj->Image[level] = texImage;
2971 if (!texImage) {
2972 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
2973 return;
2974 }
2975 }
2976 else if (texImage->Data) {
2977 FREE(texImage->Data);
2978 texImage->Data = NULL;
2979 }
2980
2981 /* setup the teximage struct's fields */
Brian Paul289d47e2000-08-29 23:31:23 +00002982 init_texture_image(ctx, texImage, width, height, 1, border, internalFormat);
Brian Paulaea66b12000-05-24 14:04:06 +00002983
2984 /* process the texture image */
2985 if (data) {
2986 GLboolean retain = GL_TRUE;
2987 GLboolean success = GL_FALSE;
2988 if (ctx->Driver.CompressedTexImage2D) {
Brian Paul289d47e2000-08-29 23:31:23 +00002989 success = (*ctx->Driver.CompressedTexImage2D)( ctx,
2990 target,
2991 level,
2992 imageSize,
2993 data,
2994 texObj,
2995 texImage,
2996 &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00002997 }
2998 if (retain || !success) {
2999 /* make internal copy of the texture image */
Brian Paul289d47e2000-08-29 23:31:23 +00003000 computedImageSize = _mesa_compressed_image_size(ctx,
3001 internalFormat,
3002 2, /* num dims */
3003 width,
3004 height,
3005 1); /* depth */
3006 if (computedImageSize != imageSize) {
3007 gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage2DARB(imageSize)");
3008 return;
3009 }
3010 texImage->Data = MALLOC(computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00003011 if (texImage->Data) {
Brian Paul289d47e2000-08-29 23:31:23 +00003012 MEMCPY(texImage->Data, data, computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00003013 }
3014 }
3015 if (!retain && texImage->Data) {
3016 FREE(texImage->Data);
3017 texImage->Data = NULL;
3018 }
3019 }
3020 else {
3021 make_null_texture(texImage);
3022 if (ctx->Driver.CompressedTexImage2D) {
3023 GLboolean retain;
Brian Paul289d47e2000-08-29 23:31:23 +00003024 (*ctx->Driver.CompressedTexImage2D)( ctx, target, level, 0,
3025 texImage->Data, texObj,
3026 texImage, &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00003027 }
3028 }
3029
3030 /* state update */
3031 gl_put_texobj_on_dirty_list( ctx, texObj );
3032 ctx->NewState |= NEW_TEXTURING;
3033 }
3034 else if (target == GL_PROXY_TEXTURE_2D) {
3035 /* Proxy texture: check for errors and update proxy state */
3036 if (texture_error_check(ctx, target, level, internalFormat,
3037 GL_NONE, GL_NONE, 1, width, 1, 1, border)) {
3038 /* if error, clear all proxy texture image parameters */
3039 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00003040 clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00003041 }
3042 }
3043 else {
3044 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00003045 init_texture_image(ctx, ctx->Texture.Proxy2D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00003046 width, 1, 1, border, internalFormat);
3047 }
3048 }
3049 else {
3050 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" );
3051 return;
3052 }
Brian Paul1207bf02000-05-23 20:10:49 +00003053}
3054
3055
3056void
3057_mesa_CompressedTexImage3DARB(GLenum target, GLint level,
Brian Paulaea66b12000-05-24 14:04:06 +00003058 GLenum internalFormat, GLsizei width,
Brian Paul1207bf02000-05-23 20:10:49 +00003059 GLsizei height, GLsizei depth, GLint border,
3060 GLsizei imageSize, const GLvoid *data)
3061{
Brian Paulaea66b12000-05-24 14:04:06 +00003062 GET_CURRENT_CONTEXT(ctx);
3063 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage3DARB");
3064
Brian Paul289d47e2000-08-29 23:31:23 +00003065 switch (internalFormat) {
3066 case GL_COMPRESSED_ALPHA_ARB:
3067 case GL_COMPRESSED_LUMINANCE_ARB:
3068 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
3069 case GL_COMPRESSED_INTENSITY_ARB:
3070 case GL_COMPRESSED_RGB_ARB:
3071 case GL_COMPRESSED_RGBA_ARB:
3072 gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB");
3073 return;
3074 default:
3075 /* silence compiler warning */
3076 ;
3077 }
3078
Brian Paul9540a1d2000-06-06 17:03:38 +00003079 if (target == GL_TEXTURE_3D) {
Brian Paulaea66b12000-05-24 14:04:06 +00003080 struct gl_texture_unit *texUnit;
3081 struct gl_texture_object *texObj;
3082 struct gl_texture_image *texImage;
Brian Paul289d47e2000-08-29 23:31:23 +00003083 GLsizei computedImageSize;
Brian Paulaea66b12000-05-24 14:04:06 +00003084
3085 if (texture_error_check(ctx, target, level, internalFormat,
3086 GL_NONE, GL_NONE, 1, width, height, depth, border)) {
3087 return; /* error in texture image was detected */
3088 }
3089
3090 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
3091 texObj = texUnit->CurrentD[3];
3092 texImage = texObj->Image[level];
3093
3094 if (!texImage) {
3095 texImage = _mesa_alloc_texture_image();
3096 texObj->Image[level] = texImage;
3097 if (!texImage) {
3098 gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
3099 return;
3100 }
3101 }
3102 else if (texImage->Data) {
3103 FREE(texImage->Data);
3104 texImage->Data = NULL;
3105 }
3106
3107 /* setup the teximage struct's fields */
Brian Paul289d47e2000-08-29 23:31:23 +00003108 init_texture_image(ctx, texImage, width, height, depth,
3109 border, internalFormat);
Brian Paulaea66b12000-05-24 14:04:06 +00003110
3111 /* process the texture image */
3112 if (data) {
3113 GLboolean retain = GL_TRUE;
3114 GLboolean success = GL_FALSE;
3115 if (ctx->Driver.CompressedTexImage3D) {
Brian Paul289d47e2000-08-29 23:31:23 +00003116 success = (*ctx->Driver.CompressedTexImage3D)(ctx, target, level,
3117 imageSize, data,
3118 texObj, texImage,
3119 &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00003120 }
3121 if (retain || !success) {
3122 /* make internal copy of the texture image */
Brian Paul289d47e2000-08-29 23:31:23 +00003123 computedImageSize = _mesa_compressed_image_size(ctx,
3124 internalFormat,
3125 3, /* num dims */
3126 width,
3127 height,
3128 depth);
3129 if (computedImageSize != imageSize) {
3130 gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage3DARB(imageSize)");
3131 return;
3132 }
3133 texImage->Data = MALLOC(computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00003134 if (texImage->Data) {
Brian Paul289d47e2000-08-29 23:31:23 +00003135 MEMCPY(texImage->Data, data, computedImageSize);
Brian Paulaea66b12000-05-24 14:04:06 +00003136 }
3137 }
3138 if (!retain && texImage->Data) {
3139 FREE(texImage->Data);
3140 texImage->Data = NULL;
3141 }
3142 }
3143 else {
3144 make_null_texture(texImage);
3145 if (ctx->Driver.CompressedTexImage3D) {
3146 GLboolean retain;
Brian Paul289d47e2000-08-29 23:31:23 +00003147 (*ctx->Driver.CompressedTexImage3D)( ctx, target, level, 0,
3148 texImage->Data, texObj,
3149 texImage, &retain);
Brian Paulaea66b12000-05-24 14:04:06 +00003150 }
3151 }
3152
3153 /* state update */
3154 gl_put_texobj_on_dirty_list( ctx, texObj );
3155 ctx->NewState |= NEW_TEXTURING;
3156 }
3157 else if (target == GL_PROXY_TEXTURE_3D) {
3158 /* Proxy texture: check for errors and update proxy state */
3159 if (texture_error_check(ctx, target, level, internalFormat,
3160 GL_NONE, GL_NONE, 1, width, height, depth, border)) {
3161 /* if error, clear all proxy texture image parameters */
3162 if (level>=0 && level<ctx->Const.MaxTextureLevels) {
Brian Paul9c272782000-09-05 22:04:30 +00003163 clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]);
Brian Paulaea66b12000-05-24 14:04:06 +00003164 }
3165 }
3166 else {
3167 /* if no error, update proxy texture image parameters */
Brian Paul289d47e2000-08-29 23:31:23 +00003168 init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level],
Brian Paulaea66b12000-05-24 14:04:06 +00003169 width, 1, 1, border, internalFormat);
3170 }
3171 }
3172 else {
3173 gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" );
3174 return;
3175 }
Brian Paul1207bf02000-05-23 20:10:49 +00003176}
3177
3178
3179void
3180_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
3181 GLsizei width, GLenum format,
3182 GLsizei imageSize, const GLvoid *data)
3183{
Brian Paul9540a1d2000-06-06 17:03:38 +00003184 GET_CURRENT_CONTEXT(ctx);
3185 struct gl_texture_unit *texUnit;
3186 struct gl_texture_object *texObj;
3187 struct gl_texture_image *texImage;
3188 GLboolean success = GL_FALSE;
3189
3190 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
3191 width, 1, 1, format, GL_NONE)) {
3192 return; /* error was detected */
3193 }
3194
3195 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
3196 texObj = _mesa_select_tex_object(ctx, texUnit, target);
3197 texImage = texObj->Image[level];
3198 assert(texImage);
3199
3200 if (width == 0 || !data)
3201 return; /* no-op, not an error */
3202
3203 if (ctx->Driver.CompressedTexSubImage1D) {
3204 success = (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level,
3205 xoffset, width, format, imageSize, data, texObj, texImage);
3206 }
3207 if (!success) {
3208 /* XXX what else can we do? */
3209 gl_problem(ctx, "glCompressedTexSubImage1DARB failed!");
3210 return;
3211 }
Brian Paul1207bf02000-05-23 20:10:49 +00003212}
3213
3214
3215void
3216_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
3217 GLint yoffset, GLsizei width, GLsizei height,
3218 GLenum format, GLsizei imageSize,
3219 const GLvoid *data)
3220{
Brian Paul9540a1d2000-06-06 17:03:38 +00003221 GET_CURRENT_CONTEXT(ctx);
3222 struct gl_texture_unit *texUnit;
3223 struct gl_texture_object *texObj;
3224 struct gl_texture_image *texImage;
3225 GLboolean success = GL_FALSE;
3226
3227 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
3228 width, height, 1, format, GL_NONE)) {
3229 return; /* error was detected */
3230 }
3231
3232 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
3233 texObj = _mesa_select_tex_object(ctx, texUnit, target);
3234 texImage = texObj->Image[level];
3235 assert(texImage);
3236
3237 if (width == 0 || height == 0 || !data)
3238 return; /* no-op, not an error */
3239
3240 if (ctx->Driver.CompressedTexSubImage2D) {
3241 success = (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level,
3242 xoffset, yoffset, width, height, format,
3243 imageSize, data, texObj, texImage);
3244 }
3245 if (!success) {
3246 /* XXX what else can we do? */
3247 gl_problem(ctx, "glCompressedTexSubImage2DARB failed!");
3248 return;
3249 }
Brian Paul1207bf02000-05-23 20:10:49 +00003250}
3251
3252
3253void
3254_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
3255 GLint yoffset, GLint zoffset, GLsizei width,
3256 GLsizei height, GLsizei depth, GLenum format,
3257 GLsizei imageSize, const GLvoid *data)
3258{
Brian Paul9540a1d2000-06-06 17:03:38 +00003259 GET_CURRENT_CONTEXT(ctx);
3260 struct gl_texture_unit *texUnit;
3261 struct gl_texture_object *texObj;
3262 struct gl_texture_image *texImage;
3263 GLboolean success = GL_FALSE;
3264
3265 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
3266 width, height, depth, format, GL_NONE)) {
3267 return; /* error was detected */
3268 }
3269
3270 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
3271 texObj = _mesa_select_tex_object(ctx, texUnit, target);
3272 texImage = texObj->Image[level];
3273 assert(texImage);
3274
3275 if (width == 0 || height == 0 || depth == 0 || !data)
3276 return; /* no-op, not an error */
3277
3278 if (ctx->Driver.CompressedTexSubImage3D) {
3279 success = (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level,
3280 xoffset, yoffset, zoffset, width, height, depth,
3281 format, imageSize, data, texObj, texImage);
3282 }
3283 if (!success) {
3284 /* XXX what else can we do? */
3285 gl_problem(ctx, "glCompressedTexSubImage3DARB failed!");
3286 return;
3287 }
Brian Paul1207bf02000-05-23 20:10:49 +00003288}
3289
3290
3291void
Brian Paul9540a1d2000-06-06 17:03:38 +00003292_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
Brian Paul1207bf02000-05-23 20:10:49 +00003293{
Brian Paul9540a1d2000-06-06 17:03:38 +00003294 GET_CURRENT_CONTEXT(ctx);
3295 const struct gl_texture_object *texObj;
3296 struct gl_texture_image *texImage;
3297
3298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetCompressedTexImageARB");
3299
3300 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
3301 gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" );
3302 return;
3303 }
3304
3305 switch (target) {
3306 case GL_TEXTURE_1D:
3307 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[1];
3308 texImage = texObj->Image[level];
3309 break;
3310 case GL_TEXTURE_2D:
3311 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[2];
3312 texImage = texObj->Image[level];
3313 break;
3314 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
3315 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3316 texImage = texObj->Image[level];
3317 break;
3318 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
3319 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3320 texImage = texObj->NegX[level];
3321 break;
3322 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
3323 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3324 texImage = texObj->PosY[level];
3325 break;
3326 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
3327 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3328 texImage = texObj->NegY[level];
3329 break;
3330 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
3331 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3332 texImage = texObj->PosZ[level];
3333 break;
3334 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
3335 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap;
3336 texImage = texObj->NegZ[level];
3337 break;
3338 case GL_TEXTURE_3D:
3339 texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[3];
3340 texImage = texObj->Image[level];
3341 break;
3342 default:
3343 gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
3344 return;
3345 }
3346
3347 if (!texImage) {
3348 /* invalid mipmap level */
3349 gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)");
3350 return;
3351 }
3352
3353 if (!texImage->IsCompressed) {
3354 gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB");
3355 return;
3356 }
3357
3358 if (!img)
3359 return;
3360
3361 if (ctx->Driver.GetCompressedTexImage) {
3362 (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj,
3363 texImage);
3364 }
3365 else {
3366 gl_problem(ctx, "Driver doesn't implement GetCompressedTexImage");
3367 }
Brian Paul1207bf02000-05-23 20:10:49 +00003368}