1 /* $Id: texstore.c,v 1.22 2001/04/04 21:54:21 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.
47 #include "texformat.h"
54 * Given an internal texture format enum or 1, 2, 3, 4 return the
55 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
56 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the
57 * number of components for the format. Return -1 if invalid enum.
59 * GH: Do we really need this? We have the number of bytes per texel
60 * in the texture format structures, so why don't we just use that?
63 components_in_intformat( GLint format
)
80 case GL_LUMINANCE_ALPHA
:
81 case GL_LUMINANCE4_ALPHA4
:
82 case GL_LUMINANCE6_ALPHA2
:
83 case GL_LUMINANCE8_ALPHA8
:
84 case GL_LUMINANCE12_ALPHA4
:
85 case GL_LUMINANCE12_ALPHA12
:
86 case GL_LUMINANCE16_ALPHA16
:
115 case GL_COLOR_INDEX1_EXT
:
116 case GL_COLOR_INDEX2_EXT
:
117 case GL_COLOR_INDEX4_EXT
:
118 case GL_COLOR_INDEX8_EXT
:
119 case GL_COLOR_INDEX12_EXT
:
120 case GL_COLOR_INDEX16_EXT
:
122 case GL_DEPTH_COMPONENT
:
123 case GL_DEPTH_COMPONENT16_SGIX
:
124 case GL_DEPTH_COMPONENT24_SGIX
:
125 case GL_DEPTH_COMPONENT32_SGIX
:
128 return -1; /* error */
134 * This function is used to transfer the user's image data into a texture
135 * image buffer. We handle both full texture images and subtexture images.
136 * We also take care of all image transfer operations here, including
137 * convolution, scale/bias, colortables, etc.
139 * The destination texel channel type is always GLchan.
141 * A hardware driver may use this as a helper routine to unpack and
142 * apply pixel transfer ops into a temporary image buffer. Then,
143 * convert the temporary image into the special hardware format.
146 * dimensions - 1, 2, or 3
147 * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
149 * texDestAddr - destination image address
150 * srcWidth, srcHeight, srcDepth - size (in pixels) of src and dest images
151 * dstXoffset, dstYoffset, dstZoffset - position to store the image within
152 * the destination 3D texture
153 * dstRowStride, dstImageStride - dest image strides in bytes
154 * srcFormat - source image format (GL_ALPHA, GL_RED, GL_RGB, etc)
155 * srcType - GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_FLOAT, etc
156 * srcPacking - describes packing of incoming image.
159 transfer_teximage(GLcontext
*ctx
, GLuint dimensions
,
160 GLenum texDestFormat
, GLvoid
*texDestAddr
,
161 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
162 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
163 GLint dstRowStride
, GLint dstImageStride
,
164 GLenum srcFormat
, GLenum srcType
,
165 const GLvoid
*srcAddr
,
166 const struct gl_pixelstore_attrib
*srcPacking
)
171 ASSERT(dimensions
>= 1 && dimensions
<= 3);
173 ASSERT(srcWidth
>= 1);
174 ASSERT(srcHeight
>= 1);
175 ASSERT(srcDepth
>= 1);
176 ASSERT(dstXoffset
>= 0);
177 ASSERT(dstYoffset
>= 0);
178 ASSERT(dstZoffset
>= 0);
179 ASSERT(dstRowStride
>= 0);
180 ASSERT(dstImageStride
>= 0);
184 texComponents
= components_in_intformat(texDestFormat
);
186 /* try common 2D texture cases first */
187 if (!ctx
->_ImageTransferState
&& dimensions
== 2 && srcType
== CHAN_TYPE
) {
189 if (srcFormat
== texDestFormat
) {
190 /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
191 * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy().
193 const GLchan
*src
= (const GLchan
*) _mesa_image_address(
194 srcPacking
, srcAddr
, srcWidth
, srcHeight
,
195 srcFormat
, srcType
, 0, 0, 0);
196 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
197 srcWidth
, srcFormat
, srcType
);
198 const GLint widthInBytes
= srcWidth
* texComponents
* sizeof(GLchan
);
199 GLchan
*dst
= (GLchan
*) texDestAddr
+ dstYoffset
* dstRowStride
200 + dstXoffset
* texComponents
;
201 if (srcRowStride
== widthInBytes
&& dstRowStride
== widthInBytes
) {
202 MEMCPY(dst
, src
, srcHeight
* widthInBytes
);
206 for (i
= 0; i
< srcHeight
; i
++) {
207 MEMCPY(dst
, src
, widthInBytes
);
212 return; /* all done */
214 else if (srcFormat
== GL_RGBA
&& texDestFormat
== GL_RGB
) {
215 /* commonly used by Quake */
216 const GLchan
*src
= (const GLchan
*) _mesa_image_address(
217 srcPacking
, srcAddr
, srcWidth
, srcHeight
,
218 srcFormat
, srcType
, 0, 0, 0);
219 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
220 srcWidth
, srcFormat
, srcType
);
221 GLchan
*dst
= (GLchan
*) texDestAddr
+ dstYoffset
* dstRowStride
222 + dstXoffset
* texComponents
;
224 for (i
= 0; i
< srcHeight
; i
++) {
225 const GLchan
*s
= src
;
227 for (j
= 0; j
< srcWidth
; j
++) {
229 *d
++ = *s
++; /*green*/
230 *d
++ = *s
++; /*blue*/
236 return; /* all done */
241 * General case solutions
243 if (texDestFormat
== GL_COLOR_INDEX
) {
244 /* color index texture */
245 const GLenum texType
= CHAN_TYPE
;
247 GLchan
*dest
= (GLchan
*) texDestAddr
+ dstZoffset
* dstImageStride
248 + dstYoffset
* dstRowStride
249 + dstXoffset
* texComponents
;
250 for (img
= 0; img
< srcDepth
; img
++) {
251 GLchan
*destRow
= dest
;
252 for (row
= 0; row
< srcHeight
; row
++) {
253 const GLvoid
*src
= _mesa_image_address(srcPacking
,
254 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
255 _mesa_unpack_index_span(ctx
, srcWidth
, texType
, destRow
,
256 srcType
, src
, srcPacking
,
257 ctx
->_ImageTransferState
);
258 destRow
+= dstRowStride
;
260 dest
+= dstImageStride
;
263 else if (texDestFormat
== GL_DEPTH_COMPONENT
) {
264 /* Depth texture (shadow maps) */
266 GLubyte
*dest
= (GLubyte
*) texDestAddr
267 + dstZoffset
* dstImageStride
268 + dstYoffset
* dstRowStride
269 + dstXoffset
* texComponents
;
270 for (img
= 0; img
< srcDepth
; img
++) {
271 GLubyte
*destRow
= dest
;
272 for (row
= 0; row
< srcHeight
; row
++) {
273 const GLvoid
*src
= _mesa_image_address(srcPacking
,
274 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
275 _mesa_unpack_depth_span(ctx
, srcWidth
, (GLfloat
*) destRow
,
276 srcType
, src
, srcPacking
);
277 destRow
+= dstRowStride
;
279 dest
+= dstImageStride
;
283 /* regular, color texture */
284 if ((dimensions
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
285 (dimensions
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
286 (dimensions
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
288 * Fill texture image with convolution
291 GLint convWidth
= srcWidth
, convHeight
= srcHeight
;
292 GLfloat
*tmpImage
, *convImage
;
293 tmpImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
295 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
298 convImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
300 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
305 for (img
= 0; img
< srcDepth
; img
++) {
307 GLfloat
*dstf
= tmpImage
;
310 /* unpack and do transfer ops up to convolution */
311 for (row
= 0; row
< srcHeight
; row
++) {
312 const GLvoid
*src
= _mesa_image_address(srcPacking
,
313 srcAddr
, srcWidth
, srcHeight
,
314 srcFormat
, srcType
, img
, row
, 0);
315 _mesa_unpack_float_color_span(ctx
, srcWidth
, GL_RGBA
, dstf
,
316 srcFormat
, srcType
, src
, srcPacking
,
317 ctx
->_ImageTransferState
& IMAGE_PRE_CONVOLUTION_BITS
,
319 dstf
+= srcWidth
* 4;
323 if (dimensions
== 1) {
324 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
325 _mesa_convolve_1d_image(ctx
, &convWidth
, tmpImage
, convImage
);
328 if (ctx
->Pixel
.Convolution2DEnabled
) {
329 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
330 tmpImage
, convImage
);
333 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
334 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
335 tmpImage
, convImage
);
339 /* packing and transfer ops after convolution */
341 dest
= (GLchan
*) texDestAddr
+ (dstZoffset
+ img
) * dstImageStride
342 + dstYoffset
* dstRowStride
;
343 for (row
= 0; row
< convHeight
; row
++) {
344 _mesa_pack_float_rgba_span(ctx
, convWidth
,
345 (const GLfloat (*)[4]) srcf
,
346 texDestFormat
, CHAN_TYPE
,
347 dest
, &_mesa_native_packing
,
348 ctx
->_ImageTransferState
349 & IMAGE_POST_CONVOLUTION_BITS
);
350 srcf
+= convWidth
* 4;
351 dest
+= dstRowStride
;
363 GLchan
*dest
= (GLchan
*) texDestAddr
+ dstZoffset
* dstImageStride
364 + dstYoffset
* dstRowStride
365 + dstXoffset
* texComponents
;
366 for (img
= 0; img
< srcDepth
; img
++) {
367 GLchan
*destRow
= dest
;
368 for (row
= 0; row
< srcHeight
; row
++) {
369 const GLvoid
*srcRow
= _mesa_image_address(srcPacking
,
370 srcAddr
, srcWidth
, srcHeight
,
371 srcFormat
, srcType
, img
, row
, 0);
372 _mesa_unpack_chan_color_span(ctx
, srcWidth
, texDestFormat
,
373 destRow
, srcFormat
, srcType
, srcRow
,
374 srcPacking
, ctx
->_ImageTransferState
);
375 destRow
+= dstRowStride
;
377 dest
+= dstImageStride
;
386 * Transfer a texture image from user space to <destAddr> applying all
387 * needed image transfer operations and storing the result in the format
388 * specified by <dstFormat>. <dstFormat> may be any format from texformat.h.
390 * dstRowStride - stride between dest rows in bytes
391 * dstImagetride - stride between dest images in bytes
393 * XXX this function is a bit more complicated than it should be. If
394 * _mesa_convert_texsubimage[123]d could handle any dest/source formats
395 * or if transfer_teximage() could store in any MESA_FORMAT_* format, we
396 * could simplify things here.
399 _mesa_transfer_teximage(GLcontext
*ctx
, GLuint dimensions
,
400 const struct gl_texture_format
*dstFormat
,
402 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
403 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
404 GLint dstRowStride
, GLint dstImageStride
,
405 GLenum srcFormat
, GLenum srcType
,
406 const GLvoid
*srcAddr
,
407 const struct gl_pixelstore_attrib
*srcPacking
)
409 const GLint dstRowStridePixels
= dstRowStride
/ dstFormat
->TexelBytes
;
410 const GLint dstImageStridePixels
= dstImageStride
/ dstFormat
->TexelBytes
;
413 /* First, determine if need to make a temporary, intermediate image */
414 if (_mesa_is_hardware_tex_format(dstFormat
)) {
415 if (ctx
->_ImageTransferState
) {
419 if (dimensions
== 1) {
420 makeTemp
= !_mesa_convert_texsubimage1d(dstFormat
->MesaFormat
,
427 else if (dimensions
== 2) {
428 makeTemp
= !_mesa_convert_texsubimage2d(dstFormat
->MesaFormat
,
429 dstXoffset
, dstYoffset
,
437 assert(dimensions
== 3);
438 makeTemp
= !_mesa_convert_texsubimage3d(dstFormat
->MesaFormat
,
439 dstXoffset
, dstYoffset
, dstZoffset
,
440 srcWidth
, srcHeight
, srcDepth
,
441 dstRowStridePixels
, dstImageStridePixels
,
443 srcPacking
, srcAddr
, dstAddr
);
452 /* software texture format */
458 GLint postConvWidth
= srcWidth
, postConvHeight
= srcHeight
;
460 GLuint tmpComps
, tmpTexelSize
;
461 GLint tmpRowStride
, tmpImageStride
;
464 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
465 _mesa_adjust_image_for_convolution(ctx
, dimensions
, &postConvWidth
,
469 tmpFormat
= _mesa_base_tex_format(ctx
, dstFormat
->IntFormat
);
470 tmpComps
= _mesa_components_in_format(tmpFormat
);
471 tmpTexelSize
= tmpComps
* sizeof(CHAN_TYPE
);
472 tmpRowStride
= postConvWidth
* tmpTexelSize
;
473 tmpImageStride
= postConvWidth
* postConvHeight
* tmpTexelSize
;
474 tmpImage
= (GLubyte
*) MALLOC(postConvWidth
* postConvHeight
*
475 srcDepth
* tmpTexelSize
);
479 transfer_teximage(ctx
, dimensions
, tmpFormat
, tmpImage
,
480 srcWidth
, srcHeight
, srcDepth
,
481 0, 0, 0, /* x/y/zoffset */
482 tmpRowStride
, tmpImageStride
,
483 srcFormat
, srcType
, srcAddr
, srcPacking
);
485 /* the temp image is our new source image */
486 srcWidth
= postConvWidth
;
487 srcHeight
= postConvHeight
;
488 srcFormat
= tmpFormat
;
491 srcPacking
= &_mesa_native_packing
;
494 if (_mesa_is_hardware_tex_format(dstFormat
)) {
496 if (dimensions
== 1) {
498 b
= _mesa_convert_texsubimage1d(dstFormat
->MesaFormat
,
506 else if (dimensions
== 2) {
508 b
= _mesa_convert_texsubimage2d(dstFormat
->MesaFormat
,
509 dstXoffset
, dstYoffset
,
519 b
= _mesa_convert_texsubimage3d(dstFormat
->MesaFormat
,
520 dstXoffset
, dstYoffset
, dstZoffset
,
521 srcWidth
, srcHeight
, srcDepth
,
522 dstRowStridePixels
, dstImageStridePixels
,
524 srcPacking
, srcAddr
, dstAddr
);
527 FREE((void *) srcAddr
); /* the temp image */
530 /* software format */
531 GLenum dstBaseFormat
= _mesa_base_tex_format(ctx
, dstFormat
->IntFormat
);
533 transfer_teximage(ctx
, dimensions
, dstBaseFormat
, dstAddr
,
534 srcWidth
, srcHeight
, srcDepth
,
535 dstXoffset
, dstYoffset
, dstZoffset
,
536 dstRowStride
, dstImageStride
,
537 srcFormat
, srcType
, srcAddr
, srcPacking
);
543 * This is the software fallback for Driver.TexImage1D().
544 * The texture image type will be GLchan.
545 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
546 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
550 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
551 GLint internalFormat
,
552 GLint width
, GLint border
,
553 GLenum format
, GLenum type
, const GLvoid
*pixels
,
554 const struct gl_pixelstore_attrib
*packing
,
555 struct gl_texture_object
*texObj
,
556 struct gl_texture_image
*texImage
)
558 GLint postConvWidth
= width
;
561 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
562 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
565 /* choose the texture format */
566 assert(ctx
->Driver
.ChooseTextureFormat
);
567 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
568 internalFormat
, format
, type
);
569 assert(texImage
->TexFormat
);
571 texelBytes
= texImage
->TexFormat
->TexelBytes
;
573 /* allocate memory */
574 texImage
->Data
= MALLOC(postConvWidth
* texelBytes
);
575 if (!texImage
->Data
) {
576 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
580 /* unpack image, apply transfer ops and store in texImage->Data */
581 _mesa_transfer_teximage(ctx
, 1, texImage
->TexFormat
, texImage
->Data
,
582 width
, 1, 1, 0, 0, 0,
583 0, /* dstRowStride */
584 0, /* dstImageStride */
585 format
, type
, pixels
, packing
);
590 * This is the software fallback for Driver.TexImage2D().
591 * The texture image type will be GLchan.
592 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
593 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
597 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
598 GLint internalFormat
,
599 GLint width
, GLint height
, GLint border
,
600 GLenum format
, GLenum type
, const void *pixels
,
601 const struct gl_pixelstore_attrib
*packing
,
602 struct gl_texture_object
*texObj
,
603 struct gl_texture_image
*texImage
)
605 GLint postConvWidth
= width
, postConvHeight
= height
;
608 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
609 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
613 /* choose the texture format */
614 assert(ctx
->Driver
.ChooseTextureFormat
);
615 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
616 internalFormat
, format
, type
);
617 assert(texImage
->TexFormat
);
619 texelBytes
= texImage
->TexFormat
->TexelBytes
;
621 /* allocate memory */
622 texImage
->Data
= MALLOC(postConvWidth
* postConvHeight
* texelBytes
);
623 if (!texImage
->Data
) {
624 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
628 /* unpack image, apply transfer ops and store in texImage->Data */
629 _mesa_transfer_teximage(ctx
, 2, texImage
->TexFormat
, texImage
->Data
,
630 width
, height
, 1, 0, 0, 0,
631 texImage
->Width
* texelBytes
,
632 0, /* dstImageStride */
633 format
, type
, pixels
, packing
);
639 * This is the software fallback for Driver.TexImage3D().
640 * The texture image type will be GLchan.
641 * The texture image format will be GL_COLOR_INDEX, GL_INTENSITY,
642 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_RGB or GL_RGBA.
646 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
647 GLint internalFormat
,
648 GLint width
, GLint height
, GLint depth
, GLint border
,
649 GLenum format
, GLenum type
, const void *pixels
,
650 const struct gl_pixelstore_attrib
*packing
,
651 struct gl_texture_object
*texObj
,
652 struct gl_texture_image
*texImage
)
656 /* choose the texture format */
657 assert(ctx
->Driver
.ChooseTextureFormat
);
658 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
659 internalFormat
, format
, type
);
660 assert(texImage
->TexFormat
);
662 texelBytes
= texImage
->TexFormat
->TexelBytes
;
664 /* allocate memory */
665 texImage
->Data
= MALLOC(width
* height
* depth
* texelBytes
);
666 if (!texImage
->Data
) {
667 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
671 /* unpack image, apply transfer ops and store in texImage->Data */
672 _mesa_transfer_teximage(ctx
, 3, texImage
->TexFormat
, texImage
->Data
,
673 width
, height
, depth
, 0, 0, 0,
674 texImage
->Width
* texelBytes
,
675 texImage
->Width
* texImage
->Height
* texelBytes
,
676 format
, type
, pixels
, packing
);
683 * This is the software fallback for Driver.TexSubImage1D().
686 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
687 GLint xoffset
, GLint width
,
688 GLenum format
, GLenum type
, const void *pixels
,
689 const struct gl_pixelstore_attrib
*packing
,
690 struct gl_texture_object
*texObj
,
691 struct gl_texture_image
*texImage
)
693 _mesa_transfer_teximage(ctx
, 1, texImage
->TexFormat
, texImage
->Data
,
694 width
, 1, 1, /* src size */
695 xoffset
, 0, 0, /* dest offsets */
696 0, /* dstRowStride */
697 0, /* dstImageStride */
698 format
, type
, pixels
, packing
);
703 * This is the software fallback for Driver.TexSubImage2D().
706 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
707 GLint xoffset
, GLint yoffset
,
708 GLint width
, GLint height
,
709 GLenum format
, GLenum type
, const void *pixels
,
710 const struct gl_pixelstore_attrib
*packing
,
711 struct gl_texture_object
*texObj
,
712 struct gl_texture_image
*texImage
)
714 _mesa_transfer_teximage(ctx
, 2, texImage
->TexFormat
, texImage
->Data
,
715 width
, height
, 1, /* src size */
716 xoffset
, yoffset
, 0, /* dest offsets */
717 texImage
->Width
* texImage
->TexFormat
->TexelBytes
,
718 0, /* dstImageStride */
719 format
, type
, pixels
, packing
);
724 * This is the software fallback for Driver.TexSubImage3D().
727 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
728 GLint xoffset
, GLint yoffset
, GLint zoffset
,
729 GLint width
, GLint height
, GLint depth
,
730 GLenum format
, GLenum type
, const void *pixels
,
731 const struct gl_pixelstore_attrib
*packing
,
732 struct gl_texture_object
*texObj
,
733 struct gl_texture_image
*texImage
)
735 const GLint texelBytes
= texImage
->TexFormat
->TexelBytes
;
736 _mesa_transfer_teximage(ctx
, 3, texImage
->TexFormat
, texImage
->Data
,
737 width
, height
, depth
, /* src size */
738 xoffset
, yoffset
, xoffset
, /* dest offsets */
739 texImage
->Width
* texelBytes
,
740 texImage
->Width
* texImage
->Height
* texelBytes
,
741 format
, type
, pixels
, packing
);
748 * Fallback for Driver.CompressedTexImage1D()
751 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
752 GLint internalFormat
,
753 GLint width
, GLint border
,
754 GLsizei imageSize
, const GLvoid
*data
,
755 struct gl_texture_object
*texObj
,
756 struct gl_texture_image
*texImage
)
759 * The device driver has to do it all.
766 * Fallback for Driver.CompressedTexImage2D()
769 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
770 GLint internalFormat
,
771 GLint width
, GLint height
, GLint border
,
772 GLsizei imageSize
, const GLvoid
*data
,
773 struct gl_texture_object
*texObj
,
774 struct gl_texture_image
*texImage
)
777 * The device driver has to do it all.
784 * Fallback for Driver.CompressedTexImage3D()
787 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
788 GLint internalFormat
,
789 GLint width
, GLint height
, GLint depth
,
791 GLsizei imageSize
, const GLvoid
*data
,
792 struct gl_texture_object
*texObj
,
793 struct gl_texture_image
*texImage
)
796 * The device driver has to do it all.
803 * This is the fallback for Driver.TestProxyTexImage().
806 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
807 GLint internalFormat
, GLenum format
, GLenum type
,
808 GLint width
, GLint height
, GLint depth
, GLint border
)
810 struct gl_texture_unit
*texUnit
;
811 struct gl_texture_object
*texObj
;
812 struct gl_texture_image
*texImage
;
817 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
818 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
819 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
822 * The core Mesa code will have already tested the image size, etc.
823 * Drivers may have more stringent texture limits to enforce and will
824 * have to override this function.
826 /* choose the texture format */
827 assert(ctx
->Driver
.ChooseTextureFormat
);
828 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
829 internalFormat
, format
, type
);
830 assert(texImage
->TexFormat
);