OpenBarnyard
 
Loading...
Searching...
No Matches
T2GLTexture_GL.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "T2GLTexture_GL.h"
3#include "T2Render_GL.h"
4
6
8{
9 if ( m_pHandle != 0 )
10 Destroy();
11}
12
14{
16 T2Render::DestroyTexture( m_pHandle );
17}
18
19void T2GLTexture::Create( TEXTURE_FORMAT a_eFormat, UINT a_uiWidth, UINT a_uiHeight, const void* a_pData )
20{
21 if ( m_pHandle != 0 )
22 Destroy();
23
24 m_pchTexName = "runtime";
25
26 GLenum glFormat =
27 ( a_eFormat == TEXTURE_FORMAT_R8G8B8A8_UNORM ) ? GL_RGBA :
28 ( a_eFormat == TEXTURE_FORMAT_R8G8_UNORM ) ? GL_RG :
29 GL_R;
30
31 m_pHandle = T2Render::CreateTexture( a_uiWidth, a_uiHeight, glFormat, glFormat, GL_UNSIGNED_BYTE, TFALSE, a_pData );
32 m_uiWidth = a_uiWidth;
33 m_uiHeight = a_uiHeight;
34 m_uiMipMapCount = 1;
35 m_eFormat = a_eFormat;
36
38}
39
41{
42 m_eAddressU = eAddressU;
43 m_eAddressV = eAddressV;
44}
45
47 : m_pLastTexture( TNULL )
48{
49 {
50 // White texture
51 constexpr int WhiteTextureWidth = 8;
52 constexpr int WhiteTextureHeight = 8;
53 constexpr int WhiteTextureSize = WhiteTextureWidth * WhiteTextureHeight * 4;
54
55 TUINT8* srcData = (TUINT8*)TMemalign( WhiteTextureSize, 16 );
56 TUtil::MemSet( srcData, 0xFF, WhiteTextureSize );
57
58 m_pWhiteTexture = new T2GLTexture;
59 m_pWhiteTexture->Create( TEXTURE_FORMAT_R8G8B8A8_UNORM, WhiteTextureWidth, WhiteTextureHeight, srcData );
60 m_pWhiteTexture->SetName( "white" );
61 m_pWhiteTexture->m_pNextTexture = TNULL;
62 m_pWhiteTexture->m_pPrevTexture = TNULL;
63 TFree( srcData );
64 }
65
66 {
67 // Invalid texture
68 constexpr int InvalidTextureWidth = 128;
69 constexpr int InvalidTextureHeight = 128;
70 constexpr int InvalidTextureSize = InvalidTextureWidth * InvalidTextureHeight * 4;
71
72 TUINT8* srcData = (TUINT8*)TMemalign( InvalidTextureSize, 16 );
73
74 for ( TUINT8* pos = srcData; pos < srcData + InvalidTextureSize; pos += 4 )
75 {
76 *( pos ) = rand() % 256;
77 *( pos + 1 ) = rand() % 256;
78 *( pos + 2 ) = rand() % 256;
79 *( pos + 3 ) = rand() % 256;
80 }
81
82 m_pInvalidTexture = new T2GLTexture;
83 m_pInvalidTexture->Create( TEXTURE_FORMAT_R8G8B8A8_UNORM, 8, 8, srcData );
84 m_pInvalidTexture->SetName( "invalid" );
85 m_pInvalidTexture->m_pNextTexture = TNULL;
86 m_pInvalidTexture->m_pPrevTexture = TNULL;
87 TFree( srcData );
88 }
89}
90
92{
93 T2GLTexture* pCurrentTex = m_pLastTexture;
94
95 while ( TTRUE )
96 {
97 if ( pCurrentTex == TNULL )
98 return m_pInvalidTexture;
99
100 if ( !T2String8::CompareNoCase( pCurrentTex->GetName(), a_pchTexName ) )
101 break;
102
103 pCurrentTex = pCurrentTex->m_pPrevTexture;
104 }
105
106 return pCurrentTex;
107}
108
110{
111 a_pTexture->m_pPrevTexture = GetLastTexture();
112 a_pTexture->m_pNextTexture = TNULL;
113
114 if ( a_pTexture->m_pPrevTexture != TNULL )
115 a_pTexture->m_pPrevTexture->m_pNextTexture = a_pTexture;
116
117 m_pLastTexture = a_pTexture;
118}
119
121{
122 if ( a_pTexture->m_pPrevTexture )
123 a_pTexture->m_pPrevTexture->m_pNextTexture = a_pTexture->m_pNextTexture;
124
125 if ( a_pTexture->m_pNextTexture )
126 a_pTexture->m_pNextTexture->m_pPrevTexture = a_pTexture->m_pPrevTexture;
127
128 if ( m_pLastTexture == a_pTexture )
129 m_pLastTexture = a_pTexture->m_pPrevTexture;
130
131 a_pTexture->m_pNextTexture = TNULL;
132 a_pTexture->m_pPrevTexture = TNULL;
133}
134
void * TMemalign(TSIZE a_uiAlignment, TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock)
Allocates aligned memory from a specific memory block.
Definition TMemory.cpp:1020
void TFree(void *a_pMem)
Frees previously allocated memory.
Definition TMemory.cpp:1054
TEXTURE_FORMAT
@ TEXTURE_FORMAT_R8G8B8A8_UNORM
@ TEXTURE_FORMAT_R8G8_UNORM
TEXTURE_ADDRESS_MODE
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
char TCHAR
Definition Typedefs.h:20
uint8_t TUINT8
Definition Typedefs.h:17
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
void SetWrap(TEXTURE_ADDRESS_MODE a_eAddressU, TEXTURE_ADDRESS_MODE a_eAddressV)
void Create(TEXTURE_FORMAT a_eFormat, UINT a_uiWidth, UINT a_uiHeight, const void *a_pData)
const TCHAR * GetName() const
friend class T2GLTexture
T2GLTexture * FindTexture(const TCHAR *a_pchTexName)
T2GLTexture * GetLastTexture() const
void AddTexture(T2GLTexture *a_pTexture)
void RemoveTexture(T2GLTexture *a_pTexture)
static TINT CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:60
static TFORCEINLINE T2TextureManager * GetSingleton()
Definition TSingleton.h:49
static void MemSet(void *ptr, TINT value, TSIZE size)
Definition TUtil.h:89