Refactor enum flags with __underlying_type and new EnumHasAnyFlags/EnumHasAllFlags
Fixes #832 Closes #886
This commit is contained in:
@@ -730,7 +730,7 @@ void AnimatedModel::Draw(RenderContext& renderContext)
|
||||
draw.World = &world;
|
||||
draw.DrawState = &_drawState;
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
draw.DrawModes = (DrawPass)(DrawModes & renderContext.View.GetShadowsDrawPassMask(ShadowsMode));
|
||||
draw.DrawModes = DrawModes & renderContext.View.GetShadowsDrawPassMask(ShadowsMode);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
draw.Bounds = _sphere;
|
||||
draw.Bounds.Center -= renderContext.View.Origin;
|
||||
@@ -785,7 +785,7 @@ void AnimatedModel::Draw(RenderContextBatch& renderContextBatch)
|
||||
// TODO: maybe deserialize ShadowsMode into ModelInstanceBuffer entries options?
|
||||
for (auto& e : renderContextBatch.Contexts)
|
||||
{
|
||||
draw.DrawModes = (DrawPass)(DrawModes & e.View.GetShadowsDrawPassMask(ShadowsMode));
|
||||
draw.DrawModes = DrawModes & e.View.GetShadowsDrawPassMask(ShadowsMode);
|
||||
SkinnedModel->Draw(e, draw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ bool Camera::HasContentLoaded() const
|
||||
|
||||
void Camera::Draw(RenderContext& renderContext)
|
||||
{
|
||||
if (renderContext.View.Flags & ViewFlags::EditorSprites
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::EditorSprites)
|
||||
&& _previewModel
|
||||
&& _previewModel->IsLoaded())
|
||||
{
|
||||
@@ -291,7 +291,7 @@ void Camera::Draw(RenderContext& renderContext)
|
||||
draw.Lightmap = nullptr;
|
||||
draw.LightmapUVs = nullptr;
|
||||
draw.Flags = StaticFlags::Transform;
|
||||
draw.DrawModes = (DrawPass)((DrawPass::Depth | DrawPass::GBuffer | DrawPass::Forward) & renderContext.View.Pass);
|
||||
draw.DrawModes = (DrawPass::Depth | DrawPass::GBuffer | DrawPass::Forward) & renderContext.View.Pass;
|
||||
BoundingSphere::FromBox(_previewModelBox, draw.Bounds);
|
||||
draw.Bounds.Center -= renderContext.View.Origin;
|
||||
draw.PerInstanceRandom = GetPerInstanceRandom();
|
||||
|
||||
@@ -69,8 +69,8 @@ void Decal::OnLayerChanged()
|
||||
|
||||
void Decal::Draw(RenderContext& renderContext)
|
||||
{
|
||||
if ((renderContext.View.Flags & ViewFlags::Decals) != 0 &&
|
||||
renderContext.View.Pass & DrawPass::GBuffer &&
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Decals) &&
|
||||
EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer) &&
|
||||
Material &&
|
||||
Material->IsLoaded() &&
|
||||
Material->IsDecal())
|
||||
|
||||
@@ -20,8 +20,8 @@ void DirectionalLight::Draw(RenderContext& renderContext)
|
||||
AdjustBrightness(renderContext.View, brightness);
|
||||
const Float3 position = GetPosition() - renderContext.View.Origin;
|
||||
if (Brightness > ZeroTolerance
|
||||
&& (renderContext.View.Flags & ViewFlags::DirectionalLights) != 0
|
||||
&& renderContext.View.Pass & DrawPass::GBuffer
|
||||
&& EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::DirectionalLights)
|
||||
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
|
||||
&& (ViewDistance < ZeroTolerance || Float3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
|
||||
{
|
||||
RendererDirectionalLightData data;
|
||||
|
||||
@@ -178,8 +178,8 @@ void EnvironmentProbe::UpdateBounds()
|
||||
void EnvironmentProbe::Draw(RenderContext& renderContext)
|
||||
{
|
||||
if (Brightness > ZeroTolerance &&
|
||||
(renderContext.View.Flags & ViewFlags::Reflections) != 0 &&
|
||||
renderContext.View.Pass & DrawPass::GBuffer)
|
||||
EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Reflections) &&
|
||||
EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer))
|
||||
{
|
||||
if (UpdateMode == ProbeUpdateMode::Realtime)
|
||||
ProbesRenderer::Bake(this, 0.0f);
|
||||
|
||||
@@ -35,8 +35,8 @@ void ExponentialHeightFog::Draw(RenderContext& renderContext)
|
||||
{
|
||||
// Render only when shader is valid and fog can be rendered
|
||||
// Do not render exponential fog in orthographic views
|
||||
if ((renderContext.View.Flags & ViewFlags::Fog) != 0
|
||||
&& renderContext.View.Pass & DrawPass::GBuffer
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Fog)
|
||||
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
|
||||
&& _shader
|
||||
&& _shader->IsLoaded()
|
||||
&& renderContext.View.IsPerspectiveProjection())
|
||||
|
||||
@@ -83,9 +83,9 @@ void PointLight::Draw(RenderContext& renderContext)
|
||||
AdjustBrightness(renderContext.View, brightness);
|
||||
const Float3 position = GetPosition() - renderContext.View.Origin;
|
||||
const float radius = GetScaledRadius();
|
||||
if ((renderContext.View.Flags & ViewFlags::PointLights) != 0
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::PointLights)
|
||||
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
|
||||
&& brightness > ZeroTolerance
|
||||
&& renderContext.View.Pass & DrawPass::GBuffer
|
||||
&& radius > ZeroTolerance
|
||||
&& (ViewDistance < ZeroTolerance || Vector3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ void Sky::DrawFog(GPUContext* context, RenderContext& renderContext, GPUTextureV
|
||||
data.ViewOffset = renderContext.View.Origin + GetPosition();
|
||||
InitConfig(data.Fog);
|
||||
data.Fog.AtmosphericFogSunPower *= SunLight ? SunLight->Brightness : 1.0f;
|
||||
bool useSpecularLight = (renderContext.View.Flags & ViewFlags::SpecularLight) != 0;
|
||||
bool useSpecularLight = EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SpecularLight);
|
||||
if (!useSpecularLight)
|
||||
{
|
||||
data.Fog.AtmosphericFogSunDiscScale = 0;
|
||||
@@ -223,7 +223,7 @@ void Sky::ApplySky(GPUContext* context, RenderContext& renderContext, const Matr
|
||||
data.ViewOffset = renderContext.View.Origin + GetPosition();
|
||||
InitConfig(data.Fog);
|
||||
//data.Fog.AtmosphericFogSunPower *= SunLight ? SunLight->Brightness : 1.0f;
|
||||
bool useSpecularLight = (renderContext.View.Flags & ViewFlags::SpecularLight) != 0;
|
||||
bool useSpecularLight = EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SpecularLight);
|
||||
if (!useSpecularLight)
|
||||
{
|
||||
// Hide sun disc if specular light is disabled
|
||||
|
||||
@@ -106,8 +106,8 @@ void SkyLight::Draw(RenderContext& renderContext)
|
||||
float brightness = Brightness;
|
||||
AdjustBrightness(renderContext.View, brightness);
|
||||
const Float3 position = GetPosition() - renderContext.View.Origin;
|
||||
if ((renderContext.View.Flags & ViewFlags::SkyLights) != 0
|
||||
&& renderContext.View.Pass & DrawPass::GBuffer
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SkyLights)
|
||||
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
|
||||
&& brightness > ZeroTolerance
|
||||
&& (ViewDistance < ZeroTolerance || Vector3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ void Skybox::Draw(RenderContext& renderContext)
|
||||
bool isReady;
|
||||
if (CustomMaterial)
|
||||
{
|
||||
isReady = CustomMaterial->IsLoaded() && CustomMaterial->IsSurface() && CustomMaterial->GetDrawModes() & DrawPass::GBuffer;
|
||||
isReady = CustomMaterial->IsLoaded() && CustomMaterial->IsSurface() && EnumHasAnyFlags(CustomMaterial->GetDrawModes(), DrawPass::GBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -348,7 +348,7 @@ bool SplineModel::HasContentLoaded() const
|
||||
|
||||
void SplineModel::Draw(RenderContext& renderContext)
|
||||
{
|
||||
const DrawPass actorDrawModes = (DrawPass)(DrawModes & renderContext.View.Pass);
|
||||
const DrawPass actorDrawModes = DrawModes & renderContext.View.Pass;
|
||||
if (!_spline || !Model || !Model->IsLoaded() || !Model->CanBeRendered() || actorDrawModes == DrawPass::None)
|
||||
return;
|
||||
auto model = Model.Get();
|
||||
@@ -428,8 +428,8 @@ void SplineModel::Draw(RenderContext& renderContext)
|
||||
continue;
|
||||
|
||||
// Check if skip rendering
|
||||
const auto shadowsMode = static_cast<ShadowsCastingMode>(entry.ShadowsMode & slot.ShadowsMode);
|
||||
const auto drawModes = static_cast<DrawPass>(actorDrawModes & renderContext.View.GetShadowsDrawPassMask(shadowsMode) & (uint32)material->GetDrawModes());
|
||||
const auto shadowsMode = entry.ShadowsMode & slot.ShadowsMode;
|
||||
const auto drawModes = actorDrawModes & renderContext.View.GetShadowsDrawPassMask(shadowsMode) & material->GetDrawModes();
|
||||
if (drawModes == DrawPass::None)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -132,8 +132,8 @@ void SpotLight::Draw(RenderContext& renderContext)
|
||||
const Float3 position = GetPosition() - renderContext.View.Origin;
|
||||
const float radius = GetScaledRadius();
|
||||
const float outerConeAngle = GetOuterConeAngle();
|
||||
if ((renderContext.View.Flags & ViewFlags::SpotLights) != 0
|
||||
&& renderContext.View.Pass & DrawPass::GBuffer
|
||||
if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SpotLights)
|
||||
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
|
||||
&& brightness > ZeroTolerance
|
||||
&& radius > ZeroTolerance
|
||||
&& outerConeAngle > ZeroTolerance
|
||||
|
||||
@@ -262,13 +262,13 @@ void StaticModel::Draw(RenderContext& renderContext)
|
||||
return;
|
||||
if (renderContext.View.Pass == DrawPass::GlobalSDF)
|
||||
{
|
||||
if (DrawModes & DrawPass::GlobalSDF)
|
||||
if (EnumHasAnyFlags(DrawModes, DrawPass::GlobalSDF))
|
||||
GlobalSignDistanceFieldPass::Instance()->RasterizeModelSDF(this, Model->SDF, _transform, _box);
|
||||
return;
|
||||
}
|
||||
if (renderContext.View.Pass == DrawPass::GlobalSurfaceAtlas)
|
||||
{
|
||||
if (DrawModes & DrawPass::GlobalSurfaceAtlas)
|
||||
if (EnumHasAnyFlags(DrawModes, DrawPass::GlobalSurfaceAtlas))
|
||||
GlobalSurfaceAtlasPass::Instance()->RasterizeActor(this, this, _sphere, _transform, Model->LODs.Last().GetBox());
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user