OpenBarnyard
 
Loading...
Searching...
No Matches
TRenderInterface.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TRenderInterface.h"
3#include "File/TFile.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
14
16{
21 m_ScreenOffset.Set( 0.0f, 0.0f );
25 m_Unk2 = TNULL;
28 m_iFrameCount = 0;
30
31 m_Transforms.PushNull();
32 m_Transforms.Top().Identity();
33
35
36 m_LightColour.Set(
37 1.0f, 1.0f, 1.0f, 0.0f,
38 0.0f, 0.0f, 0.0f, 0.0f,
39 0.0f, 0.0f, 0.0f, 0.0f,
40 0.0f, 0.0f, 0.0f, 0.0f
41 );
42
44 -0.47f, -0.74f, 0.47f, 0.0f,
45 0.0f, 0.0f, 0.0f, 0.0f,
46 0.0f, 0.0f, 0.0f, 0.0f,
47 0.0f, 0.0f, 0.0f, 0.0f
48 );
49}
50
54
56{
57 TASSERT( TFALSE == IsCreated(), "TRender already created" );
59
61 {
63 m_Unk2 = CreateUnknown( "Render", 0, 0, 10 );
65 return TTRUE;
66 }
67
68 return TFALSE;
69}
70
72{
73 TASSERT( TTRUE == IsCreated(), "TRender is not created" );
74
75 if ( m_Unk2 )
76 {
77 delete m_Unk2;
78 m_Unk2 = TNULL;
79 }
80
82 {
83 delete m_pCreatedContext;
85 }
86
89
90 return TTRUE;
91}
92
93void TRenderInterface::RenderIndexPrimitive( TINT param_2, TINT param_3, TINT param_4, TINT param_5, TINT param_6, TINT param_7 )
94{
95}
96
98{
99 TASSERT( TTRUE == IsCreated(), "TRender must be created" );
100 TASSERT( TFALSE == IsDisplayCreated(), "Display already created" );
101
103 return TTRUE;
104}
105
107{
109 return TTRUE;
110}
111
113{
114 m_iFrameCount += 1;
115 m_Transforms.Reset();
116 m_Transforms.PushNull().Identity();
117 return TTRUE;
118}
119
121{
122 TASSERT( TNULL != resource->Tree(), "Resource doesn't have a tree" );
123 TASSERT( TFALSE == resource->IsDead(), "Resource is already dead" );
124
125 if ( resource->IsDying() == TFALSE )
126 {
128 resource->AddState( TResourceState_Dying );
129 DestroyResourceRecurse( resource->Child() );
130 resource->Invalidate();
131 }
132}
133
135{
136 if ( resource != TNULL )
137 {
138 TResource* lastResource = resource->Prev();
139
140 while ( resource != TNULL )
141 {
142 TResource* nextResource = ( resource != lastResource ) ? resource->Next() : TNULL;
143
144 if ( resource->IsDying() == TFALSE )
145 {
147 resource->AddState( TResourceState_Dying );
148
149 if ( resource->Child() != TNULL )
150 {
151 DestroyResourceRecurse( resource->Child() );
152 }
153
154 resource->Invalidate();
155 }
156
157 resource = nextResource;
158 }
159 }
160}
161
163{
164 TASSERT( systemResource >= 0 && systemResource < SYSRESOURCE_NUMOF, "Unknown resource" );
165 TASSERT( m_SystemResources[ systemResource ] == TNULL, "This resource has already been assigned!" );
166 m_SystemResources[ systemResource ] = resource;
167}
168
170{
171 TASSERT( pClass != TNULL, "TResource class is TNULL" );
172 TASSERT( pClass->IsA( &TGetClass( TResource ) ), "TResource class is TNULL" );
173
174 TResource* pResource = static_cast<TResource*>( pClass->CreateObject() );
175 TASSERT( pResource != TNULL, "Couldn't create TResource" );
176
177 if ( pResource != TNULL )
178 {
179 m_Resources.Remove( *pResource, TFALSE );
180
181 if ( parent == TNULL )
182 {
183 parent = m_Resources.GetRoot();
184 }
185
186 m_Resources.Insert( parent, pResource );
187 pResource->SetUId( m_ResourceCount++ );
188 pResource->SetRenderer( this );
189 pResource->SetName( name );
190
191 return pResource;
192 }
193
194 return pResource;
195}
196
198{
199 TIMPLEMENT();
200
201 TFile* file = TFile::Create( "TRenderInterface.txt", TFILEMODE_CREATENEW );
202
203 if ( file != TNULL )
204 {
205 file->CPrintf( "-\r\n" );
206 TCHAR const* name = GetClass()->GetName();
207 uint16_t versionMajor = GetClass()->GetVersionMajor();
208 uint16_t versionMinor = GetClass()->GetVersionMinor();
209 file->CPrintf( "Toshi rendering interface through object[\"%s\"] Version : %u.%u\r\n", name, versionMajor, versionMinor );
210 file->CPrintf( "-\r\n" );
211
212 for ( auto it = m_AdapterList.Begin(); it != m_AdapterList.End(); it++ )
213 {
214 file->CPrintf( "Adapter : %d\r\n", it->GetAdapterIndex() );
215 file->CPrintf( " Driver : %s\r\n", it->GetDriver().GetString() );
216 file->CPrintf( " Description : %s\r\n", it->GetDriverDescription().GetString() );
217 file->CPrintf( " Product ID : %u\r\n", it->GetProductID() );
218 file->CPrintf( " Version : %u\r\n", it->GetVersion() );
219 file->CPrintf( " Sub-version : %u\r\n", it->GetSubVersion() );
220 file->CPrintf( " Build : %u\r\n", it->GetBuild() );
221 file->CPrintf( " Supports %d modes:\r\n", it->GetModeList()->Count() );
222 }
223
224 file->Destroy();
225 }
226}
227
229{
230 a_rVec.Set( m_ScreenOffset );
231}
232
234{
235 m_ScreenOffset.Set( a_rVec );
236}
237
239{
240 return 4.0f / 3.0f;
241}
242
247
249{
250 return TFALSE;
251}
252
256
258{
259 return TTRUE;
260}
261
266
268{
269 m_LightDirection = a_rMatrix;
270}
271
273{
274 m_LightColour = a_rMatrix;
275}
276
278{
279}
280
284
288
293
299
304
306{
307 // TODO: refactor
308 TResource* pTVar1;
309 TResource* next;
310 TResource* pRes1;
311 TResource* pRes2;
312
313 pRes1 = resources;
314 pRes2 = resources;
315 if ( resources != (TResource*)0x0 )
316 {
317 do {
318 next = pRes2->Next();
319 if ( next == pRes1 )
320 {
321 next = (TResource*)0x0;
322 }
323 if ( ( pRes2->m_State & 4 ) == 0 )
324 {
325 pRes2 = pRes2->Child();
326 if ( pRes2 != (TResource*)0x0 )
327 {
328 DestroyDyingResources( pRes2 );
329 }
330 }
331 else
332 {
333 if ( pRes2 == pRes1 )
334 {
335 pRes1 = next;
336 resources = next;
337 }
338 pTVar1 = pRes2->Child();
339 while ( pTVar1 != (TResource*)0x0 )
340 {
341 pRes1 = pTVar1->Next();
342 if ( pRes1 == pTVar1 )
343 {
344 pRes1 = (TResource*)0x0;
345 }
346 DeleteResourceAtomic( pTVar1 );
347 pTVar1 = pRes1;
348 pRes1 = resources;
349 }
350 DeleteResourceAtomic( pRes2 );
351 }
352 pRes2 = next;
353 } while ( next != (TResource*)0x0 );
354 }
355}
356
358{
359 DeleteResourceRecurse( resources->Child() );
360 DeleteResourceAtomic( resources );
361}
362
364{
365 while ( resource )
366 {
367 auto next = resource->Next();
368 if ( next == resource ) next = TNULL;
369
370 DeleteResourceAtomic( resource );
371 resource = next;
372 }
373}
374
376{
377 if ( a_pResource )
378 {
379 DeleteResourceRecurse( a_pResource->Child() );
380
381 TASSERT( TFALSE == a_pResource->IsValid() );
382
383 if ( a_pResource->IsCreated() )
384 {
385 a_pResource->OnDestroy();
386 }
387
388 m_Resources.Remove( a_pResource, TFALSE );
389
390 if ( a_pResource->IsExternal() )
391 {
392 a_pResource->~TResource();
393 }
394 else
395 {
396 delete a_pResource;
397 }
398 }
399}
400
402{
403 auto pAdapter = GetAdapterList()->Begin();
404
405 while ( TTRUE )
406 {
407 if ( pAdapter == GetAdapterList()->End() )
408 {
409 TString8 errorString = "Unable to find the passed device!\n";
410#ifdef TOSHI_DEBUG
411 OutputDebugStringA( errorString );
412#endif
413 return TNULL;
414 }
415
416 for ( auto pMode = pAdapter->GetModeList()->Begin(); pMode != pAdapter->GetModeList()->End(); pMode++ )
417 {
418 auto uiNumSupportedDevices = pAdapter->GetNumSupportedDevices();
419
420 for ( TUINT32 i = 0; i < uiNumSupportedDevices; i++ )
421 {
422 auto pDevice = pMode->GetDevice( i );
423
424 if ( pDevice->IsSoftware() ) continue;
425
426 TBOOL bPassedColourDepth = TTRUE;
427
428 if ( a_rDisplayParams.uiColourDepth == 32 )
429 {
430 if ( !pDevice->GetMode()->Is32Bit() )
431 {
432 bPassedColourDepth = TFALSE;
433 }
434 }
435 else if ( a_rDisplayParams.uiColourDepth == 16 )
436 {
437 if ( !pDevice->GetMode()->Is16Bit() )
438 {
439 bPassedColourDepth = TFALSE;
440 }
441 }
442
443 TBOOL bPassedWindowed = TTRUE;
444
445 if ( a_rDisplayParams.bWindowed && !pDevice->CanRenderWindowed() )
446 {
447 bPassedWindowed = TFALSE;
448 }
449
450 auto uiWidth = pDevice->GetMode()->GetWidth();
451 auto uiHeight = pDevice->GetMode()->GetHeight();
452
453 if ( uiHeight < uiWidth || !a_rDisplayParams.bWindowed || a_rDisplayParams.uiWidth <= a_rDisplayParams.uiHeight )
454 {
455 if ( uiWidth == a_rDisplayParams.uiWidth && uiHeight == a_rDisplayParams.uiHeight )
456 {
457 if ( pDevice->IsDepthStencilFormatSupported( a_rDisplayParams.eDepthStencilFormat ) &&
458 bPassedColourDepth && bPassedWindowed )
459 {
460 return pDevice;
461 }
462 }
463 }
464 else
465 {
466 if ( a_rDisplayParams.uiWidth <= uiWidth )
467 {
468 if ( uiHeight < a_rDisplayParams.uiHeight ) continue;
469
470 if ( pDevice->IsDepthStencilFormatSupported( a_rDisplayParams.eDepthStencilFormat ) &&
471 bPassedColourDepth && bPassedWindowed )
472 {
473 return pDevice;
474 }
475 }
476 }
477 }
478 }
479
480 pAdapter++;
481 }
482}
483
492
Core file system interface for the Toshi engine.
@ TFILEMODE_CREATENEW
Definition TFile.h:41
TOSHI_NAMESPACE_START typedef TUINT8 SYSRESOURCE
Definition TRender.h:5
@ SYSRESOURCE_NUMOF
Definition TRender.h:21
Rendering system interface for the Toshi engine.
@ TResourceState_Dying
Definition TResource.h:13
#define TIMPLEMENT()
Definition Defines.h:136
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TGetClass(CLASS)
Definition TObject.h:13
#define TDEFINE_CLASS_NORUNTIME(...)
Definition TObject.h:138
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
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
Definition TFile.h:128
void Destroy()
Definition TFile.cpp:184
static TFile * Create(const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
Definition TFile.cpp:29
virtual TINT CPrintf(const TCHAR *a_szFormat,...)=0
Analogue of printf but writes result to the file.
constexpr void Set(TFLOAT x, TFLOAT y)
Definition TVector2.h:13
virtual void SetScreenOffset(const TVector2 &a_rVec)
virtual void DestroySystemResources()
virtual void OnInitializationFailureDevice()
void DeleteResource(TResource *resources)
TDebugText * m_pDebugText
void DestroyDyingResources(TResource *resources)
virtual void RenderIndexPrimitive(TINT param_2, TINT param_3, TINT param_4, TINT param_5, TINT param_6, TINT param_7)
TNodeList< TRenderAdapter > m_AdapterList
TRenderContext * m_pCurrentContext
virtual TRenderContext * CreateRenderContext()=0
virtual TBOOL BeginScene()
TResource * m_SystemResources[SYSRESOURCE_NUMOF]
TRenderContext * SetCurrentRenderContext(TRenderContext *a_pRenderContext)
virtual void FlushOrderTables()
virtual TBOOL Supports32BitTextures()
virtual float GetScreenAspectRatio()
virtual TBOOL SetPixelAspectRatio(float a_fPixelAspectRatio)
TTexture * m_pInvalidTexture
TNodeTree< TResource > m_Resources
void DeleteResourceRecurse(TResource *resources)
TNodeList< TRenderAdapter > * GetAdapterList()
TRenderContext * m_pCreatedContext
TStack< TMatrix44, 20 > m_Transforms
void DestroyResource(TResource *resource)
void SetResourceExplicit(TResource *resource, SYSRESOURCE systemResource)
virtual TBOOL Destroy()
TResource * CreateResource(TClass *pClass, const TCHAR *name, TResource *parent)
virtual void SetLightDirectionMatrix(const TMatrix44 &a_rMatrix)
virtual TBOOL Create()
TRenderAdapter::Mode::Device * FindDevice(const DISPLAYPARAMS &a_rDisplayParams)
virtual float GetPixelAspectRatio()
virtual void SetLightColourMatrix(const TMatrix44 &a_rMatrix)
virtual void OnInitializationFailureDisplay()
virtual void * CreateUnknown(const TCHAR *a_szName, TINT a_iUnk1, TINT a_iUnk2, TINT a_iUnk3)=0
virtual void GetScreenOffset(TVector2 &a_rVec)
virtual void Unknown1(TViewport *a_pViewport)
virtual void DumpStats()
virtual TBOOL CreateSystemResources()
void DeleteResourceAtomic(TResource *resources)
virtual TBOOL IsTextureFormatSupported(TINT a_eTextureFormat)
void DestroyResourceRecurse(TResource *resource)
TBOOL IsDead() const
Definition TResource.h:42
TBOOL IsCreated() const
Definition TResource.h:46
virtual void OnDestroy()
Definition TResource.cpp:67
void SetUId(TUINT32 uid)
virtual void Invalidate()
Definition TResource.cpp:47
TBOOL IsExternal() const
Definition TResource.h:45
void SetRenderer(TRenderInterface *pRenderer)
TBOOL IsValid() const
Definition TResource.h:44
TBOOL IsDying() const
Definition TResource.h:43
void SetName(const TCHAR *name)
Definition TResource.cpp:94
void AddState(TResourceState state)
Definition TResource.h:51
Definition TClass.h:8
class TObject * CreateObject() const
Definition TClass.cpp:116
TBOOL IsA(TClass *pClass)
Definition TClass.cpp:126
Iterator Begin() const
Definition TNodeList.h:230
T * Prev() const
Definition TNodeTree.h:35
T * Child() const
Definition TNodeTree.h:37
T * Next() const
Definition TNodeTree.h:34
TNodeTree< T > * Tree() const
Definition TNodeTree.h:36
virtual Toshi::TClass * GetClass()
Definition TObject.cpp:12
static void MemClear(void *ptr, TSIZE size)
Definition TUtil.h:91