98e75f2d |
1 | /* |
2 | * Texture compression |
3 | * Version: 1.0 |
4 | * |
5 | * Copyright (C) 2004 Daniel Borca All Rights Reserved. |
6 | * |
7 | * this is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2, or (at your option) |
10 | * any later version. |
11 | * |
12 | * this is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with GNU Make; see the file COPYING. If not, write to |
19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ |
21 | |
22 | |
23 | #include <assert.h> |
24 | |
25 | #include "types.h" |
26 | #include "internal.h" |
27 | #include "dxtn.h" |
28 | |
29 | |
30 | #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 |
31 | #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 |
32 | #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 |
33 | #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 |
34 | |
35 | |
36 | TAPI void TAPIENTRY |
37 | fetch_2d_texel_rgb_dxt1 (int texImage_RowStride, |
38 | const byte *texImage_Data, |
39 | int i, int j, |
40 | byte *texel) |
41 | { |
42 | dxt1_rgb_decode_1(texImage_Data, texImage_RowStride, i, j, texel); |
43 | } |
44 | |
45 | |
46 | TAPI void TAPIENTRY |
47 | fetch_2d_texel_rgba_dxt1 (int texImage_RowStride, |
48 | const byte *texImage_Data, |
49 | int i, int j, |
50 | byte *texel) |
51 | { |
52 | dxt1_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); |
53 | } |
54 | |
55 | |
56 | TAPI void TAPIENTRY |
57 | fetch_2d_texel_rgba_dxt3 (int texImage_RowStride, |
58 | const byte *texImage_Data, |
59 | int i, int j, |
60 | byte *texel) |
61 | { |
62 | dxt3_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); |
63 | } |
64 | |
65 | |
66 | TAPI void TAPIENTRY |
67 | fetch_2d_texel_rgba_dxt5 (int texImage_RowStride, |
68 | const byte *texImage_Data, |
69 | int i, int j, |
70 | byte *texel) |
71 | { |
72 | dxt5_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); |
73 | } |
74 | |
75 | |
76 | TAPI void TAPIENTRY |
77 | tx_compress_dxtn (int srccomps, int width, int height, |
78 | const byte *source, int destformat, byte *dest, |
79 | int destRowStride) |
80 | { |
81 | int srcRowStride = width * srccomps; |
82 | |
83 | switch (destformat) { |
84 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
85 | dxt1_rgb_encode(width, height, srccomps, |
86 | source, srcRowStride, |
87 | dest, destRowStride); |
88 | break; |
89 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
90 | dxt1_rgba_encode(width, height, srccomps, |
91 | source, srcRowStride, |
92 | dest, destRowStride); |
93 | break; |
94 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
95 | dxt3_rgba_encode(width, height, srccomps, |
96 | source, srcRowStride, |
97 | dest, destRowStride); |
98 | break; |
99 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
100 | dxt5_rgba_encode(width, height, srccomps, |
101 | source, srcRowStride, |
102 | dest, destRowStride); |
103 | break; |
104 | default: |
105 | assert(0); |
106 | } |
107 | } |