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

#include <ARenderer.h>

Inheritance diagram for ARenderer:

Public Types

using ThisClass = ARenderer
 
using BaseClass = Toshi::TTask
 

Public Member Functions

virtual Toshi::TClass * GetClass () override
 
 ARenderer ()
 
virtual TBOOL OnCreate () override
 
virtual TBOOL OnUpdate (TFLOAT a_fDeltaTime) override
 
TBOOL CreateTRender ()
 
TBOOL CreateTRenderResources ()
 
void UpdateMainCamera (const Toshi::TMatrix44 &a_rTransformMatrix, const ACamera *a_pCamera)
 
void ForceUpdate30FPS ()
 
Toshi::TRenderAdapter::Mode::Device * FindSuitableDevice (Toshi::TRenderInterface::DISPLAYPARAMS &a_rDisplayParams, bool a_bReverseOrder)
 
Toshi::TViewport * GetMainViewport () const
 
Toshi::TEmitter< ARenderer, TBOOL * > & GetAnimationUpdateStartEmitter ()
 
Toshi::TEmitter< ARenderer, TBOOL * > & GetAnimationUpdateEndEmitter ()
 
Toshi::TEmitter< ARenderer, TINT > & GetRenderGUIEmitter ()
 
const Toshi::TEmitter< ARenderer, TINT > & GetRenderGUIEmitter () const
 

Static Public Member Functions

static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE Toshi::TClass * GetClassStatic ()
 

Static Public Attributes

static constexpr Toshi::TClass * PARENTCLASS = & Toshi::TTask::ms_oClass
 
static Toshi::TClass ms_oClass = Toshi::TClass( "ARenderer", ARenderer::PARENTCLASS, ARenderer::CreateTObject, ARenderer::CreateTObjectInPlace, ARenderer::InitialiseClass, ARenderer::DeinitialiseClass, 0, 1, sizeof( ARenderer ), alignof( ARenderer ) )
 

Detailed Description

Definition at line 14 of file ARenderer.h.

Member Typedef Documentation

◆ BaseClass

using ARenderer::BaseClass = Toshi::TTask

Definition at line 18 of file ARenderer.h.

◆ ThisClass

Definition at line 18 of file ARenderer.h.

Constructor & Destructor Documentation

◆ ARenderer()

ARenderer::ARenderer ( )

Definition at line 42 of file ARenderer_Win.cpp.

43 : m_RenderGUIEmitter( this ), m_AnimationUpdateStartEmitter( this ), m_AnimationUpdateEndEmitter( this ), m_pViewport( TNULL ), m_pCameraObject( TNULL ), m_pHALViewport1( TNULL ), m_pHALViewport2( TNULL ), m_bRenderGUI( TTRUE ), m_fNear( 1.0f ), m_fFar( 280.0f )
44{
45}
#define TNULL
Definition Typedefs.h:23
#define TTRUE
Definition Typedefs.h:25

Member Function Documentation

◆ CreateTObject()

Toshi::TObject * ARenderer::CreateTObject ( )
static

Definition at line 40 of file ARenderer_Win.cpp.

◆ CreateTObjectInPlace()

Toshi::TObject * ARenderer::CreateTObjectInPlace ( void * a_pPtr)
static

Definition at line 40 of file ARenderer_Win.cpp.

◆ CreateTRender()

TBOOL ARenderer::CreateTRender ( )

Definition at line 47 of file ARenderer_Win.cpp.

