Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Implement utility to check for used render pipeline #766

Merged
merged 2 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace XRTK.Definitions.Utilities
{
/// <summary>
/// Available render pipelines for use in Unity applications.
/// </summary>
public enum RenderPipeline
FejZa marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// The legacy "built-in" render pipeline of Unity that was deprecated
/// when scriptable render pipelines were introduced.
/// </summary>
Legacy = 0,
/// <summary>
/// The universal render pipeline, formerly also known as lightweight render pipeline.
/// </summary>
UniversalRenderPipeline,
/// <summary>
/// The high definition pipeline.
/// </summary>
HighDefinitionRenderPipeline,
/// <summary>
/// A customized scriptable render pipeline.
/// </summary>
Custom
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine.Rendering;
using XRTK.Extensions;
using RenderPipeline = XRTK.Definitions.Utilities.RenderPipeline;

namespace XRTK.Utilities
{
public static class RenderPipelineUtilities
{
private const string urpAssetTypeName = "UniversalRenderPipelineAsset";
private const string hdrpAssetTypeName = "HDRenderPipelineAsset";

/// <summary>
/// Gets the <see cref="RenderPipeline"/> used by the project.
/// </summary>
/// <returns>The <see cref="RenderPipeline"/> used by the project.</returns>
public static RenderPipeline GetActiveRenderingPipeline()
{
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
if (renderPipelineAsset.IsNull())
{
return RenderPipeline.Legacy;
}

switch (renderPipelineAsset.GetType().Name)
{
case urpAssetTypeName:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we can use pattern matching for the types instead of using the string name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual types are only available if the URP / HDRP package is installed and this check needs to work even when no render pipeline package is in use. So string is all we got.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FejZa do you know if those packages define symbols for the features?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they don't. Freya Holmér put a lot of thoughts into this and this is pretty much what she came up with in the end. It's not perfect but I don't think currently there is any better way to check this.

return RenderPipeline.UniversalRenderPipeline;
case hdrpAssetTypeName:
return RenderPipeline.HighDefinitionRenderPipeline;
}

return RenderPipeline.Custom;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.