1 /* $Id: texstore.c,v 1.5 2001/02/17 00:15:39 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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.
51 * Get texture palette entry.
54 palette_sample(GLcontext
*ctx
,
55 const struct gl_texture_object
*tObj
,
56 GLint index
, GLchan rgba
[4] )
58 const GLchan
*palette
;
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
;
67 ASSERT(!tObj
->Palette
.FloatTable
);
68 palette
= (const GLchan
*) tObj
->Palette
.Table
;
69 format
= tObj
->Palette
.Format
;
74 rgba
[ACOMP
] = palette
[index
];
78 rgba
[RCOMP
] = palette
[index
];
80 case GL_LUMINANCE_ALPHA
:
81 rgba
[RCOMP
] = palette
[(index
<< 1) + 0];
82 rgba
[ACOMP
] = palette
[(index
<< 1) + 1];
85 rgba
[RCOMP
] = palette
[index
* 3 + 0];
86 rgba
[GCOMP
] = palette
[index
* 3 + 1];
87 rgba
[BCOMP
] = palette
[index
* 3 + 2];
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];
96 gl_problem(NULL
, "Bad palette format in palette_sample");
103 * Default 1-D texture texel fetch function. This will typically be
104 * overridden by hardware drivers which store their texture images in
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])
113 const GLchan
*data
= (GLchan
*) img
->Data
;
116 GLint width
= img
->Width
;
121 switch (img
->Format
) {
124 GLint index
= data
[i
];
125 palette_sample(ctx
, tObj
, index
, rgba
);
129 rgba
[ACOMP
] = data
[i
];
133 rgba
[RCOMP
] = data
[i
];
135 case GL_LUMINANCE_ALPHA
:
136 texel
= data
+ i
* 2;
137 rgba
[RCOMP
] = texel
[0];
138 rgba
[ACOMP
] = texel
[1];
141 texel
= data
+ i
* 3;
142 rgba
[RCOMP
] = texel
[0];
143 rgba
[GCOMP
] = texel
[1];
144 rgba
[BCOMP
] = texel
[2];
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];
153 case GL_DEPTH_COMPONENT
:
155 const GLfloat
*data
= (const GLfloat
*) img
->Data
;
156 GLfloat
*texel
= (GLfloat
*) rgba
;
161 gl_problem(NULL
, "Bad format in fetch_1d_texel");
168 * Default 2-D texture texel fetch function.
171 fetch_2d_texel(GLcontext
*ctx
,
172 const struct gl_texture_object
*tObj
,
173 const struct gl_texture_image
*img
,
174 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
176 const GLint width
= img
->Width
; /* includes border */
177 const GLchan
*data
= (GLchan
*) img
->Data
;
181 const GLint height
= img
->Height
; /* includes border */
188 switch (img
->Format
) {
191 GLint index
= data
[width
*j
+ i
];
192 palette_sample(ctx
, tObj
, index
, rgba
);
196 rgba
[ACOMP
] = data
[width
* j
+ i
];
200 rgba
[RCOMP
] = data
[ width
* j
+ i
];
202 case GL_LUMINANCE_ALPHA
:
203 texel
= data
+ (width
* j
+ i
) * 2;
204 rgba
[RCOMP
] = texel
[0];
205 rgba
[ACOMP
] = texel
[1];
208 texel
= data
+ (width
* j
+ i
) * 3;
209 rgba
[RCOMP
] = texel
[0];
210 rgba
[GCOMP
] = texel
[1];
211 rgba
[BCOMP
] = texel
[2];
214 texel
= data
+ (width
* j
+ i
) * 4;
215 rgba
[RCOMP
] = texel
[0];
216 rgba
[GCOMP
] = texel
[1];
217 rgba
[BCOMP
] = texel
[2];
218 rgba
[ACOMP
] = texel
[3];
220 case GL_DEPTH_COMPONENT
:
222 const GLfloat
*data
= (const GLfloat
*) img
->Data
;
223 GLfloat
*texel
= (GLfloat
*) rgba
;
224 *texel
= data
[width
* j
+ i
];
228 gl_problem(NULL
, "Bad format in fetch_2d_texel");
234 * Default 2-D texture texel fetch function.
237 fetch_3d_texel(GLcontext
*ctx
,
238 const struct gl_texture_object
*tObj
,
239 const struct gl_texture_image
*img
,
240 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
242 const GLint width
= img
->Width
; /* includes border */
243 const GLint height
= img
->Height
; /* includes border */
244 const GLint rectarea
= width
* height
;
245 const GLchan
*data
= (GLchan
*) img
->Data
;
249 const GLint depth
= img
->Depth
; /* includes border */
258 switch (img
->Format
) {
261 GLint index
= data
[ rectarea
* k
+ width
* j
+ i
];
262 palette_sample(ctx
, tObj
, index
, rgba
);
266 rgba
[ACOMP
] = data
[ rectarea
* k
+ width
* j
+ i
];
270 rgba
[RCOMP
] = data
[ rectarea
* k
+ width
* j
+ i
];
272 case GL_LUMINANCE_ALPHA
:
273 texel
= data
+ ( rectarea
* k
+ width
* j
+ i
) * 2;
274 rgba
[RCOMP
] = texel
[0];
275 rgba
[ACOMP
] = texel
[1];
278 texel
= data
+ (rectarea
* k
+ width
* j
+ i
) * 3;
279 rgba
[RCOMP
] = texel
[0];
280 rgba
[GCOMP
] = texel
[1];
281 rgba
[BCOMP
] = texel
[2];
284 texel
= data
+ (rectarea
* k
+ width
* j
+ i
) * 4;
285 rgba
[RCOMP
] = texel
[0];
286 rgba
[GCOMP
] = texel
[1];
287 rgba
[BCOMP
] = texel
[2];
288 rgba
[ACOMP
] = texel
[3];
290 case GL_DEPTH_COMPONENT
:
292 const GLfloat
*data
= (const GLfloat
*) img
->Data
;
293 GLfloat
*texel
= (GLfloat
*) rgba
;
294 *texel
= data
[rectarea
* k
+ width
* j
+ i
];
298 gl_problem(NULL
, "Bad format in fetch_3d_texel");
305 * Examine the texImage->Format field and set the Red, Green, Blue, etc
306 * texel component sizes to default values.
307 * These fields are set only here by core Mesa but device drivers may
308 * overwritting these fields to indicate true texel resolution.
311 set_teximage_component_sizes( struct gl_texture_image
*texImage
)
313 switch (texImage
->Format
) {
315 texImage
->RedBits
= 0;
316 texImage
->GreenBits
= 0;
317 texImage
->BlueBits
= 0;
318 texImage
->AlphaBits
= 8 * sizeof(GLchan
);
319 texImage
->IntensityBits
= 0;
320 texImage
->LuminanceBits
= 0;
321 texImage
->IndexBits
= 0;
322 texImage
->DepthBits
= 0;
325 texImage
->RedBits
= 0;
326 texImage
->GreenBits
= 0;
327 texImage
->BlueBits
= 0;
328 texImage
->AlphaBits
= 0;
329 texImage
->IntensityBits
= 0;
330 texImage
->LuminanceBits
= 8 * sizeof(GLchan
);
331 texImage
->IndexBits
= 0;
332 texImage
->DepthBits
= 0;
334 case GL_LUMINANCE_ALPHA
:
335 texImage
->RedBits
= 0;
336 texImage
->GreenBits
= 0;
337 texImage
->BlueBits
= 0;
338 texImage
->AlphaBits
= 8 * sizeof(GLchan
);
339 texImage
->IntensityBits
= 0;
340 texImage
->LuminanceBits
= 8 * sizeof(GLchan
);
341 texImage
->IndexBits
= 0;
342 texImage
->DepthBits
= 0;
345 texImage
->RedBits
= 0;
346 texImage
->GreenBits
= 0;
347 texImage
->BlueBits
= 0;
348 texImage
->AlphaBits
= 0;
349 texImage
->IntensityBits
= 8 * sizeof(GLchan
);
350 texImage
->LuminanceBits
= 0;
351 texImage
->IndexBits
= 0;
352 texImage
->DepthBits
= 0;
355 texImage
->RedBits
= 8 * sizeof(GLchan
);
356 texImage
->GreenBits
= 0;
357 texImage
->BlueBits
= 0;
358 texImage
->AlphaBits
= 0;
359 texImage
->IntensityBits
= 0;
360 texImage
->LuminanceBits
= 0;
361 texImage
->IndexBits
= 0;
362 texImage
->DepthBits
= 0;
365 texImage
->RedBits
= 0;
366 texImage
->GreenBits
= 8 * sizeof(GLchan
);
367 texImage
->BlueBits
= 0;
368 texImage
->AlphaBits
= 0;
369 texImage
->IntensityBits
= 0;
370 texImage
->LuminanceBits
= 0;
371 texImage
->IndexBits
= 0;
372 texImage
->DepthBits
= 0;
375 texImage
->RedBits
= 0;
376 texImage
->GreenBits
= 0;
377 texImage
->BlueBits
= 8 * sizeof(GLchan
);
378 texImage
->AlphaBits
= 0;
379 texImage
->IntensityBits
= 0;
380 texImage
->LuminanceBits
= 0;
381 texImage
->IndexBits
= 0;
382 texImage
->DepthBits
= 0;
386 texImage
->RedBits
= 8 * sizeof(GLchan
);
387 texImage
->GreenBits
= 8 * sizeof(GLchan
);
388 texImage
->BlueBits
= 8 * sizeof(GLchan
);
389 texImage
->AlphaBits
= 0;
390 texImage
->IntensityBits
= 0;
391 texImage
->LuminanceBits
= 0;
392 texImage
->IndexBits
= 0;
393 texImage
->DepthBits
= 0;
398 texImage
->RedBits
= 8 * sizeof(GLchan
);
399 texImage
->GreenBits
= 8 * sizeof(GLchan
);
400 texImage
->BlueBits
= 8 * sizeof(GLchan
);
401 texImage
->AlphaBits
= 8 * sizeof(GLchan
);
402 texImage
->IntensityBits
= 0;
403 texImage
->LuminanceBits
= 0;
404 texImage
->IndexBits
= 0;
405 texImage
->DepthBits
= 0;
408 texImage
->RedBits
= 0;
409 texImage
->GreenBits
= 0;
410 texImage
->BlueBits
= 0;
411 texImage
->AlphaBits
= 0;
412 texImage
->IntensityBits
= 0;
413 texImage
->LuminanceBits
= 0;
414 texImage
->IndexBits
= 8 * sizeof(GLchan
);
415 texImage
->DepthBits
= 0;
417 case GL_DEPTH_COMPONENT
:
418 texImage
->RedBits
= 0;
419 texImage
->GreenBits
= 0;
420 texImage
->BlueBits
= 0;
421 texImage
->AlphaBits
= 0;
422 texImage
->IntensityBits
= 0;
423 texImage
->LuminanceBits
= 0;
424 texImage
->IndexBits
= 0;
425 texImage
->DepthBits
= 8 * sizeof(GLfloat
);
428 gl_problem(NULL
, "unexpected format in set_teximage_component_sizes");
435 * Given an internal texture format enum or 1, 2, 3, 4 return the
436 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
437 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the
438 * number of components for the format. Return -1 if invalid enum.
441 components_in_intformat( GLint format
)
458 case GL_LUMINANCE_ALPHA
:
459 case GL_LUMINANCE4_ALPHA4
:
460 case GL_LUMINANCE6_ALPHA2
:
461 case GL_LUMINANCE8_ALPHA8
:
462 case GL_LUMINANCE12_ALPHA4
:
463 case GL_LUMINANCE12_ALPHA12
:
464 case GL_LUMINANCE16_ALPHA16
:
493 case GL_COLOR_INDEX1_EXT
:
494 case GL_COLOR_INDEX2_EXT
:
495 case GL_COLOR_INDEX4_EXT
:
496 case GL_COLOR_INDEX8_EXT
:
497 case GL_COLOR_INDEX12_EXT
:
498 case GL_COLOR_INDEX16_EXT
:
500 case GL_DEPTH_COMPONENT
:
501 case GL_DEPTH_COMPONENT16_SGIX
:
502 case GL_DEPTH_COMPONENT24_SGIX
:
503 case GL_DEPTH_COMPONENT32_SGIX
:
506 return -1; /* error */
512 * This function is used to transfer the user's image data into a texture
513 * image buffer. We handle both full texture images and subtexture images.
514 * We also take care of all image transfer operations here, including
515 * convolution, scale/bias, colortables, etc.
517 * The destination texel channel type is always GLchan.
519 * A hardware driver may use this as a helper routine to unpack and
520 * apply pixel transfer ops into a temporary image buffer. Then,
521 * convert the temporary image into the special hardware format.
524 * dimensions - 1, 2, or 3
525 * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
527 * texAddr - destination image address
528 * srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images
529 * dstXoffset, dstYoffset, dstZoffset - position to store the image within
530 * the destination 3D texture
531 * dstRowStride, dstImageStride - dest image strides in GLchan's
532 * srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc)
533 * srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc
534 * srcPacking - describes packing of incoming image.
537 _mesa_transfer_teximage(GLcontext
*ctx
, GLuint dimensions
,
538 GLenum texFormat
, GLchan
*texAddr
,
539 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
540 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
541 GLint dstRowStride
, GLint dstImageStride
,
542 GLenum srcFormat
, GLenum srcType
,
543 const GLvoid
*srcAddr
,
544 const struct gl_pixelstore_attrib
*srcPacking
)
549 ASSERT(dimensions
>= 1 && dimensions
<= 3);
551 ASSERT(srcWidth
>= 1);
552 ASSERT(srcHeight
>= 1);
553 ASSERT(srcDepth
>= 1);
554 ASSERT(dstXoffset
>= 0);
555 ASSERT(dstYoffset
>= 0);
556 ASSERT(dstZoffset
>= 0);
557 ASSERT(dstRowStride
>= 0);
558 ASSERT(dstImageStride
>= 0);
562 texComponents
= components_in_intformat(texFormat
);
564 /* try common 2D texture cases first */
565 if (!ctx
->_ImageTransferState
&& dimensions
== 2 && srcType
== CHAN_TYPE
) {
567 if (srcFormat
== texFormat
) {
568 /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
569 * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy().
571 const GLchan
*src
= (const GLchan
*) _mesa_image_address(
572 srcPacking
, srcAddr
, srcWidth
, srcHeight
,
573 srcFormat
, srcType
, 0, 0, 0);
574 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
575 srcWidth
, srcFormat
, srcType
);
576 const GLint widthInBytes
= srcWidth
* texComponents
* sizeof(GLchan
);
577 GLchan
*dst
= texAddr
+ dstYoffset
* dstRowStride
578 + dstXoffset
* texComponents
;
579 if (srcRowStride
== widthInBytes
&& dstRowStride
== widthInBytes
) {
580 MEMCPY(dst
, src
, srcHeight
* widthInBytes
);
584 for (i
= 0; i
< srcHeight
; i
++) {
585 MEMCPY(dst
, src
, widthInBytes
);
590 return; /* all done */
592 else if (srcFormat
== GL_RGBA
&& texFormat
== GL_RGB
) {
593 /* commonly used by Quake */
594 const GLchan
*src
= (const GLchan
*) _mesa_image_address(
595 srcPacking
, srcAddr
, srcWidth
, srcHeight
,
596 srcFormat
, srcType
, 0, 0, 0);
597 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
598 srcWidth
, srcFormat
, srcType
);
599 GLchan
*dst
= texAddr
+ dstYoffset
* dstRowStride
600 + dstXoffset
* texComponents
;
602 for (i
= 0; i
< srcHeight
; i
++) {
603 const GLchan
*s
= src
;
605 for (j
= 0; j
< srcWidth
; j
++) {
607 *d
++ = *s
++; /*green*/
608 *d
++ = *s
++; /*blue*/
614 return; /* all done */
619 * General case solutions
621 if (texFormat
== GL_COLOR_INDEX
) {
622 /* color index texture */
623 const GLenum texType
= CHAN_TYPE
;
625 GLchan
*dest
= texAddr
+ dstZoffset
* dstImageStride
626 + dstYoffset
* dstRowStride
627 + dstXoffset
* texComponents
;
628 for (img
= 0; img
< srcDepth
; img
++) {
629 GLchan
*destRow
= dest
;
630 for (row
= 0; row
< srcHeight
; row
++) {
631 const GLvoid
*src
= _mesa_image_address(srcPacking
,
632 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
633 _mesa_unpack_index_span(ctx
, srcWidth
, texType
, destRow
,
634 srcType
, src
, srcPacking
,
635 ctx
->_ImageTransferState
);
636 destRow
+= dstRowStride
;
638 dest
+= dstImageStride
;
641 else if (texFormat
== GL_DEPTH_COMPONENT
) {
642 /* Depth texture (shadow maps) */
643 const GLenum texType
= GL_FLOAT
;
645 GLfloat
*dest
= (GLfloat
*) texAddr
+ dstZoffset
* dstImageStride
646 + dstYoffset
* dstRowStride
647 + dstXoffset
* texComponents
;
648 for (img
= 0; img
< srcDepth
; img
++) {
649 GLfloat
*destRow
= dest
;
650 for (row
= 0; row
< srcHeight
; row
++) {
651 const GLvoid
*src
= _mesa_image_address(srcPacking
,
652 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
655 /* XXX destRow: GLfloat vs. GLdepth? */
657 _mesa_unpack_depth_span(ctx, srcWidth, texType, destRow,
658 srcType, src, srcPacking,
659 ctx->_ImageTransferState);
661 destRow
+= dstRowStride
;
663 dest
+= dstImageStride
;
667 /* regular, color texture */
668 if ((dimensions
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
669 (dimensions
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
670 (dimensions
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
672 * Fill texture image with convolution
675 GLint convWidth
= srcWidth
, convHeight
= srcHeight
;
676 GLfloat
*tmpImage
, *convImage
;
677 tmpImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
679 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
682 convImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
684 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
689 for (img
= 0; img
< srcDepth
; img
++) {
691 GLfloat
*dstf
= tmpImage
;
694 /* unpack and do transfer ops up to convolution */
695 for (row
= 0; row
< srcHeight
; row
++) {
696 const GLvoid
*src
= _mesa_image_address(srcPacking
,
697 srcAddr
, srcWidth
, srcHeight
,
698 srcFormat
, srcType
, img
, row
, 0);
699 _mesa_unpack_float_color_span(ctx
, srcWidth
, GL_RGBA
, dstf
,
700 srcFormat
, srcType
, src
, srcPacking
,
701 ctx
->_ImageTransferState
& IMAGE_PRE_CONVOLUTION_BITS
,
703 dstf
+= srcWidth
* 4;
707 if (dimensions
== 1) {
708 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
709 _mesa_convolve_1d_image(ctx
, &convWidth
, tmpImage
, convImage
);
712 if (ctx
->Pixel
.Convolution2DEnabled
) {
713 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
714 tmpImage
, convImage
);
717 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
718 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
719 tmpImage
, convImage
);
723 /* packing and transfer ops after convolution */
725 dest
= texAddr
+ (dstZoffset
+ img
) * dstImageStride
726 + dstYoffset
* dstRowStride
;
727 for (row
= 0; row
< convHeight
; row
++) {
728 _mesa_pack_float_rgba_span(ctx
, convWidth
,
729 (const GLfloat (*)[4]) srcf
,
730 texFormat
, CHAN_TYPE
,
731 dest
, &_mesa_native_packing
,
732 ctx
->_ImageTransferState
733 & IMAGE_POST_CONVOLUTION_BITS
);
734 srcf
+= convWidth
* 4;
735 dest
+= dstRowStride
;
747 GLchan
*dest
= texAddr
+ dstZoffset
* dstImageStride
748 + dstYoffset
* dstRowStride
749 + dstXoffset
* texComponents
;
750 for (img
= 0; img
< srcDepth
; img
++) {
751 GLchan
*destRow
= dest
;
752 for (row
= 0; row
< srcHeight
; row
++) {
753 const GLvoid
*srcRow
= _mesa_image_address(srcPacking
,
754 srcAddr
, srcWidth
, srcHeight
,
755 srcFormat
, srcType
, img
, row
, 0);
756 _mesa_unpack_chan_color_span(ctx
, srcWidth
, texFormat
, destRow
,
757 srcFormat
, srcType
, srcRow
, srcPacking
,
758 ctx
->_ImageTransferState
);
759 destRow
+= dstRowStride
;
761 dest
+= dstImageStride
;
770 * This is the software fallback for Driver.TexImage1D().
771 * The texture image type will be GLchan.
772 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
773 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
777 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
778 GLint internalFormat
,
779 GLint width
, GLint border
,
780 GLenum format
, GLenum type
, const GLvoid
*pixels
,
781 const struct gl_pixelstore_attrib
*packing
,
782 struct gl_texture_object
*texObj
,
783 struct gl_texture_image
*texImage
)
785 const GLint components
= components_in_intformat(internalFormat
);
787 GLint postConvWidth
= width
;
789 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
790 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
793 /* setup the teximage struct's fields */
794 texImage
->Format
= (GLenum
) _mesa_base_tex_format(ctx
, internalFormat
);
795 if (format
== GL_DEPTH_COMPONENT
) {
796 texImage
->Type
= GL_FLOAT
; /* XXX or GL_UNSIGNED_INT? */
797 compSize
= sizeof(GLfloat
);
800 texImage
->Type
= CHAN_TYPE
; /* usually GL_UNSIGNED_BYTE */
801 compSize
= sizeof(CHAN_TYPE
);
803 texImage
->FetchTexel
= fetch_1d_texel
;
804 set_teximage_component_sizes(texImage
);
806 /* allocate memory */
807 texImage
->Data
= (GLchan
*) MALLOC(postConvWidth
* components
* compSize
);
809 return; /* out of memory */
811 /* unpack image, apply transfer ops and store in texImage->Data */
812 _mesa_transfer_teximage(ctx
, 1, texImage
->Format
, texImage
->Data
,
813 width
, 1, 1, 0, 0, 0,
814 0, /* dstRowStride */
815 0, /* dstImageStride */
816 format
, type
, pixels
, packing
);
821 * This is the software fallback for Driver.TexImage2D().
822 * The texture image type will be GLchan.
823 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
824 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
828 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
829 GLint internalFormat
,
830 GLint width
, GLint height
, GLint border
,
831 GLenum format
, GLenum type
, const void *pixels
,
832 const struct gl_pixelstore_attrib
*packing
,
833 struct gl_texture_object
*texObj
,
834 struct gl_texture_image
*texImage
)
836 const GLint components
= components_in_intformat(internalFormat
);
838 GLint postConvWidth
= width
, postConvHeight
= height
;
840 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
841 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
845 /* setup the teximage struct's fields */
846 texImage
->Format
= (GLenum
) _mesa_base_tex_format(ctx
, internalFormat
);
847 if (format
== GL_DEPTH_COMPONENT
) {
848 texImage
->Type
= GL_FLOAT
; /* XXX or GL_UNSIGNED_INT? */
849 compSize
= sizeof(GLfloat
);
852 texImage
->Type
= CHAN_TYPE
; /* usually GL_UNSIGNED_BYTE */
853 compSize
= sizeof(CHAN_TYPE
);
855 texImage
->FetchTexel
= fetch_2d_texel
;
856 set_teximage_component_sizes(texImage
);
858 /* allocate memory */
859 texImage
->Data
= (GLchan
*) MALLOC(postConvWidth
* postConvHeight
860 * components
* compSize
);
862 return; /* out of memory */
864 /* unpack image, apply transfer ops and store in texImage->Data */
865 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, texImage
->Data
,
866 width
, height
, 1, 0, 0, 0,
867 texImage
->Width
* components
* sizeof(GLchan
),
868 0, /* dstImageStride */
869 format
, type
, pixels
, packing
);
875 * This is the software fallback for Driver.TexImage3D().
876 * The texture image type will be GLchan.
877 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
878 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
882 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
883 GLint internalFormat
,
884 GLint width
, GLint height
, GLint depth
, GLint border
,
885 GLenum format
, GLenum type
, const void *pixels
,
886 const struct gl_pixelstore_attrib
*packing
,
887 struct gl_texture_object
*texObj
,
888 struct gl_texture_image
*texImage
)
890 const GLint components
= components_in_intformat(internalFormat
);
893 /* setup the teximage struct's fields */
894 texImage
->Format
= (GLenum
) _mesa_base_tex_format(ctx
, internalFormat
);
895 if (format
== GL_DEPTH_COMPONENT
) {
896 texImage
->Type
= GL_FLOAT
; /* XXX or GL_UNSIGNED_INT? */
897 compSize
= sizeof(GLfloat
);
900 texImage
->Type
= CHAN_TYPE
; /* usually GL_UNSIGNED_BYTE */
901 compSize
= sizeof(CHAN_TYPE
);
903 texImage
->FetchTexel
= fetch_3d_texel
;
904 set_teximage_component_sizes(texImage
);
906 /* allocate memory */
907 texImage
->Data
= (GLchan
*) MALLOC(width
* height
* depth
908 * components
* compSize
);
910 return; /* out of memory */
912 /* unpack image, apply transfer ops and store in texImage->Data */
913 _mesa_transfer_teximage(ctx
, 3, texImage
->Format
, texImage
->Data
,
914 width
, height
, depth
, 0, 0, 0,
915 texImage
->Width
* components
* sizeof(GLchan
),
916 texImage
->Width
* texImage
->Height
* components
918 format
, type
, pixels
, packing
);
925 * This is the software fallback for Driver.TexSubImage1D().
928 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
929 GLint xoffset
, GLint width
,
930 GLenum format
, GLenum type
, const void *pixels
,
931 const struct gl_pixelstore_attrib
*packing
,
932 struct gl_texture_object
*texObj
,
933 struct gl_texture_image
*texImage
)
935 _mesa_transfer_teximage(ctx
, 1, texImage
->Format
, texImage
->Data
,
936 width
, 1, 1, /* src size */
937 xoffset
, 0, 0, /* dest offsets */
938 0, /* dstRowStride */
939 0, /* dstImageStride */
940 format
, type
, pixels
, packing
);
945 * This is the software fallback for Driver.TexSubImage2D().
948 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
949 GLint xoffset
, GLint yoffset
,
950 GLint width
, GLint height
,
951 GLenum format
, GLenum type
, const void *pixels
,
952 const struct gl_pixelstore_attrib
*packing
,
953 struct gl_texture_object
*texObj
,
954 struct gl_texture_image
*texImage
)
956 const GLint components
= components_in_intformat(texImage
->IntFormat
);
957 const GLint compSize
= _mesa_sizeof_type(texImage
->Type
);
958 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, texImage
->Data
,
959 width
, height
, 1, /* src size */
960 xoffset
, yoffset
, 0, /* dest offsets */
961 texImage
->Width
* components
* compSize
,
962 0, /* dstImageStride */
963 format
, type
, pixels
, packing
);
968 * This is the software fallback for Driver.TexSubImage3D().
971 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
972 GLint xoffset
, GLint yoffset
, GLint zoffset
,
973 GLint width
, GLint height
, GLint depth
,
974 GLenum format
, GLenum type
, const void *pixels
,
975 const struct gl_pixelstore_attrib
*packing
,
976 struct gl_texture_object
*texObj
,
977 struct gl_texture_image
*texImage
)
979 const GLint components
= components_in_intformat(texImage
->IntFormat
);
980 const GLint compSize
= _mesa_sizeof_type(texImage
->Type
);
981 _mesa_transfer_teximage(ctx
, 3, texImage
->Format
, texImage
->Data
,
982 width
, height
, depth
, /* src size */
983 xoffset
, yoffset
, xoffset
, /* dest offsets */
984 texImage
->Width
* components
* compSize
,
985 texImage
->Width
* texImage
->Height
* components
987 format
, type
, pixels
, packing
);
993 * Fallback for Driver.CompressedTexImage1D()
996 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
997 GLint internalFormat
,
998 GLint width
, GLint border
,
999 GLsizei imageSize
, const GLvoid
*data
,
1000 struct gl_texture_object
*texObj
,
1001 struct gl_texture_image
*texImage
)
1004 * The device driver has to do it all.
1011 * Fallback for Driver.CompressedTexImage2D()
1014 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
1015 GLint internalFormat
,
1016 GLint width
, GLint height
, GLint border
,
1017 GLsizei imageSize
, const GLvoid
*data
,
1018 struct gl_texture_object
*texObj
,
1019 struct gl_texture_image
*texImage
)
1022 * The device driver has to do it all.
1029 * Fallback for Driver.CompressedTexImage3D()
1032 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
1033 GLint internalFormat
,
1034 GLint width
, GLint height
, GLint depth
,
1036 GLsizei imageSize
, const GLvoid
*data
,
1037 struct gl_texture_object
*texObj
,
1038 struct gl_texture_image
*texImage
)
1041 * The device driver has to do it all.
1051 * This is the fallback for Driver.TestProxyTexImage().
1054 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1055 GLint internalFormat
, GLenum format
, GLenum type
,
1056 GLint width
, GLint height
, GLint depth
, GLint border
)
1058 struct gl_texture_unit
*texUnit
;
1059 struct gl_texture_object
*texObj
;
1060 struct gl_texture_image
*texImage
;
1066 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1067 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1068 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1071 * The core Mesa code will have already tested the image size, etc.
1072 * Drivers may have more stringent texture limits to enforce and will
1073 * have to override this function.
1075 /* setup the teximage struct's fields */
1076 texImage
->Format
= (GLenum
) _mesa_base_tex_format(ctx
, internalFormat
);
1077 if (format
== GL_DEPTH_COMPONENT
) {
1078 texImage
->Type
= GL_FLOAT
; /* XXX or GL_UNSIGNED_INT? */
1079 compSize
= sizeof(GLfloat
);
1082 texImage
->Type
= CHAN_TYPE
; /* usually GL_UNSIGNED_BYTE */
1083 compSize
= sizeof(CHAN_TYPE
);
1085 set_teximage_component_sizes(texImage
);