48{
49#if defined( TOSHI_SKU_WINDOWS ) && defined( TRENDERINTERFACE_DX8 )
50 TString8 strRenderInterfaceName = "TRenderD3DInterface";
51#endif
52
53 TKernelInterface::GetSingleton()->LoadInterface( strRenderInterfaceName );
54
55 TClass* pRendererClass = TClass::Find( strRenderInterfaceName );
56 TRenderD3DInterface* pRenderer = TSTATICCAST( TRenderD3DInterface, pRendererClass->CreateObject() );
57
59 pRenderer->Create( "Barnyard" );
60
61 HMODULE hModuleHandle = GetModuleHandleA( TNULL );
62 HICON hIcon = LoadIconA( hModuleHandle, MAKEINTRESOURCE( IDI_ICON1 ) );
63 SendMessageA( pRenderer->GetMSWindow()->GetHWND(), 0x80, TRUE, (LPARAM)hIcon );
64
65 m_DisplayModes.Initialise();
66
68
69 TINT iWidth = 800;
70 TINT iHeight = 600;
71 TINT iColourDepth = 32;
72 TBOOL bWindowed = TTRUE;
73
74 if ( AOptions::GetSingleton() )
75 {
76 iWidth = AOptions::GetSingleton()->GetWidth();
77 iHeight = AOptions::GetSingleton()->GetHeight();
78 bWindowed = AOptions::GetSingleton()->IsWindowed();
79 pRenderer->SetGamma( AOptions::GetSingleton()->GetGamma() );
80 }
81
82 if ( !m_DisplayModes.IsModeExists( iWidth, iHeight, iColourDepth ) )
83 {
84 // Incompatible display mode
85 iWidth = 800;
86 iHeight = 600;
87 iColourDepth = 32;
88 }
89
90 TRenderInterface::DISPLAYPARAMS displayParams;
91 displayParams.uiWidth = iWidth;
92 displayParams.uiHeight = iHeight;
93 displayParams.bWindowed = bWindowed;
94 displayParams.uiColourDepth = 32;
95 displayParams.eDepthStencilFormat = 0;
96
97 auto pDevice = FindSuitableDevice( displayParams, TTRUE );
98
99 if ( !pDevice )
100 {
101 if ( displayParams.uiColourDepth == 32 )
102 {
103 displayParams.uiColourDepth = 16;
104 pDevice = FindSuitableDevice( displayParams, TTRUE );
105
106 if ( pDevice == TNULL )
107 {
109 return TFALSE;
110 }
111 }
112 else
113 {
115 return TFALSE;
116 }
117 }
118
119 if ( pRenderer->CreateDisplay( displayParams ) )
120 {
121 TTODO( "Log info about choosen device" );
122 return TTRUE;
123 }
124
125 return TFALSE;
126}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TTODO(DESC)
Definition Defines.h:134
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
bool TBOOL
Definition Typedefs.h:6
HWND GetHWND() const
Definition TMSWindow.h:52
virtual TBOOL Create() OVERRIDE
Creates the render interface.
virtual TBOOL CreateDisplay(const DISPLAYPARAMS &a_rParams) OVERRIDE
Creates a display with the specified parameters.
TFORCEINLINE TMSWindow * GetMSWindow()
Gets the MS window.
virtual void SetGamma(TFLOAT a_fGamma)
Sets the gamma value.
virtual void OnInitializationFailureDisplay() OVERRIDE
Called when display initialization fails.
void SetAutoCreateSystemResources(TBOOL a_bAutoCreate)
class TObject * CreateObject() const
Definition TClass.cpp:116
static TClass * Find(const TCHAR *name, TClass *parent=TNULL)
Definition TClass.cpp:110
static TFORCEINLINE TKernelInterface * GetSingleton()
Definition TSingleton.h:49
TKernelInterfaceDLL * LoadInterface(const TString8 &a_rcName)
Definition TSystem.cpp:83
Toshi::TRenderAdapter::Mode::Device * FindSuitableDevice(Toshi::TRenderInterface::DISPLAYPARAMS &a_rDisplayParams, bool a_bReverseOrder)
TBOOL CreateTRenderResources()

◆ CreateTRenderResources()

TBOOL ARenderer::CreateTRenderResources ( )

Definition at line 128 of file ARenderer_Win.cpp.

129{
130 TIMPLEMENT();
131
132 auto pRenderer = TSTATICCAST( TRenderD3DInterface, TRenderInterface::GetSingleton() );
133
134 {
135 auto pResource = TSTATICCAST(
136 TVertexFactoryResource,
137 pRenderer->CreateResource(
138 TClass::Find( "TVertexFactoryResource" ),
139 "VFSYSVNDUV1",
140 TNULL
141 )
142 );
143
144 pRenderer->SetResourceExplicit( pResource, SYSRESOURCE_VFSYSVNDUV1 );
145
146 TVertexFactoryFormat vertexFormat;
147 vertexFormat.m_uiNumStreams = 1;
148 vertexFormat.m_aStreamFormats[ 0 ].m_uiVertexSize = 24;
149 vertexFormat.m_aStreamFormats[ 0 ].m_Unk = 0;
150 pResource->Create( &vertexFormat, 54050, 0 );
151 }
152
153 {
154 auto pResource = TSTATICCAST(
155 TVertexFactoryResource,
156 pRenderer->CreateResource(
157 TClass::Find( "TVertexFactoryResource" ),
158 "VFSKIN",
159 TNULL
160 )
161 );
162
163 pRenderer->SetResourceExplicit( pResource, SYSRESOURCE_VFSKIN );
164
165 TVertexFactoryFormat vertexFormat;
166 vertexFormat.m_uiNumStreams = 1;
167 vertexFormat.m_aStreamFormats[ 0 ].m_uiVertexSize = 40;
168 vertexFormat.m_aStreamFormats[ 0 ].m_Unk = 0;
169 pResource->Create( &vertexFormat, 54050, 0 );
170 }
171
172 {
173 auto pResource = TSTATICCAST(
174 TVertexFactoryResource,
175 pRenderer->CreateResource(
176 TClass::Find( "TVertexFactoryResource" ),
177 "VFWORLD",
178 TNULL
179 )
180 );
181
182 pRenderer->SetResourceExplicit( pResource, SYSRESOURCE_VFWORLD );
183
184 TVertexFactoryFormat vertexFormat;
185 vertexFormat.m_uiNumStreams = 1;
186 vertexFormat.m_aStreamFormats[ 0 ].m_uiVertexSize = 44;
187 vertexFormat.m_aStreamFormats[ 0 ].m_Unk = 0;
188 pResource->Create( &vertexFormat, 54050, 0 );
189 }
190
191 {
192 auto pResource = TSTATICCAST(
193 TIndexFactoryResource,
194 pRenderer->CreateResource(
195 TClass::Find( "TIndexFactoryResource" ),
196 "IFSYS",
197 TNULL
198 )
199 );
200
201 pRenderer->SetResourceExplicit( pResource, SYSRESOURCE_IFSYS );
202
203 TIndexFactoryFormat indexFormat;
204 indexFormat.uiIndexSize = 2;
205 pResource->Create( &indexFormat, 64700, 0 );
206 }
207
208 {
209 auto pResource = pRenderer->CreateResource(
210 TClass::Find( "TTextureFactoryHAL" ),
211 "TextureFactory",
212 TNULL
213 );
214
215 pRenderer->SetResourceExplicit( pResource, SYSRESOURCE_TEXTUREFACTORY );
216 pResource->Create();
217 }
218
219 return TTRUE;
220}
@ SYSRESOURCE_VFSKIN
Definition TRender.h:10
@ SYSRESOURCE_IFSYS
Definition TRender.h:18
@ SYSRESOURCE_VFSYSVNDUV1
Definition TRender.h:9
@ SYSRESOURCE_TEXTUREFACTORY
Definition TRender.h:20
@ SYSRESOURCE_VFWORLD
Definition TRender.h:14
#define TIMPLEMENT()
Definition Defines.h:136
TVertexStreamFormat m_aStreamFormats[MAX_NUM_STREAMS]

◆ DeinitialiseClass()

void ARenderer::DeinitialiseClass ( )
static

Definition at line 40 of file ARenderer_Win.cpp.

◆ FindSuitableDevice()

TRenderAdapter::Mode::Device * ARenderer::FindSuitableDevice ( Toshi::TRenderInterface::DISPLAYPARAMS & a_rDisplayParams,
bool a_bReverseOrder )

Definition at line 222 of file ARenderer_Win.cpp.

223{
224 auto pRenderer = TSTATICCAST( TRenderD3DInterface, TRenderInterface::GetSingleton() );
225 TRenderAdapter::Mode::Device* pDevice = TNULL;
226
227 if ( a_bReverseOrder )
228 {
229 a_rDisplayParams.eDepthStencilFormat = 4;
230 pDevice = pRenderer->FindDevice( a_rDisplayParams );
231
232 if ( !pDevice )
233 {
234 a_rDisplayParams.eDepthStencilFormat = 2;
235 pDevice = pRenderer->FindDevice( a_rDisplayParams );
236
237 if ( !pDevice )
238 {
239 a_rDisplayParams.eDepthStencilFormat = 3;
240 pDevice = pRenderer->FindDevice( a_rDisplayParams );
241
242 if ( !pDevice )
243 {
244 a_rDisplayParams.eDepthStencilFormat = 0;
245 pDevice = pRenderer->FindDevice( a_rDisplayParams );
246
247 if ( !pDevice )
248 {
249 a_rDisplayParams.eDepthStencilFormat = 1;
250 pDevice = pRenderer->FindDevice( a_rDisplayParams );
251 }
252 }
253 }
254 }
255 }
256 else
257 {
258 pDevice = pRenderer->FindDevice( a_rDisplayParams );
259 a_rDisplayParams.eDepthStencilFormat = 0;
260
261 if ( !pDevice )
262 {
263 a_rDisplayParams.eDepthStencilFormat = 1;
264 pDevice = pRenderer->FindDevice( a_rDisplayParams );
265
266 if ( !pRenderer->FindDevice( a_rDisplayParams ) )
267 {
268 a_rDisplayParams.eDepthStencilFormat = 2;
269 pDevice = pRenderer->FindDevice( a_rDisplayParams );
270
271 if ( !pRenderer->FindDevice( a_rDisplayParams ) )
272 {
273 a_rDisplayParams.eDepthStencilFormat = 4;
274 pDevice = pRenderer->FindDevice( a_rDisplayParams );
275
276 if ( !pRenderer->FindDevice( a_rDisplayParams ) )
277 {
278 a_rDisplayParams.eDepthStencilFormat = 3;
279 pDevice = pRenderer->FindDevice( a_rDisplayParams );
280 }
281 }
282 }
283 }
284 }
285
286 return pDevice;
287}

◆ ForceUpdate30FPS()

void ARenderer::ForceUpdate30FPS ( )

Definition at line 476 of file ARenderer_Win.cpp.

477{
478 OnUpdate( 1.0f / 30.0f );
479}
virtual TBOOL OnUpdate(TFLOAT a_fDeltaTime) override

◆ GetAnimationUpdateEndEmitter()

Toshi::TEmitter< ARenderer, TBOOL * > & ARenderer::GetAnimationUpdateEndEmitter ( )
inline

Definition at line 38 of file ARenderer.h.

38{ return m_AnimationUpdateEndEmitter; }

◆ GetAnimationUpdateStartEmitter()

Toshi::TEmitter< ARenderer, TBOOL * > & ARenderer::GetAnimationUpdateStartEmitter ( )
inline

Definition at line 37 of file ARenderer.h.

37{ return m_AnimationUpdateStartEmitter; }

◆ GetClass()

Toshi::TClass * ARenderer::GetClass ( )
overridevirtual

Definition at line 40 of file ARenderer_Win.cpp.

◆ GetClassStatic()

static TFORCEINLINE Toshi::TClass * ARenderer::GetClassStatic ( )
inlinestatic

Definition at line 18 of file ARenderer.h.

◆ GetMainViewport()

Toshi::TViewport * ARenderer::GetMainViewport ( ) const
inline

Definition at line 35 of file ARenderer.h.

35{ return m_pViewport; }

◆ GetRenderGUIEmitter() [1/2]

Toshi::TEmitter< ARenderer, TINT > & ARenderer::GetRenderGUIEmitter ( )
inline

Definition at line 40 of file ARenderer.h.

40{ return m_RenderGUIEmitter; }

◆ GetRenderGUIEmitter() [2/2]

const Toshi::TEmitter< ARenderer, TINT > & ARenderer::GetRenderGUIEmitter ( ) const
inline

Definition at line 41 of file ARenderer.h.

41{ return m_RenderGUIEmitter; }

◆ InitialiseClass()

void ARenderer::InitialiseClass ( )
static

Definition at line 40 of file ARenderer_Win.cpp.

◆ OnCreate()

TBOOL ARenderer::OnCreate ( )
overridevirtual

Definition at line 314 of file ARenderer_Win.cpp.

315{
316 TIMPLEMENT();
317
318 TOrderTable::CreateStaticData( 2000, 4000 );
319 TBOOL bCreatedTRender = CreateTRender();
320
321 TASSERT( bCreatedTRender );
322
323 if ( bCreatedTRender )
324 {
325 ( new AWorldShaderHAL() )->Create();
326 ( new ASkinShaderHAL() )->Create();
327 ( new AGrassShaderHAL() )->Create();
328 ( new ASysShaderHAL() )->Create();
329 CreateMainViewport();
330
331 AModelLoader::CreateSingleton();
332 AMaterialLibraryManager::CreateSingleton();
333 AKeyFrameLibraryManager::CreateSingleton();
334 AModelLoader::GetSingleton()->InitialiseStatic();
335 AGlowViewport::CreateSingleton( TLightIDList::MAX_NUM_LIGHTS * SPLITSCREEN_MAX_NUM_PLAYERS );
336 }
337
338 return bCreatedTRender;
339}
#define TASSERT(X,...)
Definition Defines.h:138
#define SPLITSCREEN_MAX_NUM_PLAYERS
Definition AViewport.h:3
static void CreateStaticData(TUINT a_uiMaxMaterials, TUINT a_uiMaxRenderPackets)
static constexpr TINT MAX_NUM_LIGHTS
TBOOL CreateTRender()

◆ OnUpdate()

TBOOL ARenderer::OnUpdate ( TFLOAT a_fDeltaTime)
overridevirtual

