OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2TextureSectionManager.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUI2.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
13TBOOL AGUI2TextureSectionManager::Open( const TCHAR* a_szFileName, Toshi::TTRB* a_pTRB )
14{
15 if ( a_pTRB == TNULL )
16 {
18 g_trb = new TTRB();
19
20 if ( g_trb->Load( a_szFileName ) != TTRB::ERROR_OK )
21 return TFALSE;
22
23 g_defblock = TSTATICCAST( TRBHeader, g_trb->GetSymbolAddress( "texturesections" ) );
24 }
25 else
26 {
27 g_trb = a_pTRB;
29
30 auto iFilePathLength = TStringManager::String8Length( a_szFileName );
31 auto iFileNamePos = iFilePathLength - 1;
32
33 while ( a_szFileName[ iFileNamePos ] != '\\' && a_szFileName[ iFileNamePos ] != '/' )
34 iFileNamePos--;
35
36 iFileNamePos++;
37 TCHAR symbolName[ 132 ] = { '\0' };
38
39 auto iFileNameLength = iFilePathLength - iFileNamePos - 4;
40 TStringManager::String8Copy( symbolName, a_szFileName + iFileNamePos, iFileNameLength );
41 symbolName[ iFileNameLength ] = '_';
42 symbolName[ iFileNameLength + 1 ] = '\0';
44 TStringManager::String8Copy( symbolName + iFileNameLength + 1, "texturesections" );
45
46 g_defblock = TSTATICCAST( TRBHeader, g_trb->GetSymbolAddress( symbolName ) );
47 }
48
49 g_sections = g_defblock->m_pSections;
51
52 return TTRUE;
53}
54
56{
57 if ( g_trb )
58 {
62
63 if ( !g_providedtrb )
64 delete g_trb;
65
67 g_trb = TNULL;
68 }
69}
70
72{
74
75 for ( TUINT32 i = 0; i < g_defblock->m_uiNumSections; i++ )
76 {
77 auto pSection = &g_sections[ i ];
78
79 if ( TStringManager::String8Compare( pSection->GetName(), a_szSectionName ) == 0 )
80 return pSection;
81 }
82
83 return TNULL;
84}
85
87{
89
90 auto pRenderer = AGUI2::GetRenderer();
91
92 for ( TUINT i = 0; i < g_defblock->m_uiNumSections; i++ )
93 {
94 auto pSection = &g_defblock->m_pSections[ i ];
95
96 if ( pSection->GetMaterial() == TNULL )
97 {
98 auto pTexture = pRenderer->GetTexture( pSection->GetTextureFile() );
99
100 if ( pTexture )
101 {
102 auto pMaterial = pRenderer->CreateMaterial( pTexture );
103 pSection->SetMaterial( pMaterial );
104
105 auto iWidth = pRenderer->GetWidth( pMaterial );
106 auto iHeight = pRenderer->GetHeight( pMaterial );
107
108 auto& uv1 = pSection->GetUVPoint1();
109 uv1.x = TFLOAT( pSection->GetPoint1X() ) / TFLOAT( iWidth );
110 uv1.y = TFLOAT( pSection->GetPoint1Y() ) / TFLOAT( iHeight );
111 uv1.z = TFLOAT( pSection->GetPoint2X() ) / TFLOAT( iWidth );
112 uv1.w = TFLOAT( pSection->GetPoint1Y() ) / TFLOAT( iHeight );
113
114 auto& uv2 = pSection->GetUVPoint2();
115 uv2.x = TFLOAT( pSection->GetPoint2X() ) / TFLOAT( iWidth );
116 uv2.y = TFLOAT( pSection->GetPoint2Y() ) / TFLOAT( iHeight );
117 uv2.z = TFLOAT( pSection->GetPoint1X() ) / TFLOAT( iWidth );
118 uv2.w = TFLOAT( pSection->GetPoint2Y() ) / TFLOAT( iHeight );
119 }
120 }
121 }
122}
123
125{
127
128 auto pRenderer = AGUI2::GetRenderer();
129
130 for ( TUINT i = 0; i < g_defblock->m_uiNumSections; i++ )
131 {
132 auto pSection = &g_defblock->m_pSections[ i ];
133 auto pMaterial = pSection->GetMaterial();
134
135 if ( pMaterial != TNULL )
136 {
137 pRenderer->DestroyMaterial( pMaterial );
138 pSection->SetMaterial( TNULL );
139 }
140 }
141}
142
144{
145 if ( g_sections != TNULL )
146 {
147 auto pRenderer = AGUI2::GetRenderer();
148
149 for ( TUINT i = 0; i < g_defblock->m_uiNumSections; i++ )
150 {
151 auto pSection = &g_defblock->m_pSections[ i ];
152 auto pTexture = pRenderer->GetTexture( pSection->GetTextureFile() );
153
154 if ( pSection->GetMaterial() == TNULL )
155 {
156 if ( pTexture )
157 {
158 auto pMaterial = pRenderer->CreateMaterial( pTexture );
159 pSection->SetMaterial( pMaterial );
160
161 auto iWidth = pRenderer->GetWidth( pMaterial );
162 auto iHeight = pRenderer->GetHeight( pMaterial );
163
164 auto& uv1 = pSection->GetUVPoint1();
165 uv1.x = TFLOAT( pSection->GetPoint1X() ) * TFLOAT( iWidth );
166 uv1.y = TFLOAT( pSection->GetPoint1Y() ) * ( 1.0f / TFLOAT( iHeight ) );
167 uv1.z = TFLOAT( pSection->GetPoint2X() ) * TFLOAT( iWidth );
168 uv1.w = TFLOAT( pSection->GetPoint1Y() ) * ( 1.0f / TFLOAT( iHeight ) );
169
170 auto& uv2 = pSection->GetUVPoint2();
171 uv2.x = TFLOAT( pSection->GetPoint2X() ) * TFLOAT( iWidth );
172 uv2.y = TFLOAT( pSection->GetPoint2Y() ) * ( 1.0f / TFLOAT( iHeight ) );
173 uv2.z = TFLOAT( pSection->GetPoint1X() ) * TFLOAT( iWidth );
174 uv2.w = TFLOAT( pSection->GetPoint2Y() ) * ( 1.0f / TFLOAT( iHeight ) );
175 }
176 }
177 else if ( pTexture == TNULL )
178 {
179 pRenderer->DestroyMaterial( pSection->GetMaterial() );
180 pSection->SetMaterial( TNULL );
181 }
182 }
183 }
184}
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
Definition TTRB.h:253
@ ERROR_OK
Definition TTRB.h:258
static void String8ToLowerCase(TCHAR *str)
static TINT String8Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
static TSIZE String8Length(const TCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)
static AGUI2Renderer * GetRenderer()
Definition AGUI2.cpp:239
static AGUI2TextureSection * g_sections
static TBOOL Open(const TCHAR *a_szFileName, Toshi::TTRB *a_pTRB)
static AGUI2TextureSection * GetTextureSection(const TCHAR *a_szSectionName)