Skip to content

Commit

Permalink
fix resource assert (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw authored Feb 28, 2024
1 parent 8170d50 commit 6d6d21f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Log/Log.h"
#include "Math/Box.hpp"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"
#include "Scene/Mesh.h"
#include "Scene/VertexFormat.h"
#include "U_AtmophericScattering.sh"
Expand Down Expand Up @@ -145,6 +146,13 @@ void PBRSkyRenderer::Render(float deltaTime)
return;
}

const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
return;
}

bgfx::setImage(ATM_TRANSMITTANCE_SLOT, GetRenderContext()->GetTexture(StringCrc(TextureTransmittance)), 0, bgfx::Access::Read, bgfx::TextureFormat::RGBA32F);
bgfx::setImage(ATM_IRRADIANCE_SLOT, GetRenderContext()->GetTexture(StringCrc(TextureIrradiance)), 0, bgfx::Access::Read, bgfx::TextureFormat::RGBA32F);
bgfx::setImage(ATM_SCATTERING_SLOT, GetRenderContext()->GetTexture(StringCrc(TextureScattering)), 0, bgfx::Access::Read, bgfx::TextureFormat::RGBA32F);
Expand Down
7 changes: 1 addition & 6 deletions Engine/Source/Runtime/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ void Renderer::ScreenSpaceQuad(const RenderTarget* pRenderTarget, bool _originBo
void Renderer::SubmitStaticMeshDrawCall(StaticMeshComponent* pMeshComponent, uint16_t viewID, const std::string& programName, const std::string& featuresCombine)
{
const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
return;
}

assert(ResourceStatus::Ready == pMeshResource->GetStatus() || ResourceStatus::Optimized == pMeshResource->GetStatus());
bgfx::setVertexBuffer(0, bgfx::VertexBufferHandle{ pMeshResource->GetVertexBufferHandle() }, pMeshComponent->GetStartVertex(), pMeshComponent->GetVertexCount());
for (uint32_t indexBufferIndex = 0U, indexBufferCount = pMeshResource->GetIndexBufferCount(); indexBufferIndex < indexBufferCount; ++indexBufferIndex)
{
Expand Down
23 changes: 22 additions & 1 deletion Engine/Source/Runtime/Rendering/ShadowMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "LightUniforms.h"
#include "Material/ShaderSchema.h"
#include "Math/Transform.hpp"
#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"

#include <string>

Expand Down Expand Up @@ -237,11 +238,19 @@ void ShadowMapRenderer::Render(float deltaTime)
{
continue;
}
const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

BlendShapeComponent* pBlendShapeComponent = m_pCurrentSceneWorld->GetBlendShapeComponent(entity);
if (pBlendShapeComponent)
{
continue;
}

// Transform
if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
{
Expand Down Expand Up @@ -314,6 +323,12 @@ void ShadowMapRenderer::Render(float deltaTime)
{
continue;
}
const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

// Transform
if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
Expand Down Expand Up @@ -368,6 +383,12 @@ void ShadowMapRenderer::Render(float deltaTime)
{
continue;
}
const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

BlendShapeComponent* pBlendShapeComponent = m_pCurrentSceneWorld->GetBlendShapeComponent(entity);
if (pBlendShapeComponent)
Expand Down
8 changes: 8 additions & 0 deletions Engine/Source/Runtime/Rendering/SkyboxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ECWorld/SceneWorld.h"
#include "ECWorld/SkyComponent.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"

namespace engine
{
Expand Down Expand Up @@ -71,6 +72,13 @@ void SkyboxRenderer::Render(float deltaTime)
return;
}

const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
return;
}

// Create a new TextureHandle each frame if the skybox texture path has been updated,
// otherwise RenderContext::CreateTexture will automatically skip it.
SkyComponent* pSkyComponent = m_pCurrentSceneWorld->GetSkyComponent(m_pCurrentSceneWorld->GetSkyEntity());
Expand Down
8 changes: 8 additions & 0 deletions Engine/Source/Runtime/Rendering/TerrainRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Material/ShaderSchema.h"
#include "Math/Transform.hpp"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"
#include "Scene/Texture.h"
#include "U_IBL.sh"
#include "U_Terrain.sh"
Expand Down Expand Up @@ -123,6 +124,13 @@ void TerrainRenderer::Render(float deltaTime)
continue;
}

const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

// Transform
if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
{
Expand Down
20 changes: 14 additions & 6 deletions Engine/Source/Runtime/Rendering/WhiteModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"
#include "Scene/Texture.h"

namespace engine
Expand Down Expand Up @@ -44,18 +45,25 @@ void WhiteModelRenderer::Render(float deltaTime)
continue;
}

if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
{
pTransformComponent->Build();
bgfx::setTransform(pTransformComponent->GetWorldMatrix().begin());
}

StaticMeshComponent* pMeshComponent = m_pCurrentSceneWorld->GetStaticMeshComponent(entity);
if (!pMeshComponent)
{
continue;
}

const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
{
pTransformComponent->Build();
bgfx::setTransform(pTransformComponent->GetWorldMatrix().begin());
}

constexpr uint64_t state = BGFX_STATE_WRITE_MASK | BGFX_STATE_MSAA | BGFX_STATE_DEPTH_TEST_LESS |
BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
bgfx::setState(state);
Expand Down
18 changes: 13 additions & 5 deletions Engine/Source/Runtime/Rendering/WireframeRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Resources/MeshResource.h"
#include "Scene/Texture.h"

#undef EDITOR_MODE
Expand Down Expand Up @@ -51,18 +52,25 @@ void WireframeRenderer::Render(float deltaTime)
continue;
}

if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
StaticMeshComponent* pMeshComponent = m_pCurrentSceneWorld->GetStaticMeshComponent(entity);
if (!pMeshComponent)
{
pTransformComponent->Build();
bgfx::setTransform(pTransformComponent->GetWorldMatrix().begin());
continue;
}

StaticMeshComponent* pMeshComponent = m_pCurrentSceneWorld->GetStaticMeshComponent(entity);
if (!pMeshComponent)
const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

if (TransformComponent* pTransformComponent = m_pCurrentSceneWorld->GetTransformComponent(entity))
{
pTransformComponent->Build();
bgfx::setTransform(pTransformComponent->GetWorldMatrix().begin());
}

constexpr uint64_t state = BGFX_STATE_WRITE_MASK | BGFX_STATE_MSAA | BGFX_STATE_DEPTH_TEST_LEQUAL |
BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) | BGFX_STATE_PT_LINES;
bgfx::setState(state);
Expand Down
7 changes: 7 additions & 0 deletions Engine/Source/Runtime/Rendering/WorldRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ void WorldRenderer::Render(float deltaTime)
continue;
}

const MeshResource* pMeshResource = pMeshComponent->GetMeshResource();
if (ResourceStatus::Ready != pMeshResource->GetStatus() &&
ResourceStatus::Optimized != pMeshResource->GetStatus())
{
continue;
}

BlendShapeComponent* pBlendShapeComponent = m_pCurrentSceneWorld->GetBlendShapeComponent(entity);

// SkinMesh
Expand Down

0 comments on commit 6d6d21f

Please sign in to comment.