Skip to content

Commit

Permalink
Added TRenderD3D
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Dec 30, 2023
1 parent dd42076 commit 15e8af7
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Toshi/Include/TKernel/TNodeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class TOSHI_EXPORT TGenericNodeList
return *this;
}

protected:
public:
TBOOL IsEmpty() const
{
return m_oRoot.Next() == &m_oRoot;
Expand Down Expand Up @@ -329,6 +329,7 @@ class TNodeList : public TGenericNodeList
public:

TNodeList() { }

};

TOSHI_NAMESPACE_END
1 change: 1 addition & 0 deletions Toshi/Include/TKernel/TObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef TBOOL (*t_RecurceTreeBaseBeginCb)(class TClass*, TPCVOID);
typedef TBOOL (*t_RecurceTreeBaseEndCb)(class TClass*, TPCVOID);

#define TGetClass(X) X::m_sClass
#define TFindClass(X, Y) Toshi::TClass::Find(#X, Y)

class TOSHI_EXPORT TClass
{
Expand Down
12 changes: 12 additions & 0 deletions Toshi/Include/TRender/TNullResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "TResource.h"

TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TNullResource : public TResource
{
DECLARE_DYNAMIC(TNullResource)
};

TOSHI_NAMESPACE_END
15 changes: 15 additions & 0 deletions Toshi/Include/TRender/TRenderContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "TKernel/TObject.h"
#include "TKernel/TKernelInterface.h"

TOSHI_NAMESPACE_BEGIN

class TRenderInterface;

class TOSHI_EXPORT TRenderContext
{
private:
TRenderInterface* m_pRenderInterface; // 0x4
};

TOSHI_NAMESPACE_END
95 changes: 95 additions & 0 deletions Toshi/Include/TRender/TRenderInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#pragma once

#include "TKernel/TObject.h"
#include "TKernel/TKernelInterface.h"
#include "TRenderContext.h"
#include "TResource.h"

TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TRenderInterface : public TObject
{
DECLARE_DYNAMIC(TRenderInterface)

enum FLAG
{
FLAG_DIRTY = BITFIELD(0),
FLAG_FOG = BITFIELD(1),
FLAG_HAS_MODELWORLDMATRIX = BITFIELD(2),
FLAG_HAS_VIEWWORLDMATRIX = BITFIELD(3),
FLAG_UNK3 = BITFIELD(4),
FLAG_UNK4 = BITFIELD(5),
FLAG_HAS_WORLDPLANES = BITFIELD(6),
FLAG_UNK6 = BITFIELD(7),
FLAG_DIRTY_WORLDMODELMATRIX = BITFIELD(8),
FLAG_DIRTY_VIEWMODELMATRIX = BITFIELD(9),
};

enum SYSRESOURCES
{
SYSRESOURCE_VFACTORIES = 0,
SYSRESOURCE_VFSYSSVNDUV1 = 1,
SYSRESOURCE_VFSKIN = 2,
SYSRESOURCE_VFUNK1 = 3,
SYSRESOURCE_VFUNK2 = 4,
SYSRESOURCE_IFACTORIES = 5,
SYSRESOURCE_IFSYS = 6,
SYSRESOURCE_SHADERS = 7,
SYSRESOURCE_SHSYS = 8,
SYSRESOURCE_SHSKIN = 9,
SYSRESOURCE_SHUNK1 = 10,
SYSRESOURCE_SHLINE = 11,
SYSRESOURCE_STORAGE = 12,
SYSRESOURCE_MESHES = 13,
SYSRESOURCE_TEXTURES = 14,
SYSRESOURCE_SOUNDS = 15,
SYSRESOURCE_GFX = 16,
SYSRESOURCE_SCENE = 17,
SYSRESOURCE_TEXTUREFACTORY = 18,
SYSRESOURCES_NUMOF = 19
};

public:

TRenderInterface();

virtual TBOOL Create(TKernelInterface* pKernelInterface);

protected:

virtual TBOOL CreateSystemResources();

public:

TResource* CreateResource(const TClass* a_pClass, TPCCHAR a_szResName, TResource* a_pResource);

TResource* GetSystemResource(SYSRESOURCES a_SystemResource)
{
TASSERT(a_SystemResource < TRenderInterface::SYSRESOURCES_NUMOF);
TASSERT(m_aSysResources[a_SystemResource]!=TNULL);
return m_aSysResources[a_SystemResource];
}

TRenderContext* SetCurrentRenderContext(TRenderContext* a_pRenderContext)
{
TRenderContext* pLastRenderContext = m_pCurrentRenderContext;
m_pCurrentRenderContext = a_pRenderContext;
return pLastRenderContext;
}

TBOOL IsCreated() { return m_bIsCreated; }

private:

static TRenderInterface* s_Interface;

TBOOL m_bIsCreated; // 0x9
TRenderContext* m_pCurrentRenderContext; // 0x1C
TRenderContext* m_pDefaultRenderContext; // 0x20
TKernelInterface* m_pKernel; // 0x24
TResource* m_aSysResources[SYSRESOURCES_NUMOF]; // 0x28
TINT m_iResourceCount; // 0x124
TNodeTree<TResource> m_Resources; // 0x128
};

TOSHI_NAMESPACE_END
10 changes: 9 additions & 1 deletion Toshi/Include/TRender/TResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

TOSHI_NAMESPACE_BEGIN

class TRenderInterface;

class TOSHI_EXPORT TResource : public TObject, public TNodeTree<TResource>::TNode
{
DECLARE_DYNAMIC(TResource)
Expand All @@ -24,19 +26,25 @@ class TOSHI_EXPORT TResource : public TObject, public TNodeTree<TResource>::TNod

TResource()
{
m_pRenderer = TNULL;
*m_szName = 0;
m_iState = 0;
m_uiUId = 0;
}

virtual TBOOL Create();

void SetParent(TResource *a_pParent);
void SetName(TPCCHAR a_strName);

TBOOL IsDying() { return HASFLAG(m_iState & TResourceState_Dying); }
TBOOL IsCreated() { return HASFLAG(m_iState & TResourceState_Created); }

TUINT GetUId() const { return m_uiUId; }
TPCCHAR GetName() const { return m_szName; }

private:
public:
TRenderInterface* m_pRenderer; // 0x18
TCHAR m_szName[MAXNAMELEN]; // 0x1C
TINT8 m_iState; // 0x2B
TUINT m_uiUId; // 0x2C
Expand Down
68 changes: 68 additions & 0 deletions Toshi/Include/TRender/TTextureFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#include "TKernel/TObject.h"
#include "TRenderInterface.h"
#include "TKernel/TNodeList.h"
#include "TKernel/TSystemTools.h"

TOSHI_NAMESPACE_BEGIN

class TTextureResource;

class TOSHI_EXPORT TTextureFactory : public TResource
{
DECLARE_DYNAMIC(TTextureFactory)

public:
class NameEntry : public TNodeList<NameEntry>::TNode
{
public:
NameEntry(TPCCHAR a_szName, TTextureResource* a_pTexture)
{
m_pTexture = a_pTexture;

if (TSystem::StringLength(a_szName) < MAX_TEXTURENAMELEN) {
TSystem::StringCopy(m_szName, a_szName, MAX_TEXTURENAMELEN);
}
else {
TASSERT(1 < MAX_TEXTURENAMELEN);
*m_szName = '\0';
}
}
~NameEntry()
{
TASSERT(IsLinked()==TFALSE);
}

TPCCHAR GetName() const { return m_szName; }
TTextureResource* GetTexture() { return m_pTexture; }

private:

static constexpr TUINT32 MAX_TEXTURENAMELEN = 50;

TCHAR m_szName[MAX_TEXTURENAMELEN];
TTextureResource* m_pTexture;
};

public:

static TTextureFactory* TOSHI_API CreateHAL(TRenderInterface* a_pRenderer, TPCCHAR a_szName, TResource* a_pResource)
{
return (TTextureFactory*)a_pRenderer->CreateResource(TClass::Find("TTextureFactoryHAL", TNULL), a_szName, a_pResource);
}

protected:

TUINT HashName(TPCCHAR a_szName);

TTextureFactory::NameEntry* RegisterTexture(TPCCHAR a_szName, TTextureResource* a_pResource);

private:

static constexpr TUINT32 NUM_LISTS = 1024;

TNodeList<NameEntry> m_aLists[NUM_LISTS];
};

TOSHI_NAMESPACE_END
9 changes: 9 additions & 0 deletions Toshi/Include/TRender/TTextureResource.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#pragma once

#include "TKernel/TDebug.h"
#include "TTextureFactory.h"

TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TTextureResource
{

friend class TTextureFactory;

public:

TTextureFactory::NameEntry* GetNameEntry() { return m_pNameEntry; }

private:
TTextureFactory::NameEntry* m_pNameEntry;
};

TOSHI_NAMESPACE_END
46 changes: 46 additions & 0 deletions Toshi/Include/TRender/TVertexFactoryResourceInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
#include "TResource.h"

TOSHI_NAMESPACE_BEGIN

struct TVertexStreamFormat
{
TUSHORT m_uiUnk = 0;
TUSHORT m_uiVertexSize = 0;
TUINT m_Unk = 0;
};

class TVertexFactoryFormat
{
public:
static constexpr TUINT MAX_NUM_STREAMS = 8;

TUINT m_uiNumStreams = 0;
TVertexStreamFormat m_aStreamFormats[MAX_NUM_STREAMS];

TUINT GetNumStreams() const { return m_uiNumStreams; }
};

class TVertexPoolResourceInterface;

class TOSHI_EXPORT TVertexFactoryResourceInterface : public TResource
{
DECLARE_DYNAMIC(TVertexFactoryResourceInterface)
public:
TVertexFactoryResourceInterface();

virtual TBOOL Create(TVertexFactoryFormat* a_pVertexFormat, TUSHORT a_uiMaxStaticVertices, TUINT a_uiFlags);
virtual TVertexPoolResourceInterface* CreatePool(TUSHORT a_usMaxStaticVertices, TUINT a_uiFlags);

TVertexFactoryFormat* GetVertexFormat() { return &m_oVertexFormat; }
TUSHORT GetMaxStaticVertices() { return m_usMaxStaticVertices; }
TUINT GetFlags() { return m_uiFlags; }

private:
TUINT m_uiNumCreatedVertexPools; // 0x30
TVertexFactoryFormat m_oVertexFormat; // 0x34
TUINT m_usMaxStaticVertices; // 0x78
TUINT m_uiFlags; // 0x7C
};

TOSHI_NAMESPACE_END
16 changes: 16 additions & 0 deletions Toshi/Include/TRenderD3D/TTextureFactoryHAL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "TRender/TResource.h"
#include "TRender/TTextureResource.h"

TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TTextureFactoryHAL
{
public:

virtual TTextureResource* CreateEx(TPVOID);

};

TOSHI_NAMESPACE_END
5 changes: 5 additions & 0 deletions Toshi/Source/TRender/TNullResource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "TNullResource.h"

TOSHI_NAMESPACE_USING

IMPLEMENT_DYNAMIC(TNullResource, TResource)
Loading

0 comments on commit 15e8af7

Please sign in to comment.