10#ifndef PXR_USD_IMAGING_USD_IMAGING_GL_ENGINE_H
11#define PXR_USD_IMAGING_USD_IMAGING_GL_ENGINE_H
14#include "pxr/usdImaging/usdImagingGL/api.h"
15#include "pxr/usdImaging/usdImagingGL/version.h"
16#include "pxr/usdImaging/usdImaging/version.h"
19#include "pxr/usdImaging/usdImagingGL/rendererSettings.h"
21#include "pxr/imaging/cameraUtil/conformWindow.h"
23#include "pxr/imaging/hd/driver.h"
24#include "pxr/imaging/hd/engine.h"
25#include "pxr/imaging/hd/rprimCollection.h"
26#include "pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h"
28#include "pxr/imaging/hdx/selectionTracker.h"
29#include "pxr/imaging/hdx/renderSetupTask.h"
31#include "pxr/imaging/hgi/hgi.h"
36#include "pxr/imaging/hgi/hgi.h"
38#include "pxr/usd/sdf/path.h"
39#include "pxr/usd/usd/timeCode.h"
51PXR_NAMESPACE_OPEN_SCOPE
55class HdxTaskController;
69namespace UsdImagingGLEngine_Impl
71 using _AppSceneIndicesSharedPtr = std::shared_ptr<struct _AppSceneIndices>;
85 SdfPathVector excludedPaths;
86 SdfPathVector invisedPaths;
127 bool gpuEnabled =
true);
131 const SdfPathVector& excludedPaths,
132 const SdfPathVector& invisedPaths = SdfPathVector(),
133 const SdfPath& sceneDelegateID =
137 bool gpuEnabled =
true,
138 bool displayUnloadedPrimsWithBounds =
false,
139 bool allowAsynchronousSceneProcessing =
false);
160 void RenderBatch(
const SdfPathVector& paths,
217 const std::optional<CameraUtilConformWindowPolicy> &policy);
264 GlfSimpleMaterial
const &material,
329 SdfPath *outHitPrimPath = NULL,
330 SdfPath *outHitInstancerPath = NULL,
331 int *outHitInstanceIndex = NULL,
332 HdInstancerContext *outInstancerContext = NULL);
335 struct IntersectionResult
341 int hitInstanceIndex;
342 HdInstancerContext instancerContext;
345 typedef std::vector<struct IntersectionResult> IntersectionResultVector;
374 const PickParams& pickParams,
379 IntersectionResultVector* outResults);
385 unsigned char const primIdColor[4],
386 unsigned char const instanceIdColor[4],
387 SdfPath *outHitPrimPath = NULL,
388 SdfPath *outHitInstancerPath = NULL,
389 int *outHitInstanceIndex = NULL,
390 HdInstancerContext *outInstancerContext = NULL);
587 TfToken const& ocioDisplay = {},
589 TfToken const& ocioColorSpace = {},
644 friend class UsdImagingGL_UnitTestGLDrawing;
653 HdTaskSharedPtrVector tasks);
656 bool _CanPrepare(
const UsdPrim& root);
666 void _SetActiveRenderSettingsPrimFromStageMetadata(
UsdStageWeakPtr stage);
669 void _SetSceneGlobalsCurrentFrame(
UsdTimeCode const &time);
672 void _UpdateDomeLightCameraVisibility();
674 using BBoxVector = std::vector<GfBBox3d>;
678 const BBoxVector& bboxes,
680 float bboxLineDashSize);
686 SdfPathVector
const& roots,
696 void _InitializeHgiIfNecessary();
699 void _SetRenderDelegateAndRestoreState(
709 static TfToken _GetDefaultRendererPluginId();
723 HdxTaskController *_GetTaskController()
const;
726 HdSelectionSharedPtr _GetSelection()
const;
741 bool _displayUnloadedPrimsWithBounds;
744 std::unique_ptr<HdRenderIndex> _renderIndex;
746 SdfPath const _sceneDelegateId;
748 std::unique_ptr<HdxTaskController> _taskController;
750 HdxSelectionTrackerSharedPtr _selTracker;
754 GlfSimpleLightingContextRefPtr _lightingContextForOpenGLState;
758 bool _domeLightCameraVisibility;
761 SdfPathVector _excludedPrimPaths;
762 SdfPathVector _invisedPrimPaths;
768 static void _RegisterApplicationSceneIndices();
774 static HdSceneIndexBaseRefPtr
775 _AppendSceneGlobalsSceneIndexCallback(
776 const std::string &renderInstanceId,
777 const HdSceneIndexBaseRefPtr &inputScene,
778 const HdContainerDataSourceHandle &inputArgs);
780 HdSceneIndexBaseRefPtr
781 _AppendOverridesSceneIndices(
782 const HdSceneIndexBaseRefPtr &inputScene);
784 UsdImagingGLEngine_Impl::_AppSceneIndicesSharedPtr _appSceneIndices;
786 void _DestroyHydraObjects();
790 UsdImagingStageSceneIndexRefPtr _stageSceneIndex;
791 UsdImagingSelectionSceneIndexRefPtr _selectionSceneIndex;
792 UsdImagingRootOverridesSceneIndexRefPtr _rootOverridesSceneIndex;
793 HdsiLegacyDisplayStyleOverrideSceneIndexRefPtr _displayStyleSceneIndex;
794 HdsiPrimTypePruningSceneIndexRefPtr _materialPruningSceneIndex;
795 HdsiPrimTypePruningSceneIndexRefPtr _lightPruningSceneIndex;
796 HdSceneIndexBaseRefPtr _sceneIndex;
798 std::unique_ptr<UsdImagingDelegate> _sceneDelegate;
800 std::unique_ptr<HdEngine> _engine;
802 bool _allowAsynchronousSceneProcessing =
false;
806PXR_NAMESPACE_CLOSE_SCOPE
Stores a 4x4 matrix of double elements.
Basic type for a vector of 2 int components.
Basic type for a vector of 3 double components.
Basic type for a vector of 4 double components.
Basic type for a vector of 4 float components.
HdDriver represents a device object, commonly a render device, that is owned by the application and p...
The application-facing entry point top-level entry point for accessing Hydra.
A (movable) handle for a render delegate that was created using a a plugin.
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
A named, semantic collection of objects.
Abstract interface to scene data.
A scene index overriding the legacy display style for each prim.
Scene Index that prunes prims of given type (e.g., material) and (optionally) bindings to that prim t...
Scene index that populates a "sceneGlobals" data source as modeled by HdSceneGlobalsSchema and provid...
Hydra Graphics Interface.
A path value used to locate objects in layers or scenegraphs.
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
Token for efficient comparison, assignment, and hashing of known strings.
Pointer storage with deletion detection.
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
The UsdImagingGLEngine is the main entry point API for rendering USD scenes.
USDIMAGINGGL_API void SetSelectionColor(GfVec4f const &color)
Sets the selection highlighting color.
USDIMAGINGGL_API bool StopRenderer()
Stop the renderer.
USDIMAGINGGL_API void SetRenderBufferSize(GfVec2i const &size)
Set the size of the render buffers baking the AOVs.
USDIMAGINGGL_API bool SetRendererAov(TfToken const &id)
Set the current renderer AOV to id.
USDIMAGINGGL_API UsdImagingDelegate * _GetSceneDelegate() const
Get a direct pointer to the scene delegate.
USDIMAGINGGL_API void SetActiveRenderPassPrimPath(SdfPath const &)
Set active render pass prim to use to drive rendering.
USDIMAGINGGL_API void SetRenderViewport(GfVec4d const &viewport)
Set the viewport to use for rendering as (x,y,w,h), where (x,y) represents the lower left corner of t...
USDIMAGINGGL_API bool DecodeIntersection(unsigned char const primIdColor[4], unsigned char const instanceIdColor[4], SdfPath *outHitPrimPath=NULL, SdfPath *outHitInstancerPath=NULL, int *outHitInstanceIndex=NULL, HdInstancerContext *outInstancerContext=NULL)
Decodes a pick result given hydra prim ID/instance ID (like you'd get from an ID render).
USDIMAGINGGL_API bool RestartRenderer()
Restart the renderer.
USDIMAGINGGL_API Hgi * GetHgi()
Returns the HGI interface.
static USDIMAGINGGL_API TfTokenVector GetRendererPlugins()
Return the vector of available render-graph delegate plugins.
HdDriver driver
An HdDriver, containing the Hgi of your choice, can be optionally passed in during construction.
USDIMAGINGGL_API void Render(const UsdPrim &root, const UsdImagingGLRenderParams ¶ms)
Entry point for kicking off a render.
USDIMAGINGGL_API VtValue GetRendererSetting(TfToken const &id) const
Gets a renderer setting's current value.
USDIMAGINGGL_API bool ResumeRenderer()
Resume the renderer.
USDIMAGINGGL_API HdRenderIndex * _GetRenderIndex() const
Returns the render index of the engine, if any.
USDIMAGINGGL_API void SetEnablePresentation(bool enabled)
Enable / disable presenting the render to bound framebuffer.
USDIMAGINGGL_API void SetLightingState(GlfSimpleLightingContextPtr const &src)
Copy lighting state from another lighting context.
USDIMAGINGGL_API bool PauseRenderer()
Pause the renderer.
USDIMAGINGGL_API void SetCameraPath(SdfPath const &id)
Scene camera API Set the scene camera path to use for rendering.
USDIMAGINGGL_API void PrepareBatch(const UsdPrim &root, const UsdImagingGLRenderParams ¶ms)
Support for batched drawing.
USDIMAGINGGL_API void SetRootVisibility(bool isVisible)
Sets the root visibility.
USDIMAGINGGL_API void SetColorCorrectionSettings(TfToken const &ccType, TfToken const &ocioDisplay={}, TfToken const &ocioView={}, TfToken const &ocioColorSpace={}, TfToken const &ocioLook={})
Set ccType to one of the HdxColorCorrectionTokens: {disabled, sRGB, openColorIO}.
USDIMAGINGGL_API void SetLightingState(GlfSimpleLightVector const &lights, GlfSimpleMaterial const &material, GfVec4f const &sceneAmbient)
Set lighting state Derived classes should ensure that passing an empty lights vector disables lightin...
TfToken rendererPluginId
The rendererPluginId argument indicates the renderer plugin that Hydra should use.
USDIMAGINGGL_API UsdImagingGLEngine(const HdDriver &driver=HdDriver(), const TfToken &rendererPluginId=TfToken(), bool gpuEnabled=true)
An HdDriver, containing the Hgi of your choice, can be optionally passed in during construction.
USDIMAGINGGL_API TfTokenVector GetRendererAovs() const
Return the vector of available renderer AOV settings.
USDIMAGINGGL_API bool PollForAsynchronousUpdates() const
If allowAsynchronousSceneProcessing is true within the Parameters provided to the UsdImagingGLEngine ...
USDIMAGINGGL_API bool IsStopRendererSupported() const
Query the renderer as to whether it supports stopping and restarting.
USDIMAGINGGL_API bool IsConverged() const
Returns true if the resulting image is fully converged.
USDIMAGINGGL_API void SetCameraState(const GfMatrix4d &viewMatrix, const GfMatrix4d &projectionMatrix)
Free camera API Set camera framing state directly (without pointing to a camera on the USD stage).
bool displayUnloadedPrimsWithBounds
displayUnloadedPrimsWithBounds draws bounding boxes for unloaded prims if they have extents/extentsHi...
USDIMAGINGGL_API HdRenderBuffer * GetAovRenderBuffer(TfToken const &name) const
Returns the AOV render buffer for the given token.
USDIMAGINGGL_API bool InvokeRendererCommand(const TfToken &command, const HdCommandArgs &args=HdCommandArgs()) const
Invokes command on the active render delegate.
USDIMAGINGGL_API bool SetRendererPlugin(TfToken const &id)
Set the current render-graph delegate to id.
static USDIMAGINGGL_API bool IsColorCorrectionCapable()
Returns true if the platform is color correction capable.
static USDIMAGINGGL_API SdfPathVector GetAvailableRenderSettingsPrimPaths(UsdPrim const &root)
Utility method to query available render settings prims.
USDIMAGINGGL_API HgiTextureHandle GetAovTexture(TfToken const &name) const
Returns an AOV texture handle for the given token.
USDIMAGINGGL_API bool IsPauseRendererSupported() const
Query the renderer as to whether it supports pausing and resuming.
static USDIMAGINGGL_API std::string GetRendererDisplayName(TfToken const &id)
Return the user-friendly description of a renderer plugin.
USDIMAGINGGL_API void SetRendererSetting(TfToken const &id, VtValue const &value)
Sets a renderer setting's value.
bool allowAsynchronousSceneProcessing
allowAsynchronousSceneProcessing indicates to constructed hydra scene indices that asynchronous proce...
USDIMAGINGGL_API void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer)
The destination API (e.g., OpenGL, see hgiInterop for details) and framebuffer that the AOVs are pres...
USDIMAGINGGL_API UsdImagingGLRendererSettingsList GetRendererSettingsList() const
Returns the list of renderer settings.
USDIMAGINGGL_API TfToken GetCurrentRendererId() const
Return the id of the currently used renderer plugin.
USDIMAGINGGL_API void SetOverrideWindowPolicy(const std::optional< CameraUtilConformWindowPolicy > &policy)
Specifies whether to force a window policy when conforming the frustum of the camera to match the dis...
USDIMAGINGGL_API void ClearSelected()
Clear the list of prim paths that should be included in selection highlighting.
USDIMAGINGGL_API VtDictionary GetRenderStats() const
Returns render statistics.
USDIMAGINGGL_API HdCommandDescriptors GetRendererCommandDescriptors() const
Return command deescriptors for commands supported by the active render delegate.
USDIMAGINGGL_API void SetSelected(SdfPathVector const &paths)
Sets (replaces) the list of prim paths that should be included in selection highlighting.
bool gpuEnabled
The gpuEnabled argument determines if this instance will allow Hydra to use the GPU to produce images...
USDIMAGINGGL_API bool TestIntersection(const PickParams &pickParams, const GfMatrix4d &viewMatrix, const GfMatrix4d &projectionMatrix, const UsdPrim &root, const UsdImagingGLRenderParams ¶ms, IntersectionResultVector *outResults)
Perform picking by finding the intersection of objects in the scene with a renderered frustum.
USDIMAGINGGL_API void SetFraming(CameraUtilFraming const &framing)
Determines how the filmback of the camera is mapped into the pixels of the render buffer and what pix...
USDIMAGINGGL_API void SetWindowPolicy(CameraUtilConformWindowPolicy policy)
Set the window policy to use.
USDIMAGINGGL_API bool TestIntersection(const GfMatrix4d &viewMatrix, const GfMatrix4d &projectionMatrix, const UsdPrim &root, const UsdImagingGLRenderParams ¶ms, GfVec3d *outHitPoint, GfVec3d *outHitNormal, SdfPath *outHitPrimPath=NULL, SdfPath *outHitInstancerPath=NULL, int *outHitInstanceIndex=NULL, HdInstancerContext *outInstancerContext=NULL)
Finds closest point of intersection with a frustum by rendering.
USDIMAGINGGL_API void AddSelected(SdfPath const &path, int instanceIndex)
Add a path with instanceIndex to the list of prim paths that should be included in selection highligh...
USDIMAGINGGL_API void SetRootTransform(GfMatrix4d const &xf)
Sets the root transform.
USDIMAGINGGL_API void SetActiveRenderSettingsPrimPath(SdfPath const &)
Set active render settings prim to use to drive rendering.
USDIMAGINGGL_API bool GetGPUEnabled() const
Return if the GPU is enabled and can be used for any rendering tasks.
Parameters to construct UsdImagingGLEngine.
Used as an arguments class for various methods in UsdImagingGLEngine.
Overrides some data sources on the root prim.
A simple scene index adding HdSelectionsSchema to all prims selected with AddSelection.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
A map with string keys and VtValue values.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Standard pointer typedefs.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
RenderTask parameters (renderpass state).
std::vector< TfToken > TfTokenVector
Convenience types.