1 /* $Id: texcompress.c,v 1.2 2002/10/18 17:41:45 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
32 #include "texcompress.h"
33 #include "texformat.h"
37 * Get the list of supported internal compression formats.
38 * \param formats - the results list (may be NULL)
39 * \return number of formats.
42 _mesa_get_compressed_formats( GLcontext
*ctx
, GLint
*formats
)
45 if (ctx
->Extensions
.ARB_texture_compression
) {
46 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
48 formats
[n
++] = GL_COMPRESSED_RGB_FXT1_3DFX
;
49 formats
[n
++] = GL_COMPRESSED_RGBA_FXT1_3DFX
;
62 * Return bytes of storage needed for the given texture size and compressed
64 * \param width, height, depth - texture size in texels
65 * \param texFormat - one of the compressed format enums
66 * \return size in bytes, or zero if bad texFormat
69 _mesa_compressed_texture_size( GLcontext
*ctx
,
70 GLsizei width
, GLsizei height
, GLsizei depth
,
76 case GL_COMPRESSED_RGB_FXT1_3DFX
:
77 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
78 /* round up to multiple of 4 */
79 size
= ((width
+ 7) / 8) * ((height
+ 3) / 4) * 16;
82 _mesa_problem(ctx
, "bad texformat in compressed_texture_size");
89 * Compute the bytes per row in a compressed texture image.
92 _mesa_compressed_row_stride(GLenum format
, GLsizei width
)
94 GLint bytesPerTile
, stride
;
101 stride
= ((width
+ 3) / 4) * bytesPerTile
;
107 * Return the address of the pixel at (col, row, img) in a
108 * compressed texture image.
109 * \param col, row, img - image position (3D)
110 * \param format - compressed image format
111 * \param width - image width
112 * \param image - the image address
113 * \return address of pixel at (row, col)
116 _mesa_compressed_image_address(GLint col
, GLint row
, GLint img
,
118 GLsizei width
, const GLubyte
*image
)
120 GLint bytesPerTile
, stride
;
123 ASSERT((row
& 3) == 0);
124 ASSERT((col
& 3) == 0);
132 stride
= ((width
+ 3) / 4) * bytesPerTile
;
134 addr
= (GLubyte
*) image
+ (row
/ 4) * stride
+ (col
/ 4) * bytesPerTile
;
141 * \param srcRowStride - source stride, in pixels
144 _mesa_compress_teximage( GLcontext
*ctx
, GLsizei width
, GLsizei height
,
145 GLenum srcFormat
, const GLchan
*source
,
147 const struct gl_texture_format
*dstFormat
,
148 GLubyte
*dest
, GLint dstRowStride
)
150 switch (dstFormat
->MesaFormat
) {
152 _mesa_problem(ctx
, "Bad dstFormat in _mesa_compress_teximage()");