1 /* $Id: texstore.c,v 1.3 2001/02/07 03:53:07 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];
154 gl_problem(NULL
, "Bad format in fetch_1d_texel");
161 * Default 2-D texture texel fetch function.
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])
169 const GLint width
= img
->Width
; /* includes border */
170 const GLchan
*data
= (GLchan
*) img
->Data
;
174 const GLint height
= img
->Height
; /* includes border */
181 switch (img
->Format
) {
184 GLint index
= data
[width
*j
+ i
];
185 palette_sample(ctx
, tObj
, index
, rgba
);
189 rgba
[ACOMP
] = data
[width
* j
+ i
];
193 rgba
[RCOMP
] = data
[ width
* j
+ i
];
195 case GL_LUMINANCE_ALPHA
:
196 texel
= data
+ (width
* j
+ i
) * 2;
197 rgba
[RCOMP
] = texel
[0];
198 rgba
[ACOMP
] = texel
[1];
201 texel
= data
+ (width
* j
+ i
) * 3;
202 rgba
[RCOMP
] = texel
[0];
203 rgba
[GCOMP
] = texel
[1];
204 rgba
[BCOMP
] = texel
[2];
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];
214 gl_problem(NULL
, "Bad format in fetch_2d_texel");
220 * Default 2-D texture texel fetch function.
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])
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
;
235 const GLint depth
= img
->Depth
; /* includes border */
244 switch (img
->Format
) {
247 GLint index
= data
[ rectarea
* k
+ width
* j
+ i
];
248 palette_sample(ctx
, tObj
, index
, rgba
);
252 rgba
[ACOMP
] = data
[ rectarea
* k
+ width
* j
+ i
];
256 rgba
[RCOMP
] = data
[ rectarea
* k
+ width
* j
+ i
];
258 case GL_LUMINANCE_ALPHA
:
259 texel
= data
+ ( rectarea
* k
+ width
* j
+ i
) * 2;
260 rgba
[RCOMP
] = texel
[0];
261 rgba
[ACOMP
] = texel
[1];
264 texel
= data
+ (rectarea
* k
+ width
* j
+ i
) * 3;
265 rgba
[RCOMP
] = texel
[0];
266 rgba
[GCOMP
] = texel
[1];
267 rgba
[BCOMP
] = texel
[2];
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];
277 gl_problem(NULL
, "Bad format in fetch_3d_texel");
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.
290 set_teximage_component_sizes( struct gl_texture_image
*texImage
)
292 switch (texImage
->Format
) {
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;
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;
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;
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;
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;
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;
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;
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;
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;
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
);
387 gl_problem(NULL
, "unexpected format in set_teximage_component_sizes");
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.
400 components_in_intformat( GLint format
)
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
:
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
:
460 return -1; /* error */
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.
471 * The destination texel channel type is always GLchan.
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.
478 * dimensions - 1, 2, or 3
479 * texFormat - GL_LUMINANCE, GL_INTENSITY, GL_LUMINANCE_ALPHA, GL_ALPHA,
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.
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
)
503 ASSERT(dimensions
>= 1 && dimensions
<= 3);
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);
516 texComponents
= components_in_intformat(texFormat
);
518 /* try common 2D texture cases first */
519 if (!ctx
->_ImageTransferState
&& dimensions
== 2
520 && srcType
== GL_UNSIGNED_BYTE
) {
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().
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
);
539 for (i
= 0; i
< srcHeight
; i
++) {
540 MEMCPY(dst
, src
, widthInBytes
);
545 return; /* all done */
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
;
557 for (i
= 0; i
< srcHeight
; i
++) {
558 const GLchan
*s
= src
;
560 for (j
= 0; j
< srcWidth
; j
++) {
562 *d
++ = *s
++; /*green*/
563 *d
++ = *s
++; /*blue*/
569 return; /* all done */
574 * General case solutions
576 if (texFormat
== GL_COLOR_INDEX
) {
577 /* color index texture */
578 const GLenum texType
= GL_UNSIGNED_BYTE
;
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
;
593 dest
+= dstImageStride
;
597 /* regular, color texture */
598 if ((dimensions
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
599 (dimensions
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
600 (dimensions
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
602 * Fill texture image with convolution
605 GLint convWidth
= srcWidth
, convHeight
= srcHeight
;
606 GLfloat
*tmpImage
, *convImage
;
607 tmpImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
609 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
612 convImage
= (GLfloat
*) MALLOC(srcWidth
* srcHeight
* 4 * sizeof(GLfloat
));
614 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
619 for (img
= 0; img
< srcDepth
; img
++) {
621 GLfloat
*dstf
= tmpImage
;
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
,
633 dstf
+= srcWidth
* 4;
637 if (dimensions
== 1) {
638 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
639 _mesa_convolve_1d_image(ctx
, &convWidth
, tmpImage
, convImage
);
642 if (ctx
->Pixel
.Convolution2DEnabled
) {
643 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
644 tmpImage
, convImage
);
647 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
648 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
649 tmpImage
, convImage
);
653 /* packing and transfer ops after convolution */
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
;
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
;
691 dest
+= dstImageStride
;
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.
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
)
715 const GLint components
= components_in_intformat(internalFormat
);
716 GLint postConvWidth
= width
;
718 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
719 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
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
);
728 /* allocate memory */
729 texImage
->Data
= (GLchan
*) MALLOC(postConvWidth
730 * components
* sizeof(GLchan
));
732 return; /* out of memory */
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
);
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.
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
)
759 const GLint components
= components_in_intformat(internalFormat
);
760 GLint postConvWidth
= width
, postConvHeight
= height
;
762 if (ctx
->_ImageTransferState
& IMAGE_CONVOLUTION_BIT
) {
763 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
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
);
773 /* allocate memory */
774 texImage
->Data
= (GLchan
*) MALLOC(postConvWidth
* postConvHeight
775 * components
* sizeof(GLchan
));
777 return; /* out of memory */
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
);
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.
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
)
805 const GLint components
= components_in_intformat(internalFormat
);
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
);
813 /* allocate memory */
814 texImage
->Data
= (GLchan
*) MALLOC(width
* height
* depth
815 * components
* sizeof(GLchan
));
817 return; /* out of memory */
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
825 format
, type
, pixels
, packing
);
832 * This is the software fallback for Driver.TexSubImage1D().
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
)
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
);
852 * This is the software fallback for Driver.TexSubImage2D().
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
)
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
);
874 * This is the software fallback for Driver.TexSubImage3D().
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
)
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
892 format
, type
, pixels
, packing
);
898 * Fallback for Driver.CompressedTexImage1D()
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
)
909 * The device driver has to do it all.
916 * Fallback for Driver.CompressedTexImage2D()
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
)
927 * The device driver has to do it all.
934 * Fallback for Driver.CompressedTexImage3D()
937 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
938 GLint internalFormat
,
939 GLint width
, GLint height
, GLint depth
,
941 GLsizei imageSize
, const GLvoid
*data
,
942 struct gl_texture_object
*texObj
,
943 struct gl_texture_image
*texImage
)
946 * The device driver has to do it all.
956 * This is the fallback for Driver.TestProxyTexImage().
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
)
963 struct gl_texture_unit
*texUnit
;
964 struct gl_texture_object
*texObj
;
965 struct gl_texture_image
*texImage
;
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
);
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.
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
);