OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2TextureSectionManager Class Reference

#include <AGUI2TextureSectionManager.h>

Classes

struct  TRBHeader
 

Static Public Member Functions

static TBOOL Open (const TCHAR *a_szFileName, Toshi::TTRB *a_pTRB)
 
static void Close ()
 
static AGUI2TextureSectionGetTextureSection (const TCHAR *a_szSectionName)
 
static void CreateMaterials ()
 
static void DestroyMaterials ()
 
static void UpdateMaterials ()
 

Static Public Attributes

static TBOOL g_providedtrb = false
 
static Toshi::TTRB * g_trb = nullptr
 
static TRBHeaderg_defblock = nullptr
 
static AGUI2TextureSectiong_sections = nullptr
 

Detailed Description

Definition at line 4 of file AGUI2TextureSectionManager.h.

Member Function Documentation

◆ Close()

void AGUI2TextureSectionManager::Close ( )
static

Definition at line 55 of file AGUI2TextureSectionManager.cpp.

56{
57 if ( g_trb )
58 {
62
63 if ( !g_providedtrb )
64 delete g_trb;
65
67 g_trb = TNULL;
68 }
69}
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
static AGUI2TextureSection * g_sections

◆ CreateMaterials()

void AGUI2TextureSectionManager::CreateMaterials ( )
static

Definition at line 86 of file AGUI2TextureSectionManager.cpp.

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}
#define TASSERT(X,...)
Definition Defines.h:138
unsigned int TUINT
Definition Typedefs.h:8
float TFLOAT
Definition Typedefs.h:4
static AGUI2Renderer * GetRenderer()
Definition AGUI2.cpp:239

◆ DestroyMaterials()

void AGUI2TextureSectionManager::DestroyMaterials ( )
static

Definition at line 124 of file AGUI2TextureSectionManager.cpp.

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}

◆ GetTextureSection()

AGUI2TextureSection * AGUI2TextureSectionManager::GetTextureSection ( const TCHAR * a_szSectionName)
static

Definition at line 71 of file AGUI2TextureSectionManager.cpp.

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}
uint32_t TUINT32
Definition Typedefs.h:13
static TINT String8Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)

◆ Open()

TBOOL AGUI2TextureSectionManager::Open ( const TCHAR * a_szFileName,
Toshi::TTRB * a_pTRB )
static

Definition at line 13 of file AGUI2TextureSectionManager.cpp.

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}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
char TCHAR
Definition Typedefs.h:20
#define TTRUE
Definition Typedefs.h:25
@ ERROR_OK
Definition TTRB.h:258
static void String8ToLowerCase(TCHAR *str)
static TSIZE String8Length(const TCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)

◆ UpdateMaterials()

void AGUI2TextureSectionManager::UpdateMaterials ( )
static

Definition at line 143 of file AGUI2TextureSectionManager.cpp.

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}

Member Data Documentation

◆ g_defblock

TRBHeader* AGUI2TextureSectionManager::g_defblock = nullptr
inlinestatic

Definition at line 15 of file AGUI2TextureSectionManager.h.

◆ g_providedtrb

TBOOL AGUI2TextureSectionManager::g_providedtrb = false
inlinestatic

Definition at line 13 of file AGUI2TextureSectionManager.h.

◆ g_sections

AGUI2TextureSection* AGUI2TextureSectionManager::g_sections = nullptr
inlinestatic

Definition at line 16 of file AGUI2TextureSectionManager.h.

◆ g_trb

Toshi::TTRB* AGUI2TextureSectionManager::g_trb = nullptr
inlinestatic

Definition at line 14 of file AGUI2TextureSectionManager.h.


The documentation for this class was generated from the following files: