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

DirectX 8 implementation of the render interface Handles DirectX 8 specific rendering functionality and device management. More...

#include <TRenderInterface_DX8.h>

Inheritance diagram for TRenderD3DInterface:
TRenderInterface TObject TSingleton< TRenderInterface > TRefCounted

Public Types

using ThisClass = TRenderD3DInterface
 
using BaseClass = TRenderInterface
 
- Public Types inherited from TRenderInterface
enum  ASPECT_RATIO_ : ASPECT_RATIO { ASPECT_RATIO_4_3 , ASPECT_RATIO_16_9 }
 
typedef TUINT32 ASPECT_RATIO
 
- Public Types inherited from TObject
enum  { IsTObject = TTRUE }
 

Public Member Functions

virtual Toshi::TClass * GetClass () override
 
 TRenderD3DInterface ()
 
 ~TRenderD3DInterface ()
 
virtual TBOOL CreateDisplay (const DISPLAYPARAMS &a_rParams) OVERRIDE
 Creates a display with the specified parameters.
 
virtual TBOOL DestroyDisplay () OVERRIDE
 Destroys the current display and releases associated resources.
 
virtual TBOOL Update (float a_fDeltaTime) OVERRIDE
 Updates the render interface state.
 
virtual TBOOL BeginScene () OVERRIDE
 Begins a new rendering scene.
 
virtual TBOOL EndScene () OVERRIDE
 Ends the current rendering scene and presents the results.
 
virtual TRenderAdapter::Mode::DeviceGetCurrentDevice () OVERRIDE
 Gets the current rendering device.
 
virtual DISPLAYPARAMSGetCurrentDisplayParams () OVERRIDE
 Gets the current display parameters.
 
virtual TBOOL Create () OVERRIDE
 Creates the render interface.
 
virtual TBOOL Destroy () OVERRIDE
 Destroys the render interface and releases all resources.
 
virtual void RenderIndexPrimitive (TINT param_2, TINT param_3, TINT param_4, TINT param_5, TINT param_6, TINT param_7) OVERRIDE
 Renders an indexed primitive.
 
virtual float GetPixelAspectRatio () OVERRIDE
 Gets the pixel aspect ratio.
 
virtual TBOOL SetPixelAspectRatio (float a_fPixelAspectRatio) OVERRIDE
 Sets the pixel aspect ratio.
 
virtual void FlushOrderTables () OVERRIDE
 Flushes all order tables.
 
virtual TBOOL IsTextureFormatSupported (TINT a_eTextureFormat) OVERRIDE
 Checks if a texture format is supported.
 
virtual TBOOL Supports32BitTextures () OVERRIDE
 Checks if 32-bit textures are supported.
 
virtual TRenderContextCreateRenderContext () OVERRIDE
 Creates a new render context.
 
virtual TRenderCaptureCreateCapture () OVERRIDE
 Creates a new render capture.
 
virtual void DestroyCapture (TRenderCapture *a_pRenderCapture) OVERRIDE
 Destroys a render capture.
 
virtual void * CreateUnknown (const TCHAR *a_szName, TINT a_iUnk1, TINT a_iUnk2, TINT a_iUnk3) OVERRIDE
 Creates an unknown object.
 
virtual TModelCreateModel (TTMD *a_pTMD, TBOOL a_bLoad) OVERRIDE
 Creates a model from a TMD file.
 
virtual TModelCreateModel (const TCHAR *a_szFilePath, TBOOL a_bLoad) OVERRIDE
 Creates a model from a file.
 
virtual TModelCreateModel (const TCHAR *a_szFilePath, TBOOL a_bLoad, TTRB *a_pAssetTRB, TUINT8 a_ui8FileNameLen) OVERRIDE
 Creates a model from a file with TRB asset.
 
virtual void OnInitializationFailureDevice () OVERRIDE
 Called when device initialization fails.
 
virtual void OnInitializationFailureDisplay () OVERRIDE
 Called when display initialization fails.
 
virtual TDebugTextCreateDebugText () OVERRIDE
 Creates debug text.
 
virtual void DestroyDebugText () OVERRIDE
 Destroys debug text.
 
virtual TBOOL RecreateDisplay (const DISPLAYPARAMS &a_rDisplayParams)
 Recreates the display with new parameters.
 
virtual void SetContrast (TFLOAT a_fConstrast)
 Sets the contrast value.
 
virtual void SetBrightness (TFLOAT a_fBrightness)
 Sets the brightness value.
 
virtual void SetGamma (TFLOAT a_fGamma)
 Sets the gamma value.
 
virtual void SetSaturate (TFLOAT a_fSaturate)
 Sets the saturation value.
 
virtual TFLOAT GetContrast () const
 Gets the current contrast value.
 
virtual TFLOAT GetBrightness () const
 Gets the current brightness value.
 
virtual TFLOAT GetGamma () const
 Gets the current gamma value.
 
virtual TFLOAT GetSaturate () const
 Gets the current saturation value.
 
virtual void UpdateColourSettings ()
 Updates color correction settings.
 
virtual TBOOL IsCapableColourCorrection ()
 Checks if color correction is supported.
 
virtual void EnableColourCorrection (TBOOL a_bEnable)
 Enables or disables color correction.
 
virtual void ForceEnableColourCorrection (TBOOL a_bEnable)
 Forces color correction on or off.
 
virtual TBOOL IsColourCorrection ()
 Checks if color correction is enabled.
 
TBOOL IsTextureFormatSupportedImpl (D3DFORMAT a_eFormat)
 Checks if a specific D3D format is supported.
 
TBOOL Create (const TCHAR *a_szWindowName)
 Creates the render interface with a specific window name.
 
void BuildAdapterDatabase ()
 Builds the adapter database.
 
void DestroyAccelTable ()
 Destroys the accelerator table.
 
void CreateAccelTable ()
 Creates the accelerator table.
 
void GetCurrentColourRamp ()
 Gets the current color ramp.
 
TDebugD3DTextInitDebugText (TINT a_iBufferSize)
 Initializes debug text.
 
void SetDeviceDefaultStates ()
 Sets default device states.
 
void SetTextureAddress (TINT a_iStage, ADDRESSINGMODE a_eAddressing, TEXCOORD a_eTextureCoordinate=TEXCOORD_UV)
 Sets texture addressing mode.
 
void ClearRegion (TINT a_iX, TINT a_iY, TINT a_iWidth, TINT a_iHeight, TUINT8 a_eClearFlags, TUINT8 a_uiColorR, TUINT8 a_uiColorG, TUINT8 a_uiColorB, TFLOAT a_fZ, TUINT a_uiStencil)
 Clears a region of the screen.
 
void Exit ()
 Signals the render interface to exit.
 
void RegisterOrderTable (TOrderTable *a_pOrderTable)
 Registers an order table.
 
TFORCEINLINE TMSWindowGetMSWindow ()
 Gets the MS window.
 
TFORCEINLINE TPriList< TOrderTable > & GetOrderTables ()
 Gets the order tables.
 
TFORCEINLINE IDirect3D8 * GetDirect3D () const
 Gets the Direct3D interface.
 
TFORCEINLINE IDirect3DDevice8 * GetDirect3DDevice () const
 Gets the Direct3D device.
 
- Public Member Functions inherited from TRenderInterface
 TDECLARE_CLASS (TRenderInterface, TObject)
 
 TRenderInterface ()
 
virtual ~TRenderInterface ()
 
virtual void DumpStats ()
 
virtual void GetScreenOffset (TVector2 &a_rVec)
 
virtual void SetScreenOffset (const TVector2 &a_rVec)
 
virtual float GetScreenAspectRatio ()
 
virtual void SetLightDirectionMatrix (const TMatrix44 &a_rMatrix)
 
virtual void SetLightColourMatrix (const TMatrix44 &a_rMatrix)
 
virtual void Unknown1 (TViewport *a_pViewport)
 
virtual TBOOL CreateSystemResources ()
 
virtual void DestroySystemResources ()
 
TBOOL CreateDisplay ()
 
void DestroyResource (TResource *resource)
 
void DestroyResourceRecurse (TResource *resource)
 
template<class T>
T * GetSystemResource (SYSRESOURCE systemResource)
 
void SetResourceExplicit (TResource *resource, SYSRESOURCE systemResource)
 
TResourceCreateResource (TClass *pClass, const TCHAR *name, TResource *parent)
 
TRenderContextSetCurrentRenderContext (TRenderContext *a_pRenderContext)
 
void SetAutoCreateSystemResources (TBOOL a_bAutoCreate)
 
TBOOL IsInScene ()
 
TBOOL IsCreated ()
 
TBOOL IsDisplayCreated ()
 
const TMatrix44GetLightDirection () const
 
const TMatrix44GetLightColour () const
 
TRenderContextGetCurrentContext () const
 
TNodeList< TRenderAdapter > * GetAdapterList ()
 
TKeyframeLibraryManagerGetKeyframeLibraryManager ()
 
TStack< TMatrix44, 20 > & GetTransforms ()
 
TTextureGetInvalidTexture ()
 
void DestroyAllShaderResources ()
 
void FlushDyingResources ()
 
void DestroyDyingResources (TResource *resources)
 
void DeleteResource (TResource *resources)
 
void DeleteResourceRecurse (TResource *resources)
 
void DeleteResourceAtomic (TResource *resources)
 
TRenderAdapter::Mode::DeviceFindDevice (const DISPLAYPARAMS &a_rDisplayParams)
 
void BeginEndSceneHAL ()
 
- Public Member Functions inherited from TObject
virtual void Delete ()
 
virtual ~TObject ()
 
TBOOL IsExactly (TClass *a_pClass)
 
TBOOL IsA (TClass *a_pClass)
 
- Public Member Functions inherited from TSingleton< TRenderInterface >
 TSingleton (const TSingleton &)=delete
 
 TSingleton (const TSingleton &&)=delete
 
TSingletonoperator= (const TSingleton &)=delete
 
TSingletonoperator= (const TSingleton &&)=delete
 
- Public Member Functions inherited from TRefCounted
 TRefCounted ()
 
 ~TRefCounted ()
 
TINT DecRefCount ()
 
TINT GetRefCount ()
 
TINT IncRefCount ()
 
TRefCountedoperator= (TRefCounted 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 void FlushShaders ()
 Flushes all order tables and shaders.
 
static TBOOL CreateVertexShader (const DWORD *a_ShaderDeclaration, const DWORD *a_pFunction, DWORD *a_pOutVertexShader)
 Creates a vertex shader.
 
static void DestroyVertexShader (DWORD a_hVertexShader)
 Destroys a vertex shader.
 
static TBOOL CreatePixelShader (const DWORD *a_pFunction, DWORD *a_pOutPixelShader)
 Creates a pixel shader.
 
static void DestroyPixelShader (DWORD a_hPixelShader)
 Destroys a pixel shader.
 
static void PrintError (TINT32 a_eError, const TCHAR *a_szInfo)
 Prints error text caused by some directx call.
 
static const TCHARGetErrorString (TINT32 a_eError)
 Gets the error string for an error code.
 
static const TCHARGetErrorDescription (TINT32 a_eError)
 Gets the error description for an error code.
 
static TFORCEINLINE TRenderD3DInterfaceInterface ()
 Gets the render interface singleton.
 
- Static Public Member Functions inherited from TObject
static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE TClassGetClassStatic ()
 
- Static Public Member Functions inherited from TSingleton< TRenderInterface >
static TFORCEINLINE TRenderInterfaceCreateSingleton (Args &&... args)
 
static TFORCEINLINE D * CreateSingleton (Args &&... args)
 
static TFORCEINLINE void DestroySingleton ()
 
static TFORCEINLINE TRenderInterfaceGetSingletonSafe ()
 
static TFORCEINLINE TBOOL IsSingletonCreated ()
 
static TFORCEINLINE TRenderInterfaceGetSingleton ()
 

Public Attributes

friend TMSWindow
 

Static Public Attributes

static constexpr Toshi::TClass * PARENTCLASS = & TRenderInterface::ms_oClass
 
static Toshi::TClass ms_oClass = Toshi::TClass( "TRenderD3DInterface", TRenderD3DInterface::PARENTCLASS, TRenderD3DInterface::CreateTObject, TRenderD3DInterface::CreateTObjectInPlace, TRenderD3DInterface::InitialiseClass, TRenderD3DInterface::DeinitialiseClass, 0, 1, sizeof( TRenderD3DInterface ), alignof( TRenderD3DInterface ) )
 
- Static Public Attributes inherited from TRenderInterface
static constexpr size_t MAXNUMRESOURCES = 6000
 
- Static Public Attributes inherited from TObject
static constexpr Toshi::TClass * PARENTCLASS = TNULL
 
static constinit Toshi::TClass ms_oClass = Toshi::TClass( "TObject", TObject::CreateTObject, TObject::CreateTObjectInPlace, TObject::InitialiseClass, TObject::DeinitialiseClass, 0, 2, sizeof( TObject ), alignof( TObject ) )
 

Additional Inherited Members

- Protected Member Functions inherited from TSingleton< TRenderInterface >
TFORCEINLINE TSingleton ()
 
TFORCEINLINE ~TSingleton ()
 
- Protected Attributes inherited from TRenderInterface
TBOOL m_bCreateSystemResources
 
TBOOL m_bInScene
 
TBOOL m_bCreated = false
 
TBOOL m_bDisplayCreated
 
TVector2 m_ScreenOffset
 
TRenderContextm_pCurrentContext
 
TRenderContextm_pCreatedContext
 
TResourcem_SystemResources [SYSRESOURCE_NUMOF]
 
TMatrix44 m_LightDirection
 
TMatrix44 m_LightColour
 
TDebugTextm_pDebugText
 
void * m_Unk2
 
TTexturem_pInvalidTexture
 
TNodeList< TRenderAdapterm_AdapterList
 
TNodeTree< TResourcem_Resources
 
TUINT32 m_ResourceCount = 0
 
TUINT32 m_iFrameCount = 0
 
TBOOL m_bHasDyingResources
 
TKeyframeLibraryManager m_KeyframeManager
 
TGenericEmitter m_BeginSceneEmitter
 
TGenericEmitter m_EndSceneEmitter
 
TStack< TMatrix44, 20 > m_Transforms
 
- Protected Attributes inherited from TRefCounted
TINT m_iRefCount
 
- Static Protected Attributes inherited from TSingleton< TRenderInterface >
static TRenderInterfacems_pSingleton
 

Detailed Description

DirectX 8 implementation of the render interface Handles DirectX 8 specific rendering functionality and device management.

Definition at line 17 of file TRenderInterface_DX8.h.

Member Typedef Documentation

◆ BaseClass

◆ ThisClass

Constructor & Destructor Documentation

◆ TRenderD3DInterface()

TRenderD3DInterface::TRenderD3DInterface ( )

Definition at line 42 of file TRenderInterface_DX8.cpp.

43{
44 m_pDirect3D = TNULL;
45 m_pDirectDevice = TNULL;
46 m_fPixelAspectRatio = 1.0f;
47 m_AcceleratorTable = NULL;
48 m_pDevice = TNULL;
49 m_oDisplayParams.uiWidth = 640; // Default width
50 m_oDisplayParams.uiHeight = 480; // Default height
51 m_oDisplayParams.uiColourDepth = 32; // Default color depth
52 m_oDisplayParams.eDepthStencilFormat = 0;
53 m_oDisplayParams.bWindowed = TTRUE;
54 m_fBrightness = 0.5f; // Default brightness
55 m_fSaturate = 0.5f; // Default saturation
56 m_bExited = TFALSE;
57 m_bCheckedCapableColourCorrection = TFALSE;
58 m_bCapableColourCorrection = TFALSE;
59 m_bFailed = TFALSE;
60 m_Unk1 = TNULL;
61 m_Unk2 = TNULL;
62 m_fContrast = 0.583012f; // Default contrast
63 m_fGamma = 0.420849f; // Default gamma
64 m_bChangedColourSettings = TTRUE;
65 m_bEnableColourCorrection = TTRUE;
66}
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25

◆ ~TRenderD3DInterface()

TRenderD3DInterface::~TRenderD3DInterface ( )

Definition at line 70 of file TRenderInterface_DX8.cpp.

71{
72 Destroy();
73}
virtual TBOOL Destroy() OVERRIDE
Destroys the render interface and releases all resources.

Member Function Documentation

◆ BeginScene()

TBOOL TRenderD3DInterface::BeginScene ( )
virtual

Begins a new rendering scene.

Returns
True if successful, false otherwise

Reimplemented from TRenderInterface.

Definition at line 255 of file TRenderInterface_DX8.cpp.

256{
257 TASSERT( !IsInScene() );
258
260 {
261 HRESULT hRes = m_pDirectDevice->BeginScene();
262
263 if ( SUCCEEDED( hRes ) )
264 {
265 RECT windowRect;
266 GetWindowRect( m_Window.GetHWND(), &windowRect );
267
268 D3DVIEWPORT8 viewport = {
269 .X = 0,
270 .Y = 0,
271 .Width = DWORD( windowRect.right - windowRect.left ),
272 .Height = DWORD( windowRect.bottom - windowRect.top ),
273 .MinZ = 0.0f,
274 .MaxZ = 1.0f,
275 };
276
277 m_pDirectDevice->SetViewport( &viewport );
279
281 m_BeginSceneEmitter.Throw( 0 );
282 }
283 else
284 {
285 return TFALSE;
286 }
287 }
288
289 return TTRUE;
290}
#define TASSERT(X,...)
Definition Defines.h:138
virtual void UpdateColourSettings()
Updates color correction settings.
TGenericEmitter m_BeginSceneEmitter
virtual TBOOL BeginScene()

◆ BuildAdapterDatabase()

void TRenderD3DInterface::BuildAdapterDatabase ( )

Builds the adapter database.

Definition at line 921 of file TRenderInterface_DX8.cpp.

922{
923 UINT uiAdapterCount = m_pDirect3D->GetAdapterCount();
924
925 for ( UINT i = 0; i < uiAdapterCount; i++ )
926 {
927 auto pAdapter = new TD3DAdapter();
928 pAdapter->SetAdapterIndex( i );
929
930 D3DDISPLAYMODE displayMode;
931 auto pIdentifier = pAdapter->GetD3DIdentifier8();
932 m_pDirect3D->GetAdapterIdentifier( i, D3DENUM_NO_WHQL_LEVEL, pIdentifier );
933 m_pDirect3D->GetAdapterDisplayMode( i, &displayMode );
934
935 pAdapter->SetDriver( pIdentifier->Driver );
936 pAdapter->SetDescription( pIdentifier->Description );
937 pAdapter->SetDriverVersionLowPart( pIdentifier->DriverVersion.LowPart );
938 pAdapter->SetDriverVersionHighPart( pIdentifier->DriverVersion.HighPart );
939 pAdapter->SetDeviceId( pIdentifier->DeviceId );
940 pAdapter->SetVendorId( pIdentifier->VendorId );
941 pAdapter->SetSubSysId( pIdentifier->SubSysId );
942 pAdapter->SetRevision( pIdentifier->Revision );
943 pAdapter->SetDeviceIdentifier( pIdentifier->DeviceIdentifier );
944
945 pAdapter->GetMode().SetD3DDisplayMode( displayMode );
946 pAdapter->EnumerateOutputs( this );
947
948 GetAdapterList()->InsertTail( pAdapter );
949 }
950}
TNodeList< TRenderAdapter > * GetAdapterList()
void InsertTail(T *a_pNode)
Definition TNodeList.h:220

◆ ClearRegion()

void TRenderD3DInterface::ClearRegion ( TINT a_iX,
TINT a_iY,
TINT a_iWidth,
TINT a_iHeight,
TUINT8 a_eClearFlags,
TUINT8 a_uiColorR,
TUINT8 a_uiColorG,
TUINT8 a_uiColorB,
TFLOAT a_fZ,
TUINT a_uiStencil )

Clears a region of the screen.

Parameters
a_iXX position
a_iYY position
a_iWidthWidth
a_iHeightHeight
a_eClearFlagsClear flags
a_uiColorRRed component
a_uiColorGGreen component
a_uiColorBBlue component
a_fZZ value
a_uiStencilStencil value

Definition at line 792 of file TRenderInterface_DX8.cpp.

793{
794 // Build clear flags based on parameters
795 DWORD eFlags = ( a_eClearFlags & 1 ) ? D3DCLEAR_TARGET : 0;
796
797 if ( a_eClearFlags & 2 )
798 {
799 eFlags = eFlags | D3DCLEAR_ZBUFFER;
800 TMath::Clip( a_fZ, 0.0f, 1.0f );
801 }
802
803 if ( a_eClearFlags & 4 )
804 {
805 eFlags = eFlags | D3DCLEAR_STENCIL;
806 }
807
808 // Clear the specified region
809 m_pDirectDevice->Clear(
810 0,
811 NULL,
812 eFlags,
813 ( ( a_uiColorR | 0xffffff00 ) << 8 | (TUINT)a_uiColorG ) << 8 | (TUINT)a_uiColorB,
814 a_fZ,
815 a_uiStencil
816 );
817}
unsigned int TUINT
Definition Typedefs.h:8
TFORCEINLINE void Clip(T &rVal, const T &Min, const T &Max)

◆ Create() [1/2]

TBOOL TRenderD3DInterface::Create ( )
virtual

Creates the render interface.

Returns
True if successful, false otherwise

Reimplemented from TRenderInterface.

Definition at line 344 of file TRenderInterface_DX8.cpp.

345{
346 return Create( TClassObjectName.GetName() );
347}
#define TClassObjectName
Definition TObject.h:12
virtual TBOOL Create() OVERRIDE
Creates the render interface.

◆ Create() [2/2]

TBOOL TRenderD3DInterface::Create ( const TCHAR * a_szWindowName)

Creates the render interface with a specific window name.

Parameters
a_szWindowNameName of the window
Returns
True if successful, false otherwise

Definition at line 884 of file TRenderInterface_DX8.cpp.

885{
886 TASSERT( TFALSE == IsCreated() );
887
889 {
890 // Create Direct3D 8 interface
891 m_pDirect3D = Direct3DCreate8( D3D_SDK_VERSION );
892
893 if ( m_pDirect3D )
894 {
895 // Initialize adapter database and create accelerator table
898
899 // Create window
900 if ( m_Window.Create( this, a_szWindowName ) )
901 {
902 // Create system resources if needed
904 {
906 }
907
908 return TTRUE;
909 }
910 }
911 else
912 {
914 }
915 }
916
917 return TFALSE;
918}
void BuildAdapterDatabase()
Builds the adapter database.
void CreateAccelTable()
Creates the accelerator table.
virtual void OnInitializationFailureDevice() OVERRIDE
Called when device initialization fails.
virtual TBOOL Create()
virtual TBOOL CreateSystemResources()

◆ CreateAccelTable()

void TRenderD3DInterface::CreateAccelTable ( )

Creates the accelerator table.

Definition at line 962 of file TRenderInterface_DX8.cpp.

963{
965
966 ACCEL accel[ 2 ];
967 accel[ 0 ].fVirt = 1;
968 accel[ 0 ].key = 27;
969 accel[ 0 ].cmd = 0;
970 accel[ 1 ].fVirt = 16;
971 accel[ 1 ].key = 13;
972 accel[ 1 ].cmd = 0;
973 m_AcceleratorTable = CreateAcceleratorTableA( accel, 2 );
974}
void DestroyAccelTable()
Destroys the accelerator table.

◆ CreateCapture()

TRenderCapture * TRenderD3DInterface::CreateCapture ( )
virtual

Creates a new render capture.

Returns
Pointer to the new render capture

Implements TRenderInterface.

Definition at line 498 of file TRenderInterface_DX8.cpp.

499{
500 return new TRenderCaptureD3D();
501}

◆ CreateDebugText()

TDebugText * TRenderD3DInterface::CreateDebugText ( )
virtual

Creates debug text.

Returns
Pointer to the created debug text

Implements TRenderInterface.

Definition at line 568 of file TRenderInterface_DX8.cpp.

569{
571 return m_pDebugText;
572}
TDebugD3DText * InitDebugText(TINT a_iBufferSize)
Initializes debug text.
TDebugText * m_pDebugText

◆ CreateDisplay()

TBOOL TRenderD3DInterface::CreateDisplay ( const DISPLAYPARAMS & a_rParams)
virtual

Creates a display with the specified parameters.

Parameters
a_rParamsDisplay parameters including resolution, color depth, etc.
Returns
True if successful, false otherwise

Reimplemented from TRenderInterface.

Definition at line 78 of file TRenderInterface_DX8.cpp.

79{
81 {
83 return TFALSE;
84 }
85
86 // Find appropriate device for the display parameters
87 m_pDevice = TSTATICCAST( TD3DAdapter::Mode::Device, FindDevice( a_rParams ) );
88 m_oDisplayParams = a_rParams;
89
90 if ( m_pDevice )
91 {
92 auto pDisplayParams = GetCurrentDisplayParams();
93
94 // Get desktop window dimensions
95 RECT clientRect;
96 GetClientRect( GetDesktopWindow(), &clientRect );
97
98 // Handle large displays
99 if ( 2000 < clientRect.right )
100 {
101 clientRect.right /= 2;
102 }
103
104 TUINT32 uiWindowPosX = 0;
105 TUINT32 uiWindowPosY = 0;
106
107 // Calculate window position for windowed mode
108 if ( pDisplayParams->bWindowed )
109 {
110 auto pMode = GetCurrentDevice()->GetMode();
111 uiWindowPosX = ( clientRect.right - pMode->GetWidth() ) / 2;
112 uiWindowPosY = ( clientRect.bottom - pMode->GetHeight() ) / 2;
113 }
114
115 // Initialize presentation parameters
116 TUtil::MemClear( &m_PresentParams, sizeof( m_PresentParams ) );
117 m_PresentParams.Windowed = pDisplayParams->bWindowed;
118 m_PresentParams.BackBufferCount = 1;
119 m_PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE;
120 m_PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
121 m_PresentParams.EnableAutoDepthStencil = TRUE;
122 m_PresentParams.hDeviceWindow = m_Window.GetHWND();
123 m_PresentParams.AutoDepthStencilFormat = TD3DAdapter::Mode::Device::DEPTHSTENCILFORMATS[ pDisplayParams->eDepthStencilFormat ];
124 m_PresentParams.BackBufferWidth = pDisplayParams->uiWidth;
125 m_PresentParams.BackBufferHeight = pDisplayParams->uiHeight;
126
127 // Get device information
128 auto pDevice = TSTATICCAST( TD3DAdapter::Mode::Device, GetCurrentDevice() );
129 auto pMode = TSTATICCAST( TD3DAdapter::Mode, pDevice->GetMode() );
130 auto pAdapter = TSTATICCAST( TD3DAdapter, pMode->GetAdapter() );
131 auto uiAdapterIndex = pAdapter->GetAdapterIndex();
132
133 // Set back buffer format based on windowed/fullscreen mode
134 if ( pDisplayParams->bWindowed )
135 {
136 m_PresentParams.BackBufferFormat = pMode->GetD3DDisplayMode().Format;
137 }
138 else
139 {
140 m_PresentParams.BackBufferFormat = pMode->GetBackBufferFormat( pDisplayParams->uiColourDepth );
141 }
142
143 // Create Direct3D device
144 HRESULT hRes = m_pDirect3D->CreateDevice(
145 uiAdapterIndex,
146 TD3DAdapter::Mode::Device::DEVICETYPES[ pDevice->GetDeviceIndex() ],
147 m_Window.GetHWND(),
148 pDevice->GetD3DDeviceFlags(),
149 &m_PresentParams,
150 &m_pDirectDevice
151 );
152
153 if ( FAILED( hRes ) )
154 {
156 PrintError( hRes, "Failed to create D3D Device!" );
157 return TFALSE;
158 }
159
160 // Initialize device states
162
163 // Set window mode
164 if ( pDisplayParams->bWindowed )
165 {
166 m_Window.SetWindowed();
167 }
168 else
169 {
170 m_Window.SetFullscreen();
171 }
172
173 // Handle multi-monitor setup
174 if ( uiAdapterIndex != 0 )
175 {
176 HMONITOR hMonitor = m_pDirect3D->GetAdapterMonitor( uiAdapterIndex );
177
178 MONITORINFO monitorInfo = { .cbSize = sizeof( monitorInfo ) };
179 GetMonitorInfoA( hMonitor, &monitorInfo );
180
181 uiWindowPosX += monitorInfo.rcMonitor.left;
182 uiWindowPosY += monitorInfo.rcMonitor.right;
183 }
184
185 // Set window position and size
186 m_Window.SetPosition( uiWindowPosX, uiWindowPosY, pDisplayParams->uiWidth, pDisplayParams->uiHeight );
187
188 // Get back buffer surface description
189 IDirect3DSurface8* pSurface;
190 m_pDirectDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );
191 pSurface->GetDesc( &m_SurfaceDesk );
192 pSurface->Release();
193
194 // Set cursor position to center of window
195 SetCursorPos(
196 uiWindowPosX + pDisplayParams->uiWidth / 2,
197 uiWindowPosY + pDisplayParams->uiHeight / 2
198 );
199
200 m_pDirectDevice->ShowCursor( TRUE );
201
202 // Create invalid texture pattern
203 TUINT invalidTextureData[ 32 ];
204 for ( TINT i = 0; i < 32; i++ )
205 {
206 invalidTextureData[ i ] = 0xff0fff0f;
207 }
208
210 m_pInvalidTexture = pTextureFactory->CreateTextureFromMemory( invalidTextureData, sizeof( invalidTextureData ), 0x11, 8, 8 );
211
212 // Enable color correction and mark display as created
215
216 return TTRUE;
217 }
218
220 return TFALSE;
221}
@ SYSRESOURCE_TEXTUREFACTORY
Definition TRender.h:20
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
uint32_t TUINT32
Definition Typedefs.h:13
int TINT
Definition Typedefs.h:7
static constexpr D3DFORMAT DEPTHSTENCILFORMATS[]
static constexpr D3DDEVTYPE DEVICETYPES[NUMSUPPORTEDDEVICES]
static void PrintError(TINT32 a_eError, const TCHAR *a_szInfo)
Prints error text caused by some directx call.
virtual void EnableColourCorrection(TBOOL a_bEnable)
Enables or disables color correction.
virtual DISPLAYPARAMS * GetCurrentDisplayParams() OVERRIDE
Gets the current display parameters.
void SetDeviceDefaultStates()
Sets default device states.
virtual TRenderAdapter::Mode::Device * GetCurrentDevice() OVERRIDE
Gets the current rendering device.
virtual void OnInitializationFailureDisplay() OVERRIDE
Called when display initialization fails.
virtual Mode * GetMode() const =0
T * GetSystemResource(SYSRESOURCE systemResource)
TTexture * m_pInvalidTexture
TRenderAdapter::Mode::Device * FindDevice(const DISPLAYPARAMS &a_rDisplayParams)
static void MemClear(void *ptr, TSIZE size)
Definition TUtil.h:91

◆ CreateModel() [1/3]

TModel * TRenderD3DInterface::CreateModel ( const TCHAR * a_szFilePath,
TBOOL a_bLoad )
virtual

Creates a model from a file.

Parameters
a_szFilePathPath to the model file
a_bLoadWhether to load the model immediately
Returns
Pointer to the created model

Implements TRenderInterface.

Definition at line 534 of file TRenderInterface_DX8.cpp.

535{
536 auto pModel = new TModelHAL();
537
538 if ( pModel )
539 {
540 if ( !pModel->Create( a_szFilePath, a_bLoad ) )
541 {
542 pModel->Delete();
543 return TNULL;
544 }
545 }
546
547 return pModel;
548}

◆ CreateModel() [2/3]

TModel * TRenderD3DInterface::CreateModel ( const TCHAR * a_szFilePath,
TBOOL a_bLoad,
TTRB * a_pAssetTRB,
TUINT8 a_ui8FileNameLen )
virtual

Creates a model from a file with TRB asset.

Parameters
a_szFilePathPath to the model file
a_bLoadWhether to load the model immediately
a_pAssetTRBPointer to the TRB asset
a_ui8FileNameLenLength of the filename
Returns
Pointer to the created model

Implements TRenderInterface.

Definition at line 551 of file TRenderInterface_DX8.cpp.

552{
553 auto pModel = new TModelHAL();
554
555 if ( pModel )
556 {
557 if ( !pModel->Create( a_szFilePath, a_bLoad, a_pAssetTRB, a_ui8FileNameLen ) )
558 {
559 pModel->Delete();
560 return TNULL;
561 }
562 }
563
564 return pModel;
565}

◆ CreateModel() [3/3]

TModel * TRenderD3DInterface::CreateModel ( TTMD * a_pTMD,
TBOOL a_bLoad )
virtual

Creates a model from a TMD file.

Parameters
a_pTMDPointer to the TMD data
a_bLoadWhether to load the model immediately
Returns
Pointer to the created model

Implements TRenderInterface.

Definition at line 517 of file TRenderInterface_DX8.cpp.

518{
519 auto pModel = new TModelHAL();
520
521 if ( pModel )
522 {
523 if ( !pModel->Create( a_pTMD, a_bLoad ) )
524 {
525 pModel->Delete();
526 return TNULL;
527 }
528 }
529
530 return pModel;
531}

◆ CreatePixelShader()

TBOOL TRenderD3DInterface::CreatePixelShader ( const DWORD * a_pFunction,
DWORD * a_pOutPixelShader )
static

Creates a pixel shader.

Parameters
a_pFunctionShader function
a_pOutPixelShaderOutput pixel shader handle
Returns
True if successful, false otherwise

Definition at line 389 of file TRenderInterface_DX8.cpp.

390{
391 auto pD3DDevice = Interface()->GetDirect3DDevice();
392 auto pCurrentDevice = Interface()->GetCurrentDevice();
393 auto bSupportsHardwareTransformations = pCurrentDevice->SupportsHardwareTransfomations();
394
395 HRESULT hRes = pD3DDevice->CreatePixelShader( a_pFunction, a_pOutPixelShader );
396
397 if ( FAILED( hRes ) )
398 {
399 PrintError( hRes, "Failure to create the pixel shader!" );
400 return TFALSE;
401 }
402
403 return TTRUE;
404}
TFORCEINLINE IDirect3DDevice8 * GetDirect3DDevice() const
Gets the Direct3D device.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
virtual TBOOL SupportsHardwareTransfomations() const =0

◆ CreateRenderContext()

TRenderContext * TRenderD3DInterface::CreateRenderContext ( )
virtual

Creates a new render context.

Returns
Pointer to the new render context

Implements TRenderInterface.

Definition at line 492 of file TRenderInterface_DX8.cpp.

493{
494 return new TRenderContextD3D( this );
495}

◆ CreateTObject()

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

Definition at line 26 of file TRenderInterface_DX8.cpp.

◆ CreateTObjectInPlace()

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

Definition at line 26 of file TRenderInterface_DX8.cpp.

◆ CreateUnknown()

void * TRenderD3DInterface::CreateUnknown ( const TCHAR * a_szName,
TINT a_iUnk1,
TINT a_iUnk2,
TINT a_iUnk3 )
virtual

Creates an unknown object.

Parameters
a_szNameName of the object
a_iUnk1Unknown parameter 1
a_iUnk2Unknown parameter 2
a_iUnk3Unknown parameter 3
Returns
Pointer to the created object

Implements TRenderInterface.

Definition at line 511 of file TRenderInterface_DX8.cpp.

512{
513 return TNULL;
514}

◆ CreateVertexShader()

TBOOL TRenderD3DInterface::CreateVertexShader ( const DWORD * a_ShaderDeclaration,
const DWORD * a_pFunction,
DWORD * a_pOutVertexShader )
static

Creates a vertex shader.

Parameters
a_ShaderDeclarationShader declaration
a_pFunctionShader function
a_pOutVertexShaderOutput vertex shader handle
Returns
True if successful, false otherwise

Definition at line 360 of file TRenderInterface_DX8.cpp.

361{
362 auto pD3DDevice = Interface()->GetDirect3DDevice();
363 auto pCurrentDevice = Interface()->GetCurrentDevice();
364 auto bSupportsHardwareTransformations = pCurrentDevice->SupportsHardwareTransfomations();
365
366 HRESULT hRes = pD3DDevice->CreateVertexShader(
367 a_ShaderDeclaration,
368 a_pFunction,
369 a_pOutVertexShader,
370 !bSupportsHardwareTransformations ? D3DCREATE_PUREDEVICE : 0
371 );
372
373 if ( FAILED( hRes ) )
374 {
375 PrintError( hRes, "Failure to create the vertex shader!" );
376 return TFALSE;
377 }
378
379 return TTRUE;
380}

◆ DeinitialiseClass()

void TRenderD3DInterface::DeinitialiseClass ( )
static

Definition at line 26 of file TRenderInterface_DX8.cpp.

◆ Destroy()

TBOOL TRenderD3DInterface::Destroy ( )
virtual

Destroys the render interface and releases all resources.

Returns
True if successful, false otherwise

Reimplemented from TRenderInterface.

Definition at line 431 of file TRenderInterface_DX8.cpp.

432{
433 TASSERT( TTRUE == IsCreated() );
434
435 if ( IsCreated() )
436 {
440
443
444 m_Window.UnregisterWindowClass();
446
447 if ( m_pDirect3D )
448 {
449 m_pDirect3D->Release();
450 m_pDirect3D = TNULL;
451 }
452
454 }
455 else
456 {
457 return TTRUE;
458 }
459}
virtual TBOOL DestroyDisplay() OVERRIDE
Destroys the current display and releases associated resources.
virtual void DestroySystemResources()
virtual TBOOL Destroy()

◆ DestroyAccelTable()

void TRenderD3DInterface::DestroyAccelTable ( )

Destroys the accelerator table.

Definition at line 952 of file TRenderInterface_DX8.cpp.

953{
954 if ( m_AcceleratorTable )
955 {
956 DestroyAcceleratorTable( m_AcceleratorTable );
957 m_AcceleratorTable = NULL;
958 }
959}

◆ DestroyCapture()

void TRenderD3DInterface::DestroyCapture ( TRenderCapture * a_pRenderCapture)
virtual

Destroys a render capture.

Parameters
a_pRenderCaptureThe render capture to destroy

Implements TRenderInterface.

Definition at line 504 of file TRenderInterface_DX8.cpp.

505{
506 TTODO( "a_pRenderCapture->vftable + 8" );
507 delete a_pRenderCapture;
508}
#define TTODO(DESC)
Definition Defines.h:134

◆ DestroyDebugText()

void TRenderD3DInterface::DestroyDebugText ( )
virtual

Destroys debug text.

Implements TRenderInterface.

Definition at line 575 of file TRenderInterface_DX8.cpp.

576{
577 if ( m_pDebugText )
578 {
579 delete m_pDebugText;
581 }
582}

◆ DestroyDisplay()

TBOOL TRenderD3DInterface::DestroyDisplay ( )
virtual

Destroys the current display and releases associated resources.

Returns
True if successful, false otherwise

Implements TRenderInterface.

Definition at line 224 of file TRenderInterface_DX8.cpp.

225{
228
229 if ( IsDisplayCreated() )
230 {
231 if ( m_pDirectDevice )
232 {
233 m_pDirectDevice->Release();
234 }
235
237 return TTRUE;
238 }
239 else
240 {
241 return TTRUE;
242 }
243}

◆ DestroyPixelShader()

void TRenderD3DInterface::DestroyPixelShader ( DWORD a_hPixelShader)
static

Destroys a pixel shader.

Parameters
a_hPixelShaderPixel shader handle to destroy

Definition at line 406 of file TRenderInterface_DX8.cpp.

407{
408 auto pD3DDevice = Interface()->GetDirect3DDevice();
409 HRESULT hRes = pD3DDevice->DeletePixelShader( a_hPixelShader );
410 TASSERT( SUCCEEDED( hRes ) );
411}

◆ DestroyVertexShader()

void TRenderD3DInterface::DestroyVertexShader ( DWORD a_hVertexShader)
static

Destroys a vertex shader.

Parameters
a_hVertexShaderVertex shader handle to destroy

Definition at line 382 of file TRenderInterface_DX8.cpp.

383{
384 auto pD3DDevice = Interface()->GetDirect3DDevice();
385 HRESULT hRes = pD3DDevice->DeleteVertexShader( a_hVertexShader );
386 TASSERT( SUCCEEDED( hRes ) );
387}

◆ EnableColourCorrection()

void TRenderD3DInterface::EnableColourCorrection ( TBOOL a_bEnable)
virtual

Enables or disables color correction.

Parameters
a_bEnableWhether to enable color correction

Definition at line 685 of file TRenderInterface_DX8.cpp.

686{
687 m_bEnableColourCorrection = a_bEnable && IsCapableColourCorrection();
688}
virtual TBOOL IsCapableColourCorrection()
Checks if color correction is supported.

◆ EndScene()

TBOOL TRenderD3DInterface::EndScene ( )
virtual

Ends the current rendering scene and presents the results.

Returns
True if successful, false otherwise

Implements TRenderInterface.

Definition at line 293 of file TRenderInterface_DX8.cpp.

294{
295 TASSERT( IsInScene() );
296
297 if ( IsInScene() )
298 {
299 m_EndSceneEmitter.Throw( TNULL );
300 HRESULT hRes = m_pDirectDevice->EndScene();
301
302 if ( SUCCEEDED( hRes ) )
303 {
304 HRESULT hPresentRes = m_pDirectDevice->Present( NULL, NULL, NULL, NULL );
305
306 if ( hPresentRes == D3DERR_DEVICELOST )
307 {
308 HRESULT hCooperativeLevel = m_pDirectDevice->TestCooperativeLevel();
309
310 if ( hCooperativeLevel == D3DERR_DEVICELOST )
311 {
312 OnD3DDeviceLost();
313 }
314 else if ( hCooperativeLevel == D3DERR_DEVICENOTRESET )
315 {
316 OnD3DDeviceFound();
317 }
318 }
319
321 }
322 else
323 {
324 return TFALSE;
325 }
326 }
327
328 return TTRUE;
329}
TGenericEmitter m_EndSceneEmitter

◆ Exit()

void TRenderD3DInterface::Exit ( )
inline

Signals the render interface to exit.

Definition at line 361 of file TRenderInterface_DX8.h.

361{ m_bExited = TTRUE; }

◆ FlushOrderTables()

void TRenderD3DInterface::FlushOrderTables ( )
virtual

Flushes all order tables.

Reimplemented from TRenderInterface.

Definition at line 481 of file TRenderInterface_DX8.cpp.

482{
483 TASSERT( TTRUE == IsInScene() );
484
485 for ( auto it = m_OrderTables.Begin(); it != m_OrderTables.End(); it++ )
486 {
487 it->Flush();
488 }
489}

◆ FlushShaders()

void TRenderD3DInterface::FlushShaders ( )
static

Flushes all order tables and shaders.

Definition at line 350 of file TRenderInterface_DX8.cpp.

351{
353
354 for ( auto it = TShader::sm_oShaderList.GetRootShader(); it != TNULL; it = it->GetNextShader() )
355 {
356 it->Flush();
357 }
358}
virtual void FlushOrderTables() OVERRIDE
Flushes all order tables.
static TShaderList sm_oShaderList
Definition TShader.h:90

◆ ForceEnableColourCorrection()

void TRenderD3DInterface::ForceEnableColourCorrection ( TBOOL a_bEnable)
virtual

Forces color correction on or off.

Parameters
a_bEnableWhether to force color correction on

Definition at line 691 of file TRenderInterface_DX8.cpp.

692{
693 m_bEnableColourCorrection = a_bEnable;
694}

◆ GetBrightness()

TFLOAT TRenderD3DInterface::GetBrightness ( ) const
virtual

Gets the current brightness value.

Returns
Current brightness value

Definition at line 644 of file TRenderInterface_DX8.cpp.

645{
646 return m_fBrightness;
647}

◆ GetClass()

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

Reimplemented from TObject.

Definition at line 26 of file TRenderInterface_DX8.cpp.

◆ GetClassStatic()

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

Definition at line 20 of file TRenderInterface_DX8.h.

◆ GetContrast()

TFLOAT TRenderD3DInterface::GetContrast ( ) const
virtual

Gets the current contrast value.

Returns
Current contrast value

Definition at line 638 of file TRenderInterface_DX8.cpp.

639{
640 return m_fContrast;
641}

◆ GetCurrentColourRamp()

void TRenderD3DInterface::GetCurrentColourRamp ( )

Gets the current color ramp.

Definition at line 715 of file TRenderInterface_DX8.cpp.

716{
717 TIMPLEMENT();
718
719 if ( m_bChangedColourSettings )
720 {
721 m_bChangedColourSettings = TFALSE;
722 }
723}
#define TIMPLEMENT()
Definition Defines.h:136

◆ GetCurrentDevice()

TRenderAdapter::Mode::Device * TRenderD3DInterface::GetCurrentDevice ( )
virtual

Gets the current rendering device.

Returns
Pointer to the current device

Implements TRenderInterface.

Definition at line 332 of file TRenderInterface_DX8.cpp.

333{
334 return m_pDevice;
335}

◆ GetCurrentDisplayParams()

TRenderInterface::DISPLAYPARAMS * TRenderD3DInterface::GetCurrentDisplayParams ( )
virtual

Gets the current display parameters.

Returns
Pointer to the current display parameters

Implements TRenderInterface.

Definition at line 338 of file TRenderInterface_DX8.cpp.

339{
340 return &m_oDisplayParams;
341}

◆ GetDirect3D()

TFORCEINLINE IDirect3D8 * TRenderD3DInterface::GetDirect3D ( ) const
inline

Gets the Direct3D interface.

Returns
Pointer to the Direct3D interface

Definition at line 385 of file TRenderInterface_DX8.h.

385{ return m_pDirect3D; }

◆ GetDirect3DDevice()

TFORCEINLINE IDirect3DDevice8 * TRenderD3DInterface::GetDirect3DDevice ( ) const
inline

Gets the Direct3D device.

Returns
Pointer to the Direct3D device

Definition at line 391 of file TRenderInterface_DX8.h.

391{ return m_pDirectDevice; }

◆ GetErrorDescription()

const TCHAR * TRenderD3DInterface::GetErrorDescription ( TINT32 a_eError)
static

Gets the error description for an error code.

Parameters
a_eErrorError code
Returns
Error description

Definition at line 983 of file TRenderInterface_DX8.cpp.

984{
985 return DXGetErrorDescription8A( a_eError );
986}

◆ GetErrorString()

const TCHAR * TRenderD3DInterface::GetErrorString ( TINT32 a_eError)
static

Gets the error string for an error code.

Parameters
a_eErrorError code
Returns
Error string

Definition at line 977 of file TRenderInterface_DX8.cpp.

978{
979 return DXGetErrorString8A( a_eError );
980}

◆ GetGamma()

TFLOAT TRenderD3DInterface::GetGamma ( ) const
virtual

Gets the current gamma value.

Returns
Current gamma value

Definition at line 650 of file TRenderInterface_DX8.cpp.

651{
652 return m_fGamma;
653}

◆ GetMSWindow()

TFORCEINLINE TMSWindow * TRenderD3DInterface::GetMSWindow ( )
inline

Gets the MS window.

Returns
Pointer to the MS window

Definition at line 373 of file TRenderInterface_DX8.h.

373{ return &m_Window; }

◆ GetOrderTables()

TFORCEINLINE TPriList< TOrderTable > & TRenderD3DInterface::GetOrderTables ( )
inline

Gets the order tables.

Returns
Reference to the order tables list

Definition at line 379 of file TRenderInterface_DX8.h.

379{ return m_OrderTables; }

◆ GetPixelAspectRatio()

TFLOAT TRenderD3DInterface::GetPixelAspectRatio ( )
virtual

Gets the pixel aspect ratio.

Returns
The current pixel aspect ratio

Reimplemented from TRenderInterface.

Definition at line 468 of file TRenderInterface_DX8.cpp.

469{
470 return m_fPixelAspectRatio;
471}

◆ GetSaturate()

TFLOAT TRenderD3DInterface::GetSaturate ( ) const
virtual

Gets the current saturation value.

Returns
Current saturation value

Definition at line 656 of file TRenderInterface_DX8.cpp.

657{
658 return m_fSaturate;
659}

◆ InitDebugText()

TDebugD3DText * TRenderD3DInterface::InitDebugText ( TINT a_iBufferSize)

Initializes debug text.

Parameters
a_iBufferSizeSize of the buffer
Returns
Pointer to the initialized debug text

Definition at line 726 of file TRenderInterface_DX8.cpp.

727{
728 TIMPLEMENT();
729 return TNULL;
730}

◆ InitialiseClass()

void TRenderD3DInterface::InitialiseClass ( )
static

Definition at line 26 of file TRenderInterface_DX8.cpp.

◆ Interface()

static TFORCEINLINE TRenderD3DInterface * TRenderD3DInterface::Interface ( )
inlinestatic

Gets the render interface singleton.

Returns
Pointer to the render interface singleton

Definition at line 453 of file TRenderInterface_DX8.h.

454 {
456 }
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49

◆ IsCapableColourCorrection()

TBOOL TRenderD3DInterface::IsCapableColourCorrection ( )
virtual

Checks if color correction is supported.

Returns
True if supported, false otherwise

Definition at line 672 of file TRenderInterface_DX8.cpp.

673{
674 if ( !m_bCheckedCapableColourCorrection )
675 {
676 D3DCAPS8 caps;
677 HRESULT hRes = m_pDirectDevice->GetDeviceCaps( &caps );
678 m_bCapableColourCorrection = SUCCEEDED( hRes ) && HASANYFLAG( caps.AdapterOrdinal, 0x20000 );
679 }
680
681 return m_bCapableColourCorrection;
682}
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5

◆ IsColourCorrection()

TBOOL TRenderD3DInterface::IsColourCorrection ( )
virtual

Checks if color correction is enabled.

Returns
True if enabled, false otherwise

Definition at line 697 of file TRenderInterface_DX8.cpp.

698{
699 return m_bEnableColourCorrection;
700}

◆ IsTextureFormatSupported()

TBOOL TRenderD3DInterface::IsTextureFormatSupported ( TINT a_eTextureFormat)
virtual

Checks if a texture format is supported.

Parameters
a_eTextureFormatThe texture format to check
Returns
True if supported, false otherwise

Reimplemented from TRenderInterface.

Definition at line 820 of file TRenderInterface_DX8.cpp.

821{
822 switch ( a_eTextureFormat )
823 {
824 case 1:
825 return IsTextureFormatSupportedImpl( D3DFMT_A8R8G8B8 );
826 case 2:
827 return IsTextureFormatSupportedImpl( D3DFMT_X8R8G8B8 );
828 case 3:
829 return IsTextureFormatSupportedImpl( D3DFMT_A1R5G5B5 );
830 case 4:
831 return TTRUE;
832 default:
833 return TFALSE;
834 }
835}
TBOOL IsTextureFormatSupportedImpl(D3DFORMAT a_eFormat)
Checks if a specific D3D format is supported.

◆ IsTextureFormatSupportedImpl()

TBOOL TRenderD3DInterface::IsTextureFormatSupportedImpl ( D3DFORMAT a_eFormat)

Checks if a specific D3D format is supported.

Parameters
a_eFormatThe D3D format to check
Returns
True if supported, false otherwise

Definition at line 838 of file TRenderInterface_DX8.cpp.

839{
840 auto pDevice = GetCurrentDevice();
841
842 return SUCCEEDED(
843 m_pDirect3D->CheckDeviceFormat(
844 pDevice->GetMode()->GetAdapter()->GetAdapterIndex(),
845 TD3DAdapter::Mode::Device::DEVICETYPES[ pDevice->GetDeviceIndex() ],
846 m_PresentParams.BackBufferFormat,
847 0,
848 D3DRTYPE_TEXTURE,
849 a_eFormat
850 )
851 );
852}

◆ OnInitializationFailureDevice()

void TRenderD3DInterface::OnInitializationFailureDevice ( )
virtual

Called when device initialization fails.

Reimplemented from TRenderInterface.

Definition at line 861 of file TRenderInterface_DX8.cpp.

862{
863 CHAR caption[ 1024 ];
864 CHAR text[ 1024 ];
865
866 GetPrivateProfileStringA( "Setup", "IDS_D3DDEVICEERRORTITLE", "Initialization failure", caption, 0x400, ".\\Setup.ini" );
867 GetPrivateProfileStringA( "Setup", "IDS_D3DDEVICEERROR", "Failed to initialize Direct3D. Please ensure DirectX8.1b is installed AND DirectX8.1b drivers for your video card", text, 0x400, ".\\Setup.ini" );
868 MessageBoxA( NULL, text, caption, 0 );
869}

◆ OnInitializationFailureDisplay()

void TRenderD3DInterface::OnInitializationFailureDisplay ( )
virtual

Called when display initialization fails.

Reimplemented from TRenderInterface.

Definition at line 872 of file TRenderInterface_DX8.cpp.

873{
874 CHAR caption[ 1024 ];
875 CHAR text[ 1024 ];
876
877 GetPrivateProfileStringA( "Setup", "IDS_D3DDISPLAYERRORTITLE", "Initialization failure", caption, 0x400, ".\\Setup.ini" );
878 GetPrivateProfileStringA( "Setup", "IDS_D3DDISPLAYERROR", "Failed to create the display. Please run the Barnyard setup program and reconfigure", text, 0x400, ".\\Setup.ini" );
879 MessageBoxA( NULL, text, caption, 0 );
880}

◆ PrintError()

void TRenderD3DInterface::PrintError ( TINT32 a_eError,
const TCHAR * a_szInfo )
static

Prints error text caused by some directx call.

Parameters
a_eErrorError code
a_szInfoAdditional error information

Definition at line 414 of file TRenderInterface_DX8.cpp.

415{
416 if ( !a_szInfo )
417 {
418 a_szInfo = "D3D Error";
419 }
420
421 const TCHAR* errString = GetErrorString( a_eError );
422 const TCHAR* errDescription = GetErrorDescription( a_eError );
423
424 TString8 string = TString8::VarArgs( "> %s: D3D Error [%s] : Description [%s] !\n", a_szInfo, errString, errDescription );
425 OutputDebugStringA( string );
426
427 TASSERT( TFALSE, string.GetString() );
428}
char TCHAR
Definition Typedefs.h:20
static const TCHAR * GetErrorDescription(TINT32 a_eError)
Gets the error description for an error code.
static const TCHAR * GetErrorString(TINT32 a_eError)
Gets the error string for an error code.
static TString8 VarArgs(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:202

◆ RecreateDisplay()

TBOOL TRenderD3DInterface::RecreateDisplay ( const DISPLAYPARAMS & a_rDisplayParams)
virtual

Recreates the display with new parameters.

Parameters
a_rDisplayParamsNew display parameters
Returns
True if successful, false otherwise

Definition at line 585 of file TRenderInterface_DX8.cpp.

586{
587 if ( IsCreated() )
588 {
589 if ( IsDisplayCreated() )
590 {
591 OnD3DDeviceLost();
593
594 if ( CreateDisplay( a_rDisplayParams ) )
595 {
596 OnD3DDeviceFound();
597 return TTRUE;
598 }
599 }
600 }
601
602 return TFALSE;
603}

◆ RegisterOrderTable()

void TRenderD3DInterface::RegisterOrderTable ( TOrderTable * a_pOrderTable)

Registers an order table.

Parameters
a_pOrderTableThe order table to register

Definition at line 988 of file TRenderInterface_DX8.cpp.

989{
990 m_OrderTables.Insert( a_pOrderTable );
991}

◆ RenderIndexPrimitive()

void TRenderD3DInterface::RenderIndexPrimitive ( TINT param_2,
TINT param_3,
TINT param_4,
TINT param_5,
TINT param_6,
TINT param_7 )
virtual

Renders an indexed primitive.

Parameters
param_2First parameter
param_3Second parameter
param_4Third parameter
param_5Fourth parameter
param_6Fifth parameter
param_7Sixth parameter

Reimplemented from TRenderInterface.

Definition at line 462 of file TRenderInterface_DX8.cpp.

463{
464 TIMPLEMENT();
465}

◆ SetBrightness()

void TRenderD3DInterface::SetBrightness ( TFLOAT a_fBrightness)
virtual

Sets the brightness value.

Parameters
a_fBrightnessNew brightness value (0.0-1.0)

Definition at line 614 of file TRenderInterface_DX8.cpp.

615{
616 TMath::Clip( a_fBrightness, 0.0f, 1.0f );
617 m_fBrightness = a_fBrightness;
618 m_bChangedColourSettings = TTRUE;
619}

◆ SetContrast()

void TRenderD3DInterface::SetContrast ( TFLOAT a_fConstrast)
virtual

Sets the contrast value.

Parameters
a_fConstrastNew contrast value (0.0-1.0)

Definition at line 606 of file TRenderInterface_DX8.cpp.

607{
608 TMath::Clip( a_fConstrast, 0.0f, 1.0f );
609 m_fContrast = a_fConstrast;
610 m_bChangedColourSettings = TTRUE;
611}

◆ SetDeviceDefaultStates()

void TRenderD3DInterface::SetDeviceDefaultStates ( )

Sets default device states.

Definition at line 734 of file TRenderInterface_DX8.cpp.

735{
736 // Enable Z-buffer
737 m_pDirectDevice->SetRenderState( D3DRS_ZENABLE, 1 );
738 // Set culling mode to counter-clockwise
739 m_pDirectDevice->SetRenderState( D3DRS_CULLMODE, 2 );
740 // Disable lighting
741 m_pDirectDevice->SetRenderState( D3DRS_LIGHTING, 0 );
742 // Set texture filtering to linear
743 m_pDirectDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, 2 );
744 m_pDirectDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, 2 );
745 m_pDirectDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, 2 );
746}

◆ SetGamma()

void TRenderD3DInterface::SetGamma ( TFLOAT a_fGamma)
virtual

Sets the gamma value.

Parameters
a_fGammaNew gamma value (0.0-1.0)

Definition at line 622 of file TRenderInterface_DX8.cpp.

623{
624 TMath::Clip( a_fGamma, 0.0f, 1.0f );
625 m_fGamma = a_fGamma;
626 m_bChangedColourSettings = TTRUE;
627}

◆ SetPixelAspectRatio()

TBOOL TRenderD3DInterface::SetPixelAspectRatio ( float a_fPixelAspectRatio)
virtual

Sets the pixel aspect ratio.

Parameters
a_fPixelAspectRatioThe new pixel aspect ratio
Returns
True if successful, false otherwise

Reimplemented from TRenderInterface.

Definition at line 474 of file TRenderInterface_DX8.cpp.

475{
476 m_fPixelAspectRatio = a_fPixelAspectRatio;
477 return TTRUE;
478}

◆ SetSaturate()

void TRenderD3DInterface::SetSaturate ( TFLOAT a_fSaturate)
virtual

Sets the saturation value.

Parameters
a_fSaturateNew saturation value (0.0-1.0)

Definition at line 630 of file TRenderInterface_DX8.cpp.

631{
632 TMath::Clip( a_fSaturate, 0.0f, 1.0f );
633 m_fSaturate = a_fSaturate;
634 m_bChangedColourSettings = TTRUE;
635}

◆ SetTextureAddress()

void TRenderD3DInterface::SetTextureAddress ( TINT a_iStage,
ADDRESSINGMODE a_eAddressing,
TEXCOORD a_eTextureCoordinate = TEXCOORD_UV )

Sets texture addressing mode.

Parameters
a_iStageTexture stage
a_eAddressingAddressing type
a_eTextureCoordinateTexture coordinate (U or V)

Definition at line 750 of file TRenderInterface_DX8.cpp.

751{
752 // Map texture addressing type to D3D address mode
753 DWORD addressMode;
754 switch ( a_eAddressing )
755 {
757 addressMode = D3DTADDRESS_WRAP;
758 break;
760 addressMode = D3DTADDRESS_MIRROR;
761 break;
763 addressMode = D3DTADDRESS_CLAMP;
764 break;
766 addressMode = D3DTADDRESS_BORDER;
767 break;
768 default:
769 TERROR( "TRenderD3DInterface::SetTextureAddress: Invalid addressing mode specified!\n" );
770 return;
771 }
772
773 // Set either U or V coordinate addressing
774 if ( a_eTextureCoordinate == TEXCOORD_U )
775 {
776 m_pDirectDevice->SetTextureStageState( a_iStage, D3DTSS_ADDRESSU, addressMode );
777 }
778 else if ( a_eTextureCoordinate == TEXCOORD_V )
779 {
780 m_pDirectDevice->SetTextureStageState( a_iStage, D3DTSS_ADDRESSV, addressMode );
781 }
782 else
783 {
784 TASSERT( a_eTextureCoordinate == TEXCOORD_UV );
785 m_pDirectDevice->SetTextureStageState( a_iStage, D3DTSS_ADDRESSU, addressMode );
786 m_pDirectDevice->SetTextureStageState( a_iStage, D3DTSS_ADDRESSV, addressMode );
787 }
788}
@ ADDRESSINGMODE_CLAMP
Definition TRender.h:42
@ ADDRESSINGMODE_WRAP
Definition TRender.h:40
@ ADDRESSINGMODE_MIRROR
Definition TRender.h:41
@ ADDRESSINGMODE_BORDER
Definition TRender.h:43
@ TEXCOORD_UV
Definition TRender.h:29
@ TEXCOORD_U
Definition TRender.h:30
@ TEXCOORD_V
Definition TRender.h:31
#define TERROR(...)
Definition Defines.h:153

◆ Supports32BitTextures()

TBOOL TRenderD3DInterface::Supports32BitTextures ( )
virtual

Checks if 32-bit textures are supported.

Returns
True if supported, false otherwise

Reimplemented from TRenderInterface.

Definition at line 855 of file TRenderInterface_DX8.cpp.

856{
858}
virtual TBOOL IsTextureFormatSupported(TINT a_eTextureFormat) OVERRIDE
Checks if a texture format is supported.

◆ Update()

TBOOL TRenderD3DInterface::Update ( float a_fDeltaTime)
virtual

Updates the render interface state.

Parameters
a_fDeltaTimeTime elapsed since last update
Returns
True if successful, false otherwise

Implements TRenderInterface.

Definition at line 246 of file TRenderInterface_DX8.cpp.

247{
249 m_Window.Update( a_fDeltaTime );
250
251 return !m_bExited;
252}

◆ UpdateColourSettings()

void TRenderD3DInterface::UpdateColourSettings ( )
virtual

Updates color correction settings.

Definition at line 662 of file TRenderInterface_DX8.cpp.

663{
664 if ( IsColourCorrection() )
665 {
667 m_pDirectDevice->SetGammaRamp( 0, &m_GammaRamp );
668 }
669}
virtual TBOOL IsColourCorrection()
Checks if color correction is enabled.
void GetCurrentColourRamp()
Gets the current color ramp.

Member Data Documentation

◆ ms_oClass

Definition at line 20 of file TRenderInterface_DX8.h.

◆ PARENTCLASS

Toshi::TClass* TRenderD3DInterface::PARENTCLASS = & TRenderInterface::ms_oClass
staticconstexpr

Definition at line 20 of file TRenderInterface_DX8.h.

◆ TMSWindow

friend TRenderD3DInterface::TMSWindow

Definition at line 22 of file TRenderInterface_DX8.h.


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