|
|
|
|
@@ -59,8 +59,8 @@ public:
|
|
|
|
|
virtual void Frame();
|
|
|
|
|
|
|
|
|
|
PerMeshData_t m_data = {};
|
|
|
|
|
Quat m_vRotation = {};
|
|
|
|
|
Vector m_vPosition = {};
|
|
|
|
|
Quat m_vRotation = { 0, 0, 0, 1 };
|
|
|
|
|
Vector m_vPosition = { 0, 0, 0};
|
|
|
|
|
Vector m_vScale = { 1, 1, 1 };
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
@@ -105,6 +105,12 @@ void CFunnyMeshInstance::Frame()
|
|
|
|
|
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
|
|
|
|
|
|
|
|
|
m_data.m_uAlbedo = 1;
|
|
|
|
|
/*
|
|
|
|
|
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[0][0], m_data.m_matTranslation[0][1], m_data.m_matTranslation[0][2], m_data.m_matTranslation[0][3]);
|
|
|
|
|
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[1][0], m_data.m_matTranslation[1][1], m_data.m_matTranslation[1][2], m_data.m_matTranslation[1][3]);
|
|
|
|
|
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[2][0], m_data.m_matTranslation[2][1], m_data.m_matTranslation[2][2], m_data.m_matTranslation[2][3]);
|
|
|
|
|
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[3][0], m_data.m_matTranslation[3][1], m_data.m_matTranslation[3][2], m_data.m_matTranslation[3][3]);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -222,7 +228,7 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
|
|
|
|
glm_mat4_identity(matCamera);
|
|
|
|
|
glm_mat4_identity(matCamera2);
|
|
|
|
|
glm_translate(matCamera2, m_vPos);
|
|
|
|
|
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
|
|
|
|
glm_perspective(glm_rad(75), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
|
|
|
|
glm_mul(matCamera, matCamera2, matCamera);
|
|
|
|
|
m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
|
|
|
|
|
m_pViewBuffer->Lock();
|
|
|
|
|
@@ -278,38 +284,44 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
|
|
|
|
m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight);
|
|
|
|
|
m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0);
|
|
|
|
|
m_pRasterCommandList->SetClearDepth(1);
|
|
|
|
|
uint32_t uTotalMeshes = 0;
|
|
|
|
|
uint32_t u = 0;
|
|
|
|
|
for ( auto mesh: m_pMeshes)
|
|
|
|
|
{
|
|
|
|
|
uTotalMeshes+=mesh->m_instances.GetSize();
|
|
|
|
|
}
|
|
|
|
|
if (!uTotalMeshes)
|
|
|
|
|
return;
|
|
|
|
|
IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(uTotalMeshes*sizeof(PerMeshData_t));
|
|
|
|
|
pDataBuffer->Lock();
|
|
|
|
|
void *pData = pDataBuffer->Map();
|
|
|
|
|
for ( auto mesh: m_pMeshes)
|
|
|
|
|
{
|
|
|
|
|
if (mesh->m_instances.GetSize()==0)
|
|
|
|
|
continue;
|
|
|
|
|
CUtlVector<PerMeshData_t> data = {};
|
|
|
|
|
data.Reserve(mesh->m_instances.GetSize());
|
|
|
|
|
for ( auto instance: mesh->m_instances )
|
|
|
|
|
{
|
|
|
|
|
instance->Frame();
|
|
|
|
|
data.AppendTail(instance->m_data);
|
|
|
|
|
}
|
|
|
|
|
IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(data.GetSize()*sizeof(PerMeshData_t));
|
|
|
|
|
pDataBuffer->Lock();
|
|
|
|
|
void *pData = pDataBuffer->Map();
|
|
|
|
|
for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ )
|
|
|
|
|
{
|
|
|
|
|
V_memcpy(&((PerMeshData_t*)pData)[i], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t));
|
|
|
|
|
mesh->m_instances[i]->Frame();
|
|
|
|
|
V_memcpy(&((PerMeshData_t*)pData)[i+u], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t));
|
|
|
|
|
}
|
|
|
|
|
pDataBuffer->Unmap();
|
|
|
|
|
pDataBuffer->Unlock();
|
|
|
|
|
m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer);
|
|
|
|
|
m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer);
|
|
|
|
|
m_pRasterMaterial->PSSetTextureArray(1, m_pTextures);
|
|
|
|
|
g_pRenderContext->DestroyBuffer(pDataBuffer);
|
|
|
|
|
u+=mesh->m_instances.GetSize();
|
|
|
|
|
}
|
|
|
|
|
pDataBuffer->Unmap();
|
|
|
|
|
pDataBuffer->Unlock();
|
|
|
|
|
g_pRenderContext->DestroyBuffer(pDataBuffer);
|
|
|
|
|
m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer);
|
|
|
|
|
m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer);
|
|
|
|
|
m_pRasterMaterial->PSSetTextureArray(1, m_pTextures);
|
|
|
|
|
|
|
|
|
|
m_pRasterCommandList->SetMaterial(m_pRasterMaterial);
|
|
|
|
|
u = 0;
|
|
|
|
|
for ( auto mesh: m_pMeshes)
|
|
|
|
|
{
|
|
|
|
|
if (mesh->m_instances.GetSize()==0)
|
|
|
|
|
continue;
|
|
|
|
|
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
|
|
|
|
|
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), 0);
|
|
|
|
|
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), u);
|
|
|
|
|
u += mesh->m_instances.GetSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pRasterCommandList->ResolveImage(m_pOutputImage, m_pResolvedOutputImage);
|
|
|
|
|
|