OpenBarnyard
 
Loading...
Searching...
No Matches
TTexture_Rev.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TTexture_Rev.h"
3
5
6TINT TTexture::GetBitsPerTexel( GXTexFmt a_texFmt )
7{
8 switch ( a_texFmt )
9 {
10 case I4:
11 case C4:
12 case CMPR:
13 return 4;
14 case I8:
15 case IA4:
16 case C8:
17 case 0x11:
18 return 8;
19 /*case IA8:
20 case RGB565:
21 case RGB5A3:*/
22 case C14X2:
23 case 0x13:
24 return 16;
25 case RGBA8:
26 case 0x16:
27 return 32;
28 default:
29 return 0;
30 }
31}
32
33TINT TTexture::ComputeHash( const TCHAR* str )
34{
35 TINT hash = 0;
36 while ( true )
37 {
38 TBYTE val = *str++;
39 if ( val == '\0' ) break;
40 hash = hash * 0x11 + val;
41 }
42 return hash;
43}
44
45void TTexture::CheckValid()
46{
47 if ( m_texFmt - 8 < 3 )
48 {
49 m_unk2 |= 0x20000000;
50 }
51
52 if ( m_mipMaps != 0 )
53 {
54 m_unk2 |= 0x10000000;
55 m_unk3 = 2;
56 m_magFilter = GX_LIN_MIP_LIN;
57 m_unk4 = 0.5f * -( m_mipMaps - 176.0f );
58 }
59
60 if ( m_texFmt - 8 < 2 )
61 {
62 m_unk2 |= 0x20000000;
63 }
64
65 m_unk2 |= 0x80000000;
66}
67
68void TTexture::InitTexObj()
69{
70 CheckValid();
71
72 if ( m_mipMaps & 0x20000000 )
73 {
74 m_pImageData = new byte[ m_iImageSize ];
75 if ( m_width != ( m_width & -m_width ) || m_height != ( m_height & -m_height ) )
76 {
77 m_wrapS = 0;
78 m_wrapT = 0;
79 m_mipMaps = 0;
80 }
81 }
82}
83
84void TTexture::InitRuntime( GXTexFmt a_texFmt, GXTlutFmt a_tlutFmt, TUINT a_unk, TUINT a_unk2, TUINT a_unk3, TUINT a_unk4, void* a_unk5, void* a_unk6, TCHAR const* a_szFileName )
85{
86 m_pImageData = TNULL;
87 m_texFmt = a_texFmt;
88 m_tlutFmt = a_tlutFmt;
89 m_wrapS = GX_REPEAT;
90 m_wrapT = GX_REPEAT;
91 m_szFileName = (TCHAR*)a_szFileName;
92
93 m_iHash = ComputeHash( m_szFileName );
94
95 if ( m_texFmt - 8 < 3 )
96 {
97 a_unk3 |= 0x20000000;
98 }
99 else
100 {
101 a_unk3 |= 0x10000000;
102 }
103}
104
105void TTexture::Swizzle()
106{
107 uint8_t bitsPerTexel = GetBitsPerTexel( m_texFmt );
108 switch ( bitsPerTexel )
109 {
110 case 0x4:
111 Swizzle4Bit();
112 return;
113 case 0x8:
114 Swizzle8Bit();
115 return;
116 case 0x10:
117 Swizzle16Bit();
118 return;
119 case 0x20:
120 Swizzle32Bit();
121 return;
122 default:
123 return;
124 }
125}
126
127void TTexture::Swizzle32Bit()
128{
129 uint8_t* buf;
130 TUINT32* imgPtr3;
131 TUINT32 height = m_height;
132 TUINT32 width = m_width;
133 for ( TSIZE i = 0; i < m_mipMaps + 1; i++ )
134 {
135 TINT iVar7 = 0;
136 TUINT32* imagePtr = reinterpret_cast<TUINT32*>( m_pImageData );
137 for ( TSIZE j = 0; j < height; j += 4 )
138 {
139 TUtil::MemCopy( buf, imagePtr + ( iVar7 * 2 ), width * 16 );
140 TINT iVar1 = 0;
141 for ( TSIZE k = 0; k < width; k += 4 )
142 {
143 uint8_t* buf2 = buf + iVar1;
144 for ( TSIZE s = 0; s < 2; s++ )
145 {
146 imgPtr3 = imagePtr;
147 imgPtr3[ 0 ] = buf2[ 0 ] >> 0x10;
148 imgPtr3[ 1 ] = buf2[ 1 ] >> 0x10;
149 imgPtr3[ 2 ] = buf2[ 2 ] >> 0x10;
150 imgPtr3[ 3 ] = buf2[ 3 ] >> 0x10;
151
152 imgPtr3[ 16 ] = buf2[ 0 ];
153 imgPtr3[ 17 ] = buf2[ 1 ];
154 imgPtr3[ 18 ] = buf2[ 2 ];
155 imgPtr3[ 19 ] = buf2[ 3 ];
156
157 uint8_t* buf3 = buf2 + width;
158 imgPtr3[ 4 ] = buf3[ 0 ] >> 0x10;
159 imgPtr3[ 5 ] = buf3[ 1 ] >> 0x10;
160 imgPtr3[ 6 ] = buf3[ 2 ] >> 0x10;
161 imgPtr3[ 7 ] = buf3[ 3 ] >> 0x10;
162
163 imgPtr3[ 20 ] = buf3[ 0 ];
164 imgPtr3[ 21 ] = buf3[ 1 ];
165 imgPtr3[ 22 ] = buf3[ 2 ];
166 imgPtr3[ 23 ] = buf3[ 3 ];
167
168 buf2 = buf3 + width;
169 imagePtr += 8;
170 }
171 imagePtr = imgPtr3 + 24;
172 iVar1 += 16;
173 }
174 iVar7 += width * 4;
175 }
176 height /= 2;
177 width /= 2;
178 imagePtr += 32;
179 }
180}
181
182void TTexture::GetPhysicalSize( TUINT32& width, TUINT32& height, TUINT32 bitsPerTexel )
183{
184 if ( bitsPerTexel < 16 )
185 {
186 }
187}
188
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
unsigned int TUINT
Definition Typedefs.h:8
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
int TINT
Definition Typedefs.h:7
uint8_t TBYTE
Definition Typedefs.h:19
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90