Definition at line 412 of file ARenderer_Win.cpp.

413{
414 TIMPLEMENT();
415
416 TRenderD3DInterface* pRender = TRenderD3DInterface::Interface();
417
418 if ( g_oTheApp.IsDestroyed() )
419 return TTRUE;
420
421 TBOOL bMoviePlaying = AMoviePlayer::IsSingletonCreated() && AMoviePlayer::GetSingleton()->IsMoviePlaying();
422
423 pRender->Update( a_fDeltaTime );
424
426 return TFALSE;
427
428 // Update transforms of glow objects
429 AGlowViewport::GetSingleton()->Update();
430
431 ARootTask* pRootTask = ARootTask::GetSingleton();
432 if ( pRootTask->IsGameSystemCreated() )
433 {
434 auto pRenderContext = TRenderInterface::GetSingleton()->GetCurrentContext();
435
436 pRender->BeginScene();
437
438 if ( bMoviePlaying )
439 {
440 AMoviePlayer::GetSingleton()->Render( a_fDeltaTime );
441 }
442 else if ( pRootTask->IsRenderWorld() )
443 {
444 const ACamera* pCamera = ACameraManager::GetSingleton()->GetCurrentCamera();
445 TMatrix44 oCamMatrix = pCamera->GetMatrix();
446 oCamMatrix.SetTranslation( pCamera->GetMatrix().GetTranslation() );
447
448 UpdateMainCamera( oCamMatrix, pCamera );
449 m_pViewport->AllowDepthClear( TFALSE );
450
451 pRenderContext->EnableFog( TTRUE );
452 RenderMainScene( a_fDeltaTime );
453 }
454
455 if ( m_bRenderGUI )
456 RenderGUI();
457
458 pRender->EndScene();
459 return TTRUE;
460 }
461 else
462 {
463 pRender->BeginScene();
464
465 if ( bMoviePlaying )
466 AMoviePlayer::GetSingleton()->Render( a_fDeltaTime );
467
468 if ( m_bRenderGUI )
469 RenderGUI();
470
471 pRender->EndScene();
472 return TTRUE;
473 }
474}
AApplication g_oTheApp
Definition AppBoot.cpp:31
TSystemManager g_oSystemManager
Definition TSystem.cpp:15
void SetTranslation(const TVector4 &a_rTranslation)
Definition TMatrix44.h:167
virtual TBOOL BeginScene() OVERRIDE
Begins a new rendering scene.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
virtual TBOOL Update(float a_fDeltaTime) OVERRIDE
Updates the render interface state.
virtual TBOOL EndScene() OVERRIDE
Ends the current rendering scene and presents the results.
TRenderContext * GetCurrentContext() const
TBOOL IsPaused() const
Definition TSystem.h:160
Toshi::TMatrix44 & GetMatrix()
Definition ACamera.cpp:58
void UpdateMainCamera(const Toshi::TMatrix44 &a_rTransformMatrix, const ACamera *a_pCamera)
TBOOL IsRenderWorld()
Definition ARootTask.h:30
TBOOL IsGameSystemCreated() const
Definition ARootTask.h:27

◆ UpdateMainCamera()

void ARenderer::UpdateMainCamera ( const Toshi::TMatrix44 & a_rTransformMatrix,
const ACamera * a_pCamera )

Definition at line 341 of file ARenderer_Win.cpp.

342{
343 m_pCameraObject->SetProjectionCentreX( a_pCamera->m_fProjectionCentreX );
344 m_pCameraObject->SetProjectionCentreY( a_pCamera->m_fProjectionCentreY );
345 m_pCameraObject->SetFOV( a_pCamera->m_fFOV );
346 m_pCameraObject->GetTransformObject().SetMatrix( a_rTransformMatrix );
347 m_pCameraObject->SetFar( m_fFar );
348 m_pCameraObject->SetNear( m_fNear );
349}

Member Data Documentation

◆ ms_oClass

Toshi::TClass ARenderer::ms_oClass = Toshi::TClass( "ARenderer", ARenderer::PARENTCLASS, ARenderer::CreateTObject, ARenderer::CreateTObjectInPlace, ARenderer::InitialiseClass, ARenderer::DeinitialiseClass, 0, 1, sizeof( ARenderer ), alignof( ARenderer ) )
static

Definition at line 18 of file ARenderer.h.

◆ PARENTCLASS

Toshi::TClass* ARenderer::PARENTCLASS = & Toshi::TTask::ms_oClass
staticconstexpr

Definition at line 18 of file ARenderer.h.


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