remove unused functions
[mesa.git] / src / mesa / main / texstore.c
1 /* $Id: texstore.c,v 1.3 2001/02/07 03:53:07 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
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 * Authors:
29 * Brian Paul
30 */
31
32
33 /*
34 * The functions in this file are mostly related to software texture fallbacks.
35 * This includes texture image transfer/packing and texel fetching.
36 * Hardware drivers will likely override most of this.
37 */
38
39
40
41 #include "context.h"
42 #include "convolve.h"
43 #include "image.h"
44 #include "macros.h"
45 #include "mem.h"
46 #include "teximage.h"
47 #include "texstore.h"
48
49
50 /*
51 * Get texture palette entry.
52 */
53 static void
54 palette_sample(GLcontext *ctx,
55 const struct gl_texture_object *tObj,
56 GLint index, GLchan rgba[4] )
57 {
58 const GLchan *palette;
59 GLenum format;
60
61 if (ctx->Texture.SharedPalette) {
62 ASSERT(!ctx->Texture.Palette.FloatTable);
63 palette = (const GLchan *) ctx->Texture.Palette.Table;
64 format = ctx->Texture.Palette.Format;
65 }
66 else {
67 ASSERT(!tObj->Palette.FloatTable);
68 palette = (const GLchan *) tObj->Palette.Table;
69 format = tObj->Palette.Format;
70 }
71
72 switch (format) {
73 case GL_ALPHA:
74 rgba[ACOMP] = palette[index];
75 return;
76 case GL_LUMINANCE:
77 case GL_INTENSITY:
78 rgba[RCOMP] = palette[index];
79 return;
80 case GL_LUMINANCE_ALPHA:
81 rgba[RCOMP] = palette[(index << 1) + 0];
82 rgba[ACOMP] = palette[(index << 1) + 1];
83 return;
84 case GL_RGB:
85 rgba[RCOMP] = palette[index * 3 + 0];
86 rgba[GCOMP] = palette[index * 3 + 1];
87 rgba[BCOMP] = palette[index * 3 + 2];
88 return;
89 case GL_RGBA:
90 rgba[RCOMP] = palette[(index << 2) + 0];
91 rgba[GCOMP] = palette[(index << 2) + 1];
92 rgba[BCOMP] = palette[(index << 2) + 2];
93 rgba[ACOMP] = palette[(index << 2) + 3];
94 return;
95 default:
96 gl_problem(NULL, "Bad palette format in palette_sample");
97 }
98 }
99
100
101
102 /*
103 * Default 1-D texture texel fetch function. This will typically be
104 * overridden by hardware drivers which store their texture images in
105 * special ways.
106 */
107 static void
108 fetch_1d_texel(GLcontext *ctx,
109 const struct gl_texture_object *tObj,
110 const struct gl_texture_image *img,
111 GLint i, GLint j, GLint k, GLchan rgba[4])
112 {
113 const GLchan *data = (GLchan *) img->Data;
114 const GLchan *texel;
115 #ifdef DEBUG
116 GLint width = img->Width;
117 assert(i >= 0);
118 assert(i < width);
119 #endif
120
121 switch (img->Format) {
122 case GL_COLOR_INDEX:
123 {
124 GLint index = data[i];
125 palette_sample(ctx, tObj, index, rgba);
126 return;
127 }
128 case GL_ALPHA:
129 rgba[ACOMP] = data[i];
130 return;
131 case GL_LUMINANCE:
132 case GL_INTENSITY:
133 rgba[RCOMP] = data[i];
134 return;
135 case GL_LUMINANCE_ALPHA:
136 texel = data + i * 2;
137 rgba[RCOMP] = texel[0];
138 rgba[ACOMP] = texel[1];
139 return;
140 case GL_RGB:
141 texel = data + i * 3;
142 rgba[RCOMP] = texel[0];
143 rgba[GCOMP] = texel[1];
144 rgba[BCOMP] = texel[2];
145 return;
146 case GL_RGBA:
147 texel = data + i * 4;
148 rgba[RCOMP] = texel[0];
149 rgba[GCOMP] = texel[1];
150 rgba[BCOMP] = texel[2];
151 rgba[ACOMP] = texel[3];
152 return;
153 default:
154 gl_problem(NULL, "Bad format in fetch_1d_texel");
155 return;
156 }
157 }
158
159
160 /*
161 * Default 2-D texture texel fetch function.
162 */
163 static void
164 fetch_2d_texel(GLcontext *ctx,
165 const struct gl_texture_object *tObj,
166 const struct gl_texture_image *img,
167 GLint i, GLint j, GLint k, GLchan rgba[4])
168 {
169 const GLint width = img->Width; /* includes border */
170 const GLchan *data = (GLchan *) img->Data;
171 const GLchan *texel;
172
173 #ifdef DEBUG
174 const GLint height = img->Height; /* includes border */
175 assert(i >= 0);
176 assert(i < width);
177 assert(j >= 0);
178 assert(j < height);
179 #endif
180
181 switch (img->Format) {
182 case GL_COLOR_INDEX:
183 {
184 GLint index = data[width *j + i];
185 palette_sample(ctx, tObj, index, rgba );
186 return;
187 }
188 case GL_ALPHA:
189 rgba[ACOMP] = data[width * j + i];
190 return;
191 case GL_LUMINANCE:
192 case GL_INTENSITY:
193 rgba[RCOMP] = data[ width * j + i];
194 return;
195 case GL_LUMINANCE_ALPHA:
196 texel = data + (width * j + i) * 2;
197 rgba[RCOMP] = texel[0];
198 rgba[ACOMP] = texel[1];
199 return;
200 case GL_RGB:
201 texel = data + (width * j + i) * 3;
202 rgba[RCOMP] = texel[0];
203 rgba[GCOMP] = texel[1];
204 rgba[BCOMP] = texel[2];
205 return;
206 case GL_RGBA:
207 texel = data + (width * j + i) * 4;
208 rgba[RCOMP] = texel[0];
209 rgba[GCOMP] = texel[1];
210 rgba[BCOMP] = texel[2];
211 rgba[ACOMP] = texel[3];
212 return;
213 default:
214 gl_problem(NULL, "Bad format in fetch_2d_texel");
215 }
216 }
217
218
219 /*
220 * Default 2-D texture texel fetch function.
221 */
222 static void
223 fetch_3d_texel(GLcontext *ctx,
224 const struct gl_texture_object *tObj,
225 const struct gl_texture_image *img,
226 GLint i, GLint j, GLint k, GLchan rgba[4])
227 {
228 const GLint width = img->Width; /* includes border */
229 const GLint height = img->Height; /* includes border */
230 const GLint rectarea = width * height;
231 const GLchan *data = (GLchan *) img->Data;
232 const GLchan *texel;
233
234 #ifdef DEBUG
235 const GLint depth = img->Depth; /* includes border */
236 assert(i >= 0);
237 assert(i < width);
238 assert(j >= 0);
239 assert(j < height);
240 assert(k >= 0);
241 assert(k < depth);
242 #endif
243
244 switch (img->Format) {
245 case GL_COLOR_INDEX:
246 {
247 GLint index = data[ rectarea * k + width * j + i ];
248 palette_sample(ctx, tObj, index, rgba );
249 return;
250 }
251 case GL_ALPHA:
252 rgba[ACOMP] = data[ rectarea * k + width * j + i ];
253 return;
254 case GL_LUMINANCE:
255 case GL_INTENSITY:
256 rgba[RCOMP] = data[ rectarea * k + width * j + i ];
257 return;
258 case GL_LUMINANCE_ALPHA:
259 texel = data + ( rectarea * k + width * j + i) * 2;
260 rgba[RCOMP] = texel[0];
261 rgba[ACOMP] = texel[1];
262 return;
263 case GL_RGB:
264 texel = data + (rectarea * k + width * j + i) * 3;
265 rgba[RCOMP] = texel[0];
266 rgba[GCOMP] = texel[1];
267 rgba[BCOMP] = texel[2];
268 return;
269 case GL_RGBA:
270 texel = data + (rectarea * k + width * j + i) * 4;
271 rgba[RCOMP] = texel[0];
272 rgba[GCOMP] = texel[1];
273 rgba[BCOMP] = texel[2];
274 rgba[ACOMP] = texel[3];
275 return;
276 default:
277 gl_problem(NULL, "Bad format in fetch_3d_texel");
278 }
279 }
280
281
282
283 /*
284 * Examine the texImage->Format field and set the Red, Green, Blue, etc
285 * texel component sizes to default values.
286 * These fields are set only here by core Mesa but device drivers may
287 * overwritting these fields to indicate true texel resolution.
288 */
289 static void
290 set_teximage_component_sizes( struct gl_texture_image *texImage )
291 {
292 switch (texImage->Format) {
293 case GL_ALPHA:
294 texImage->RedBits = 0;
295 texImage->GreenBits = 0;
296 texImage->BlueBits = 0;
297 texImage->AlphaBits = 8 * sizeof(GLchan);
298 texImage->IntensityBits = 0;
299 texImage->LuminanceBits = 0;
300 texImage->IndexBits = 0;
301 break;
302 case GL_LUMINANCE:
303 texImage->RedBits = 0;
304 texImage->GreenBits = 0;
305 texImage->BlueBits = 0;
306 texImage->AlphaBits = 0;
307 texImage->IntensityBits = 0;
308 texImage->LuminanceBits = 8 * sizeof(GLchan);
309 texImage->IndexBits = 0;
310 break;
311 case GL_LUMINANCE_ALPHA:
312 texImage->RedBits = 0;
313 texImage->GreenBits = 0;
314 texImage->BlueBits = 0;
315 texImage->AlphaBits = 8 * sizeof(GLchan);
316 texImage->IntensityBits = 0;
317 texImage->LuminanceBits = 8 * sizeof(GLchan);
318 texImage->IndexBits = 0;
319 break;
320 case GL_INTENSITY:
321 texImage->RedBits = 0;
322 texImage->GreenBits = 0;
323 texImage->BlueBits = 0;
324 texImage->AlphaBits = 0;
325 texImage->IntensityBits = 8 * sizeof(GLchan);
326 texImage->LuminanceBits = 0;
327 texImage->IndexBits = 0;
328 break;
329 case GL_RED:
330 texImage->RedBits = 8 * sizeof(GLchan);
331 texImage->GreenBits = 0;
332 texImage->BlueBits = 0;
333 texImage->AlphaBits = 0;
334 texImage->IntensityBits = 0;
335 texImage->LuminanceBits = 0;
336 texImage->IndexBits = 0;
337 break;
338 case GL_GREEN:
339 texImage->RedBits = 0;
340 texImage->GreenBits = 8 * sizeof(GLchan);
341 texImage->BlueBits = 0;
342 texImage->AlphaBits = 0;
343 texImage->IntensityBits = 0;
344 texImage->LuminanceBits = 0;
345 texImage->IndexBits = 0;
346 break;
347 case GL_BLUE:
348 texImage->RedBits = 0;
349 texImage->GreenBits = 0;
350 texImage->BlueBits = 8 * sizeof(GLchan);
351 texImage->AlphaBits = 0;
352 texImage->IntensityBits = 0;
353 texImage->LuminanceBits = 0;
354 texImage->IndexBits = 0;
355 break;
356 case GL_RGB:
357 case GL_BGR:
358 texImage->RedBits = 8 * sizeof(GLchan);
359 texImage->GreenBits = 8 * sizeof(GLchan);
360 texImage->BlueBits = 8 * sizeof(GLchan);
361 texImage->AlphaBits = 0;
362 texImage->IntensityBits = 0;
363 texImage->LuminanceBits = 0;
364 texImage->IndexBits = 0;
365 break;
366 case GL_RGBA:
367 case GL_BGRA:
368 case GL_ABGR_EXT:
369 texImage->RedBits = 8 * sizeof(GLchan);
370 texImage->GreenBits = 8 * sizeof(GLchan);
371 texImage->BlueBits = 8 * sizeof(GLchan);
372 texImage->AlphaBits = 8 * sizeof(GLchan);
373 texImage->IntensityBits = 0;
374 texImage->LuminanceBits = 0;
375 texImage->IndexBits = 0;
376 break;
377 case GL_COLOR_INDEX:
378 texImage->RedBits = 0;
379 texImage->GreenBits = 0;
380 texImage->BlueBits = 0;
381 texImage->AlphaBits = 0;
382 texImage->IntensityBits = 0;
383 texImage->LuminanceBits = 0;
384 texImage->IndexBits = 8 * sizeof(GLchan);
385 break;
386 default:
387 gl_problem(NULL, "unexpected format in set_teximage_component_sizes");
388 }
389 }
390
391
392
393 /*
394 * Given an internal texture format enum or 1, 2, 3, 4 return the
395 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
396 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the
397 * number of components for the format. Return -1 if invalid enum.
398 */
399 static GLint
400 components_in_intformat( GLint format )
401 {
402 switch (format) {
403 case GL_ALPHA:
404 case GL_ALPHA4:
405 case GL_ALPHA8:
406 case GL_ALPHA12:
407 case GL_ALPHA16:
408 return 1;
409 case 1:
410 case GL_LUMINANCE:
411 case GL_LUMINANCE4:
412 case GL_LUMINANCE8:
413 case GL_LUMINANCE12:
414 case GL_LUMINANCE16:
415 return 1;
416 case 2:
417 case GL_LUMINANCE_ALPHA:
418 case GL_LUMINANCE4_ALPHA4:
419 case GL_LUMINANCE6_ALPHA2:
420 case GL_LUMINANCE8_ALPHA8:
421 case GL_LUMINANCE12_ALPHA4:
422 case GL_LUMINANCE12_ALPHA12:
423 case GL_LUMINANCE16_ALPHA16:
424 return 2;
425 case GL_INTENSITY:
426 case GL_INTENSITY4:
427 case GL_INTENSITY8:
428 case GL_INTENSITY12:
429 case GL_INTENSITY16:
430 return 1;
431 case 3:
432 case GL_RGB:
433 case GL_R3_G3_B2:
434 case GL_RGB4:
435 case GL_RGB5:
436 case GL_RGB8:
437 case GL_RGB10:
438 case GL_RGB12:
439 case GL_RGB16:
440 return 3;
441 case 4:
442 case GL_RGBA:
443 case GL_RGBA2:
444 case GL_RGBA4:
445 case GL_RGB5_A1:
446 case GL_RGBA8:
447 case GL_RGB10_A2:
448 case GL_RGBA12:
449 case GL_RGBA16:
450 return 4;
451 case GL_COLOR_INDEX:
452 case GL_COLOR_INDEX1_EXT:
453 case GL_COLOR_INDEX2_EXT:
454 case GL_COLOR_INDEX4_EXT:
455 case GL_COLOR_INDEX8_EXT:
456 case GL_COLOR_INDEX12_EXT:
457 case GL_COLOR_INDEX16_EXT:
458 return 1;
459 default:
460 return -1; /* error */
461 }
462 }
463
464
465 /*
466 * This function is used to transfer the user's image data into a texture
467 * image buffer. We handle both full texture images and subtexture images.
468 * We also take care of all image transfer operations here, including
469 * convolution, scale/bias, colortables, etc.
470 *
471 * The destination texel channel type is always GLchan.
472 *
473 * A hardware driver may use this as a helper routine to unpack and
474 * apply pixel transfer ops into a temporary image buffer. Then,
475 * convert the temporary image into the special hardware format.
476 *
477 * Input:
478 * dimensions - 1, 2, or 3
479 * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
480 * GL_RGB or GL_RGBA
481 * texAddr - destination image address
482 * srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images
483 * dstXoffset, dstYoffset, dstZoffset - position to store the image within
484 * the destination 3D texture
485 * dstRowStride, dstImageStride - dest image strides in GLchan's
486 * srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc)
487 * srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc
488 * srcPacking - describes packing of incoming image.
489 */
490 void
491 _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
492 GLenum texFormat, GLchan *texAddr,
493 GLint srcWidth, GLint srcHeight, GLint srcDepth,
494 GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
495 GLint dstRowStride, GLint dstImageStride,
496 GLenum srcFormat, GLenum srcType,
497 const GLvoid *srcAddr,
498 const struct gl_pixelstore_attrib *srcPacking)
499 {
500 GLint texComponents;
501
502 ASSERT(ctx);
503 ASSERT(dimensions >= 1 && dimensions <= 3);
504 ASSERT(texAddr);
505 ASSERT(srcWidth >= 1);
506 ASSERT(srcHeight >= 1);
507 ASSERT(srcDepth >= 1);
508 ASSERT(dstXoffset >= 0);
509 ASSERT(dstYoffset >= 0);
510 ASSERT(dstZoffset >= 0);
511 ASSERT(dstRowStride >= 0);
512 ASSERT(dstImageStride >= 0);
513 ASSERT(srcAddr);
514 ASSERT(srcPacking);
515
516 texComponents = components_in_intformat(texFormat);
517
518 /* try common 2D texture cases first */
519 if (!ctx->_ImageTransferState && dimensions == 2
520 && srcType == GL_UNSIGNED_BYTE) {
521
522 if (srcFormat == texFormat) {
523 /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
524 * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy().
525 */
526 const GLchan *src = (const GLchan *) _mesa_image_address(
527 srcPacking, srcAddr, srcWidth, srcHeight,
528 srcFormat, srcType, 0, 0, 0);
529 const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
530 srcWidth, srcFormat, srcType);
531 const GLint widthInBytes = srcWidth * texComponents * sizeof(GLchan);
532 GLchan *dst = texAddr + dstYoffset * dstRowStride
533 + dstXoffset * texComponents;
534 if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) {
535 MEMCPY(dst, src, srcHeight * widthInBytes);
536 }
537 else {
538 GLint i;
539 for (i = 0; i < srcHeight; i++) {
540 MEMCPY(dst, src, widthInBytes);
541 src += srcRowStride;
542 dst += dstRowStride;
543 }
544 }
545 return; /* all done */
546 }
547 else if (srcFormat == GL_RGBA && texFormat == GL_RGB) {
548 /* commonly used by Quake */
549 const GLchan *src = (const GLchan *) _mesa_image_address(
550 srcPacking, srcAddr, srcWidth, srcHeight,
551 srcFormat, srcType, 0, 0, 0);
552 const GLint srcRowStride = _mesa_image_row_stride(srcPacking,
553 srcWidth, srcFormat, srcType);
554 GLchan *dst = texAddr + dstYoffset * dstRowStride
555 + dstXoffset * texComponents;
556 GLint i, j;
557 for (i = 0; i < srcHeight; i++) {
558 const GLchan *s = src;
559 GLchan *d = dst;
560 for (j = 0; j < srcWidth; j++) {
561 *d++ = *s++; /*red*/
562 *d++ = *s++; /*green*/
563 *d++ = *s++; /*blue*/
564 s++; /*alpha*/
565 }
566 src += srcRowStride;
567 dst += dstRowStride;
568 }
569 return; /* all done */
570 }
571 }
572
573 /*
574 * General case solutions
575 */
576 if (texFormat == GL_COLOR_INDEX) {
577 /* color index texture */
578 const GLenum texType = GL_UNSIGNED_BYTE;
579 GLint img, row;
580 GLchan *dest = texAddr + dstZoffset * dstImageStride
581 + dstYoffset * dstRowStride
582 + dstXoffset * texComponents;
583 for (img = 0; img < srcDepth; img++) {
584 GLchan *destRow = dest;
585 for (row = 0; row < srcHeight; row++) {
586 const GLvoid *src = _mesa_image_address(srcPacking,
587 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
588 _mesa_unpack_index_span(ctx, srcWidth, texType, destRow,
589 srcType, src, srcPacking,
590 ctx->_ImageTransferState);
591 destRow += dstRowStride;
592 }
593 dest += dstImageStride;
594 }
595 }
596 else {
597 /* regular, color texture */
598 if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) ||
599 (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) ||
600 (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) {
601 /*
602 * Fill texture image with convolution
603 */
604 GLint img, row;
605 GLint convWidth = srcWidth, convHeight = srcHeight;
606 GLfloat *tmpImage, *convImage;
607 tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
608 if (!tmpImage) {
609 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
610 return;
611 }
612 convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat));
613 if (!convImage) {
614 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
615 FREE(tmpImage);
616 return;
617 }
618
619 for (img = 0; img < srcDepth; img++) {
620 const GLfloat *srcf;
621 GLfloat *dstf = tmpImage;
622 GLchan *dest;
623
624 /* unpack and do transfer ops up to convolution */
625 for (row = 0; row < srcHeight; row++) {
626 const GLvoid *src = _mesa_image_address(srcPacking,
627 srcAddr, srcWidth, srcHeight,
628 srcFormat, srcType, img, row, 0);
629 _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf,
630 srcFormat, srcType, src, srcPacking,
631 ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS,
632 GL_TRUE);
633 dstf += srcWidth * 4;
634 }
635
636 /* convolve */
637 if (dimensions == 1) {
638 ASSERT(ctx->Pixel.Convolution1DEnabled);
639 _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage);
640 }
641 else {
642 if (ctx->Pixel.Convolution2DEnabled) {
643 _mesa_convolve_2d_image(ctx, &convWidth, &convHeight,
644 tmpImage, convImage);
645 }
646 else {
647 ASSERT(ctx->Pixel.Separable2DEnabled);
648 _mesa_convolve_sep_image(ctx, &convWidth, &convHeight,
649 tmpImage, convImage);
650 }
651 }
652
653 /* packing and transfer ops after convolution */
654 srcf = convImage;
655 dest = texAddr + (dstZoffset + img) * dstImageStride
656 + dstYoffset * dstRowStride;
657 for (row = 0; row < convHeight; row++) {
658 _mesa_pack_float_rgba_span(ctx, convWidth,
659 (const GLfloat (*)[4]) srcf,
660 texFormat, GL_UNSIGNED_BYTE,
661 dest, &_mesa_native_packing,
662 ctx->_ImageTransferState
663 & IMAGE_POST_CONVOLUTION_BITS);
664 srcf += convWidth * 4;
665 dest += dstRowStride;
666 }
667 }
668
669 FREE(convImage);
670 FREE(tmpImage);
671 }
672 else {
673 /*
674 * no convolution
675 */
676 GLint img, row;
677 GLchan *dest = texAddr + dstZoffset * dstImageStride
678 + dstYoffset * dstRowStride
679 + dstXoffset * texComponents;
680 for (img = 0; img < srcDepth; img++) {
681 GLchan *destRow = dest;
682 for (row = 0; row < srcHeight; row++) {
683 const GLvoid *srcRow = _mesa_image_address(srcPacking,
684 srcAddr, srcWidth, srcHeight,
685 srcFormat, srcType, img, row, 0);
686 _mesa_unpack_chan_color_span(ctx, srcWidth, texFormat, destRow,
687 srcFormat, srcType, srcRow, srcPacking,
688 ctx->_ImageTransferState);
689 destRow += dstRowStride;
690 }
691 dest += dstImageStride;
692 }
693 }
694 }
695 }
696
697
698
699 /*
700 * This is the software fallback for Driver.TexImage1D().
701 * The texture image type will be GLchan.
702 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
703 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
704 *
705 */
706 void
707 _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
708 GLint internalFormat,
709 GLint width, GLint border,
710 GLenum format, GLenum type, const GLvoid *pixels,
711 const struct gl_pixelstore_attrib *packing,
712 struct gl_texture_object *texObj,
713 struct gl_texture_image *texImage)
714 {
715 const GLint components = components_in_intformat(internalFormat);
716 GLint postConvWidth = width;
717
718 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
719 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
720 }
721
722 /* setup the teximage struct's fields */
723 texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat);
724 texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */
725 texImage->FetchTexel = fetch_1d_texel;
726 set_teximage_component_sizes(texImage);
727
728 /* allocate memory */
729 texImage->Data = (GLchan *) MALLOC(postConvWidth
730 * components * sizeof(GLchan));
731 if (!texImage->Data)
732 return; /* out of memory */
733
734 /* unpack image, apply transfer ops and store in texImage->Data */
735 _mesa_transfer_teximage(ctx, 1, texImage->Format, texImage->Data,
736 width, 1, 1, 0, 0, 0,
737 0, /* dstRowStride */
738 0, /* dstImageStride */
739 format, type, pixels, packing);
740 }
741
742
743 /*
744 * This is the software fallback for Driver.TexImage2D().
745 * The texture image type will be GLchan.
746 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
747 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
748 *
749 */
750 void
751 _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
752 GLint internalFormat,
753 GLint width, GLint height, GLint border,
754 GLenum format, GLenum type, const void *pixels,
755 const struct gl_pixelstore_attrib *packing,
756 struct gl_texture_object *texObj,
757 struct gl_texture_image *texImage)
758 {
759 const GLint components = components_in_intformat(internalFormat);
760 GLint postConvWidth = width, postConvHeight = height;
761
762 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
763 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
764 &postConvHeight);
765 }
766
767 /* setup the teximage struct's fields */
768 texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat);
769 texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */
770 texImage->FetchTexel = fetch_2d_texel;
771 set_teximage_component_sizes(texImage);
772
773 /* allocate memory */
774 texImage->Data = (GLchan *) MALLOC(postConvWidth * postConvHeight
775 * components * sizeof(GLchan));
776 if (!texImage->Data)
777 return; /* out of memory */
778
779 /* unpack image, apply transfer ops and store in texImage->Data */
780 _mesa_transfer_teximage(ctx, 2, texImage->Format, texImage->Data,
781 width, height, 1, 0, 0, 0,
782 texImage->Width * components * sizeof(GLchan),
783 0, /* dstImageStride */
784 format, type, pixels, packing);
785 }
786
787
788
789 /*
790 * This is the software fallback for Driver.TexImage3D().
791 * The texture image type will be GLchan.
792 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
793 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
794 *
795 */
796 void
797 _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
798 GLint internalFormat,
799 GLint width, GLint height, GLint depth, GLint border,
800 GLenum format, GLenum type, const void *pixels,
801 const struct gl_pixelstore_attrib *packing,
802 struct gl_texture_object *texObj,
803 struct gl_texture_image *texImage)
804 {
805 const GLint components = components_in_intformat(internalFormat);
806
807 /* setup the teximage struct's fields */
808 texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat);
809 texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */
810 texImage->FetchTexel = fetch_3d_texel;
811 set_teximage_component_sizes(texImage);
812
813 /* allocate memory */
814 texImage->Data = (GLchan *) MALLOC(width * height * depth
815 * components * sizeof(GLchan));
816 if (!texImage->Data)
817 return; /* out of memory */
818
819 /* unpack image, apply transfer ops and store in texImage->Data */
820 _mesa_transfer_teximage(ctx, 3, texImage->Format, texImage->Data,
821 width, height, depth, 0, 0, 0,
822 texImage->Width * components * sizeof(GLchan),
823 texImage->Width * texImage->Height * components
824 * sizeof(GLchan),
825 format, type, pixels, packing);
826 }
827
828
829
830
831 /*
832 * This is the software fallback for Driver.TexSubImage1D().
833 */
834 void
835 _mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
836 GLint xoffset, GLint width,
837 GLenum format, GLenum type, const void *pixels,
838 const struct gl_pixelstore_attrib *packing,
839 struct gl_texture_object *texObj,
840 struct gl_texture_image *texImage)
841 {
842 _mesa_transfer_teximage(ctx, 1, texImage->Format, texImage->Data,
843 width, 1, 1, /* src size */
844 xoffset, 0, 0, /* dest offsets */
845 0, /* dstRowStride */
846 0, /* dstImageStride */
847 format, type, pixels, packing);
848 }
849
850
851 /*
852 * This is the software fallback for Driver.TexSubImage2D().
853 */
854 void
855 _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level,
856 GLint xoffset, GLint yoffset,
857 GLint width, GLint height,
858 GLenum format, GLenum type, const void *pixels,
859 const struct gl_pixelstore_attrib *packing,
860 struct gl_texture_object *texObj,
861 struct gl_texture_image *texImage)
862 {
863 const GLint components = components_in_intformat(texImage->IntFormat);
864 _mesa_transfer_teximage(ctx, 2, texImage->Format, texImage->Data,
865 width, height, 1, /* src size */
866 xoffset, yoffset, 0, /* dest offsets */
867 texImage->Width * components * sizeof(GLchan),
868 0, /* dstImageStride */
869 format, type, pixels, packing);
870 }
871
872
873 /*
874 * This is the software fallback for Driver.TexSubImage3D().
875 */
876 void
877 _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
878 GLint xoffset, GLint yoffset, GLint zoffset,
879 GLint width, GLint height, GLint depth,
880 GLenum format, GLenum type, const void *pixels,
881 const struct gl_pixelstore_attrib *packing,
882 struct gl_texture_object *texObj,
883 struct gl_texture_image *texImage)
884 {
885 const GLint components = components_in_intformat(texImage->IntFormat);
886 _mesa_transfer_teximage(ctx, 3, texImage->Format, texImage->Data,
887 width, height, depth, /* src size */
888 xoffset, yoffset, xoffset, /* dest offsets */
889 texImage->Width * components * sizeof(GLchan),
890 texImage->Width * texImage->Height * components
891 * sizeof(GLchan),
892 format, type, pixels, packing);
893 }
894
895
896
897 /*
898 * Fallback for Driver.CompressedTexImage1D()
899 */
900 void
901 _mesa_store_compressed_teximage1d(GLcontext *ctx, GLenum target, GLint level,
902 GLint internalFormat,
903 GLint width, GLint border,
904 GLsizei imageSize, const GLvoid *data,
905 struct gl_texture_object *texObj,
906 struct gl_texture_image *texImage)
907 {
908 /* Nothing here.
909 * The device driver has to do it all.
910 */
911 }
912
913
914
915 /*
916 * Fallback for Driver.CompressedTexImage2D()
917 */
918 void
919 _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
920 GLint internalFormat,
921 GLint width, GLint height, GLint border,
922 GLsizei imageSize, const GLvoid *data,
923 struct gl_texture_object *texObj,
924 struct gl_texture_image *texImage)
925 {
926 /* Nothing here.
927 * The device driver has to do it all.
928 */
929 }
930
931
932
933 /*
934 * Fallback for Driver.CompressedTexImage3D()
935 */
936 void
937 _mesa_store_compressed_teximage3d(GLcontext *ctx, GLenum target, GLint level,
938 GLint internalFormat,
939 GLint width, GLint height, GLint depth,
940 GLint border,
941 GLsizei imageSize, const GLvoid *data,
942 struct gl_texture_object *texObj,
943 struct gl_texture_image *texImage)
944 {
945 /* Nothing here.
946 * The device driver has to do it all.
947 */
948 }
949
950
951
952
953
954
955 /*
956 * This is the fallback for Driver.TestProxyTexImage().
957 */
958 GLboolean
959 _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
960 GLint internalFormat, GLenum format, GLenum type,
961 GLint width, GLint height, GLint depth, GLint border)
962 {
963 struct gl_texture_unit *texUnit;
964 struct gl_texture_object *texObj;
965 struct gl_texture_image *texImage;
966
967 (void) format;
968 (void) type;
969
970 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
971 texObj = _mesa_select_tex_object(ctx, texUnit, target);
972 texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
973
974 /* We always pass.
975 * The core Mesa code will have already tested the image size, etc.
976 * Drivers may have more stringent texture limits to enforce and will
977 * have to override this function.
978 */
979 /* setup the teximage struct's fields */
980 texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat);
981 texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */
982 set_teximage_component_sizes(texImage);
983
984 return GL_TRUE;
985 }
986