2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file texcompress_fxt1.c
28 * GL_EXT_texture_compression_fxt1 support.
38 #include "texcompress.h"
39 #include "texformat.h"
44 compress_fxt1 (GLcontext
*ctx
,
55 * Called during context initialization.
58 _mesa_init_texture_fxt1( GLcontext
*ctx
)
64 * Called via TexFormat->StoreImage to store an RGB_FXT1 texture.
67 texstore_rgb_fxt1(STORE_PARAMS
)
72 const GLint texWidth
= dstRowStride
* 8 / 16; /* a bit of a hack */
73 const GLchan
*tempImage
= NULL
;
75 ASSERT(dstFormat
== &_mesa_texformat_rgb_fxt1
);
76 ASSERT(dstXoffset
% 8 == 0);
77 ASSERT(dstYoffset
% 4 == 0);
78 ASSERT(dstZoffset
== 0);
81 * we still need to pass 4byte/texel to the codec
83 if (1 || srcFormat
!= GL_RGB
||
84 srcType
!= CHAN_TYPE
||
85 ctx
->_ImageTransferState
||
86 srcPacking
->SwapBytes
) {
87 /* convert image to RGB/GLchan */
88 tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
90 /*dstFormat->BaseFormat*/GL_RGBA
,
91 srcWidth
, srcHeight
, srcDepth
,
92 srcFormat
, srcType
, srcAddr
,
95 return GL_FALSE
; /* out of memory */
96 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
98 srcRowStride
= /*3*/4 * srcWidth
;
102 pixels
= (const GLchan
*) srcAddr
;
103 srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
,
104 srcType
) / sizeof(GLchan
);
107 dst
= _mesa_compressed_image_address(dstXoffset
, dstYoffset
, 0,
108 GL_COMPRESSED_RGB_FXT1_3DFX
,
111 compress_fxt1(ctx
, srcWidth
, srcHeight
, srcFormat
, pixels
, srcRowStride
,
115 _mesa_free((void *) tempImage
);
122 * Called via TexFormat->StoreImage to store an RGBA_FXT1 texture.
125 texstore_rgba_fxt1(STORE_PARAMS
)
127 const GLchan
*pixels
;
130 GLint texWidth
= dstRowStride
* 8 / 16; /* a bit of a hack */
131 const GLchan
*tempImage
= NULL
;
133 ASSERT(dstFormat
== &_mesa_texformat_rgba_fxt1
);
134 ASSERT(dstXoffset
% 8 == 0);
135 ASSERT(dstYoffset
% 4 == 0);
136 ASSERT(dstZoffset
== 0);
138 if (srcFormat
!= GL_RGBA
||
139 srcType
!= CHAN_TYPE
||
140 ctx
->_ImageTransferState
||
141 srcPacking
->SwapBytes
) {
142 /* convert image to RGBA/GLchan */
143 tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
145 dstFormat
->BaseFormat
,
146 srcWidth
, srcHeight
, srcDepth
,
147 srcFormat
, srcType
, srcAddr
,
150 return GL_FALSE
; /* out of memory */
151 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
153 srcRowStride
= 4 * srcWidth
;
157 pixels
= (const GLchan
*) srcAddr
;
158 srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
,
159 srcType
) / sizeof(GLchan
);
162 dst
= _mesa_compressed_image_address(dstXoffset
, dstYoffset
, 0,
163 GL_COMPRESSED_RGBA_FXT1_3DFX
,
166 compress_fxt1(ctx
, srcWidth
, srcHeight
, srcFormat
, pixels
, srcRowStride
,
170 _mesa_free((void*) tempImage
);
177 fetch_texel_2d_rgba_fxt1( const struct gl_texture_image
*texImage
,
178 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
185 fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image
*texImage
,
186 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
188 /* just sample as GLchan and convert to float here */
190 fetch_texel_2d_rgba_fxt1(texImage
, i
, j
, k
, rgba
);
191 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
192 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
193 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
194 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
199 fetch_texel_2d_rgb_fxt1( const struct gl_texture_image
*texImage
,
200 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
207 fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image
*texImage
,
208 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
210 /* just sample as GLchan and convert to float here */
212 fetch_texel_2d_rgb_fxt1(texImage
, i
, j
, k
, rgba
);
213 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
214 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
215 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
216 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
221 const struct gl_texture_format _mesa_texformat_rgb_fxt1
= {
222 MESA_FORMAT_RGB_FXT1
, /* MesaFormat */
223 GL_RGB
, /* BaseFormat */
224 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
225 4, /*approx*/ /* RedBits */
226 4, /*approx*/ /* GreenBits */
227 4, /*approx*/ /* BlueBits */
229 0, /* LuminanceBits */
230 0, /* IntensityBits */
234 texstore_rgb_fxt1
, /* StoreTexImageFunc */
235 NULL
, /*impossible*/ /* FetchTexel1D */
236 fetch_texel_2d_rgb_fxt1
, /* FetchTexel2D */
237 NULL
, /*impossible*/ /* FetchTexel3D */
238 NULL
, /*impossible*/ /* FetchTexel1Df */
239 fetch_texel_2d_f_rgb_fxt1
, /* FetchTexel2Df */
240 NULL
, /*impossible*/ /* FetchTexel3Df */
243 const struct gl_texture_format _mesa_texformat_rgba_fxt1
= {
244 MESA_FORMAT_RGBA_FXT1
, /* MesaFormat */
245 GL_RGBA
, /* BaseFormat */
246 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
247 4, /*approx*/ /* RedBits */
248 4, /*approx*/ /* GreenBits */
249 4, /*approx*/ /* BlueBits */
250 1, /*approx*/ /* AlphaBits */
251 0, /* LuminanceBits */
252 0, /* IntensityBits */
256 texstore_rgba_fxt1
, /* StoreTexImageFunc */
257 NULL
, /*impossible*/ /* FetchTexel1D */
258 fetch_texel_2d_rgba_fxt1
, /* FetchTexel2D */
259 NULL
, /*impossible*/ /* FetchTexel3D */
260 NULL
, /*impossible*/ /* FetchTexel1Df */
261 fetch_texel_2d_f_rgba_fxt1
, /* FetchTexel2Df */
262 NULL
, /*impossible*/ /* FetchTexel3Df */
267 compress_fxt1 (GLcontext
*ctx
,
271 const GLchan
*source
,
276 /* here be dragons */