added material rendering
This commit is contained in:
@@ -95,10 +95,17 @@ public:
|
||||
uint32_t LoadShader( const char *szName );
|
||||
IShader **GetShaderByIndex( uint32_t hShader );
|
||||
void UnrefShader( uint32_t hShader );
|
||||
|
||||
virtual HFunnyTexture LoadTexture( const char *szName ) override;
|
||||
virtual FunnyTexture_t *GetTextureByIndex( HFunnyTexture hTexture ) override;
|
||||
virtual void UnrefTexture( HFunnyTexture hTexture ) override;
|
||||
|
||||
void LoadMaterialData( CBaseMaterial *pMaterial, IJSONObject *pObj );
|
||||
|
||||
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||
CAssetArc<FunnyMesh_t, MAX_MESH_COUNT> m_meshes = {};
|
||||
CAssetArc<FunnyMaterial_t, MAX_MATERIAL_COUNT> m_materials = {};
|
||||
CAssetArc<FunnyTexture_t, MAX_TEXTURE_COUNT> m_textures = {};
|
||||
CAssetArc<IShader*, MAX_SHADER_COUNT> m_shaders = {};
|
||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||
|
||||
@@ -162,6 +169,7 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
||||
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
||||
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||
V_printf("%s\n", pMaterial->GetStringValue());
|
||||
if (pMesh)
|
||||
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
||||
if (pMaterial)
|
||||
@@ -184,6 +192,48 @@ void CAssetManager::UnrefModel( uint32_t uIndex )
|
||||
|
||||
}
|
||||
|
||||
void CAssetManager::LoadMaterialData( CBaseMaterial *pMaterial, IJSONObject *pObj )
|
||||
{
|
||||
for ( int i = 0; i < pMaterial->GetDataMap()->m_iNumFields; i++ )
|
||||
{
|
||||
typedescription_t desc = pMaterial->GetDataMap()->m_pData[i];
|
||||
IJSONValue *pValue = pObj->GetValue(desc.m_szEditorName);
|
||||
switch ( desc.m_eFieldType )
|
||||
{
|
||||
case FIELD_SHADER_TEXTURE:
|
||||
{
|
||||
FMat::XMTexture *texture = (FMat::XMTexture*)((char*)pMaterial+desc.m_iFieldOffset);
|
||||
if ( pValue->GetType()
|
||||
== JSON_PARAMETER_STRING )
|
||||
*texture = GetTextureByIndex(LoadTexture(pValue->GetStringValue()))->m_hTexture;
|
||||
break;
|
||||
}
|
||||
case FIELD_SHADER_COLOR_FLOAT4:
|
||||
{
|
||||
FMat::XMFLOAT4 *data = (FMat::XMFLOAT4*)((char*)pMaterial+desc.m_iFieldOffset);
|
||||
if ( pValue->GetArray()->GetParameter(0)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
data->x = pValue->GetArray()->GetParameter(0)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(1)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
data->y = pValue->GetArray()->GetParameter(1)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(2)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
data->z = pValue->GetArray()->GetParameter(2)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(3)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
data->w = pValue->GetArray()->GetParameter(3)->GetNumberValue();
|
||||
V_printf("%s %f %f %f %f\n", desc.m_szEditorName, data->x, data->y, data->z, data->w);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||
{
|
||||
@@ -205,31 +255,32 @@ uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_OBJECT:
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pShaderValue = pMainObject->GetValue("shader");
|
||||
CUtlString szShader = pShaderValue->GetStringValue();
|
||||
CBaseMaterial *pRenderMaterial = CreateMaterial(szShader);
|
||||
}
|
||||
IJSONValue *pShaderValue = pMainObject->GetValue("shader");
|
||||
CUtlString szShader = pShaderValue->GetStringValue();
|
||||
CBaseMaterial *pRenderMaterial = CreateMaterial(szShader);
|
||||
LoadMaterialData(pRenderMaterial, pMainObject);
|
||||
|
||||
uint32_t uShaderId = LoadShader(pRenderMaterial->GetShaderPath());
|
||||
if (!uShaderId)
|
||||
return 0;
|
||||
uint32_t uShaderId = LoadShader(pRenderMaterial->GetShaderPath());
|
||||
if (!uShaderId)
|
||||
return 0;
|
||||
|
||||
IShader **ppShader = GetShaderByIndex(uShaderId);
|
||||
IShader **ppShader = GetShaderByIndex(uShaderId);
|
||||
|
||||
pMaterial->m_pShaders = *ppShader;
|
||||
pMaterial->m_pMaterial = g_pRenderContext->CreateMaterial(*ppShader);
|
||||
pMaterial->m_pLayout = pRenderMaterial;
|
||||
pMaterial->m_pShaders = *ppShader;
|
||||
pMaterial->m_pMaterial = g_pRenderContext->CreateMaterial(*ppShader);
|
||||
pMaterial->m_pLayout = pRenderMaterial;
|
||||
|
||||
return hMaterial;
|
||||
}
|
||||
break;
|
||||
return hMaterial;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -301,6 +352,36 @@ void CAssetManager::UnrefShader( uint32_t uIndex )
|
||||
m_shaders.UnrefObject(uIndex);
|
||||
}
|
||||
|
||||
HFunnyTexture CAssetManager::LoadTexture( const char *szName )
|
||||
{
|
||||
bool bHasBeenCreated = false;
|
||||
uint32_t hTexture = m_textures.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||
if (!bHasBeenCreated)
|
||||
return hTexture;
|
||||
FunnyTexture_t *pTexture = m_textures.GetObjectPtr(hTexture);
|
||||
|
||||
|
||||
uint32_t hTex = g_pWorldRenderer->GetTextures()->LoadTexture(szName);
|
||||
if ( hTex == 0 )
|
||||
{
|
||||
V_printf("Failed to load %s\n", szName);
|
||||
m_textures.UnrefObject(hTexture);
|
||||
return 0;
|
||||
}
|
||||
pTexture->m_hTexture = hTex;
|
||||
return hTexture;
|
||||
}
|
||||
|
||||
FunnyTexture_t *CAssetManager::GetTextureByIndex( HFunnyTexture hTexture )
|
||||
{
|
||||
return m_textures.GetObjectPtr(hTexture);
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefTexture( uint32_t hTexture )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
{
|
||||
@@ -354,6 +435,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
return hPhysics;
|
||||
}
|
||||
|
||||
|
||||
FunnyPhysics_t *CAssetManager::GetPhysicsByIndex( HFunnyPhysics hPhysics )
|
||||
{
|
||||
return m_physics.GetObjectPtr(hPhysics);
|
||||
|
||||
Reference in New Issue
Block a user