-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYDRA-598 : Merge viewport information interface (#4)
* HYDRA-598 : Merge viewport information interface * Fix build under Linux. * HYDRA-598 : Fixes from code review. * HYDRA-598 : Attempt in fixing Linux crash in tests * HYDRA-598 : Changes from code review. * HYDRA-598 : Fix a possible crash by deleting the RenderIndexProxy last. * HYDRA-598 : Fixes from the code review. * HYDRA-598 : Update a name from code review. * HYDRA-598 : Add tests for multiviewports and update code taking into account the shared scene/render/index we use for all viewports * HYDRA-598 : Fixes from code review. * HYDRA-598 : Fixes from code review.
- Loading branch information
1 parent
d4f2a6d
commit 9922683
Showing
47 changed files
with
1,341 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Copyright 2023 Autodesk, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
|
||
/// Is the definition of a callbacks InformationClient for an Hydra viewport. | ||
|
||
#ifndef FLOW_VIEWPORT_API_INFORMATION_CLIENT_H | ||
#define FLOW_VIEWPORT_API_INFORMATION_CLIENT_H | ||
|
||
#include "flowViewport/api.h" | ||
|
||
#include "fvpInformationInterface.h" | ||
|
||
namespace FVP_NS_DEF | ||
{ | ||
///Subclass this to create a client and register it through the InformationInterface class | ||
class InformationClient | ||
{ | ||
public: | ||
|
||
/** | ||
* @brief Callback function called when an Hydra viewport scene index is being created by our Hydra viewport plugin | ||
* | ||
* This is a callback function that gets called when an Hydra viewport scene index is being created by our Hydra viewport plugin. | ||
* A typical case is when an Hydra viewport is created. | ||
* | ||
* @param[in] viewportInformation is an Hydra viewport information from the scene index being added by our Hydra viewport plugin. | ||
*/ | ||
virtual void SceneIndexAdded(const InformationInterface::ViewportInformation& viewportInformation) = 0; | ||
|
||
/** | ||
* @brief Callback function called when an Hydra viewport scene index is being removed by our Hydra viewport plugin | ||
* | ||
* This is a callback function that gets called when an Hydra viewport scene index is removed by our Hydra viewport plugin. | ||
* A typical case is when an Hydra viewport is removed. | ||
* | ||
* @param[in] viewportInformation is an Hydra viewport information from the scene index being removed by our Hydra viewport plugin. | ||
*/ | ||
virtual void SceneIndexRemoved(const InformationInterface::ViewportInformation& viewportInformation) = 0; | ||
|
||
/// Destructor | ||
virtual ~InformationClient() = default; | ||
}; | ||
|
||
/// Set of InformationClient | ||
using SharedInformationClientPtrSet = std::set<std::shared_ptr<InformationClient>>; | ||
|
||
}//end of namespace | ||
|
||
#endif //FLOW_VIEWPORT_API_INFORMATION_CLIENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// Copyright 2023 Autodesk, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#ifndef FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H | ||
#define FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H | ||
|
||
//Local headers | ||
#include "flowViewport/api.h" | ||
|
||
//Hydra headers | ||
#include <pxr/imaging/hd/sceneIndex.h> | ||
|
||
namespace FVP_NS_DEF | ||
{ | ||
class InformationClient;//Predeclaration | ||
|
||
/*!\class InformationInterface | ||
\brief : interface for a customer to register a callbacks InformationClient to get Hydra viewports information. | ||
* To get an instance of the InformationInterface class, please use : | ||
* Fvp::InformationInterface& informationInterface = Fvp::InformationInterface::Get(); | ||
*/ | ||
class InformationInterface | ||
{ | ||
public: | ||
|
||
///Interface accessor | ||
static FVP_API InformationInterface& Get(); | ||
|
||
///Struct used to store information about an Hydra viewport from the DCC | ||
struct ViewportInformation | ||
{ | ||
/// Constructor | ||
ViewportInformation(const std::string& viewportId, const std::string& cameraName) | ||
: _viewportId(viewportId), _cameraName(cameraName) {} | ||
|
||
///_viewportId is an Hydra viewport string identifier which is unique for all hydra viewports during a session | ||
const std::string _viewportId; | ||
|
||
///_cameraName is the name of the camera/viewport when the viewport was created, it is not updated if the camera's name has changed. | ||
const std::string _cameraName; | ||
|
||
///_rendererName is the Hydra viewport renderer name (example : "GL" for Storm or "Arnold" for the Arnold render delegate) | ||
std::string _rendererName; | ||
|
||
bool operator ==(const ViewportInformation& other)const{ | ||
return _viewportId == other._viewportId && | ||
_cameraName == other._cameraName && | ||
_rendererName == other._rendererName; | ||
} | ||
|
||
bool operator <(const ViewportInformation& other) const{ //to be used in std::set | ||
auto a = {_viewportId, _cameraName, _rendererName}; | ||
auto b = {other._viewportId, other._cameraName, other._rendererName}; | ||
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); | ||
} | ||
}; | ||
|
||
///Set of InformationInterface::ViewportInformation | ||
typedef std::set<InformationInterface::ViewportInformation> ViewportInformationSet; | ||
|
||
/** | ||
* @brief Register a set of callbacks through an InformationClient instance | ||
* | ||
* @param[in] client is the InformationClient. | ||
*/ | ||
virtual void RegisterInformationClient(const std::shared_ptr<InformationClient>& client) = 0; | ||
|
||
/** | ||
* @brief Unregister an InformationClient instance | ||
* | ||
* @param[in] client is the InformationClient. | ||
*/ | ||
virtual void UnregisterInformationClient(const std::shared_ptr<InformationClient>& client)= 0; | ||
|
||
/** | ||
* @brief Get the Hydra viewports information. | ||
* | ||
* @param[out] outAllHydraViewportInformation is a set of ViewportInformation to have information about each Hydra viewport in use in the current DCC. | ||
*/ | ||
virtual void GetViewportsInformation(ViewportInformationSet& outAllHydraViewportInformation)const = 0; | ||
}; | ||
|
||
}//end of namespace | ||
|
||
#endif //FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
lib/flowViewport/API/interfacesImp/fvpInformationInterfaceImp.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// Copyright 2023 Autodesk, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
//Local headers | ||
#include "fvpInformationInterfaceImp.h" | ||
#include "flowViewport/API/perViewportSceneIndicesData/fvpViewportInformationAndSceneIndicesPerViewportDataManager.h" | ||
|
||
#include <mutex> | ||
|
||
namespace{ | ||
std::mutex _viewportInformationClient_mutex; | ||
|
||
//Set of information clients | ||
FVP_NS_DEF::SharedInformationClientPtrSet _viewportInformationClients; | ||
} | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
|
||
InformationInterface& InformationInterface::Get() | ||
{ | ||
return InformationInterfaceImp::Get(); | ||
} | ||
|
||
InformationInterfaceImp& InformationInterfaceImp::Get() | ||
{ | ||
static InformationInterfaceImp theInterface; | ||
return theInterface; | ||
} | ||
|
||
void InformationInterfaceImp::RegisterInformationClient(const std::shared_ptr<InformationClient>& client) | ||
{ | ||
TF_AXIOM(client); | ||
|
||
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex); | ||
|
||
auto foundResult = _viewportInformationClients.find(client); | ||
if (foundResult == _viewportInformationClients.cend()){ | ||
_viewportInformationClients.insert(client); | ||
} | ||
} | ||
|
||
void InformationInterfaceImp::UnregisterInformationClient(const std::shared_ptr<InformationClient>& client) | ||
{ | ||
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex); | ||
|
||
auto foundResult = _viewportInformationClients.find(client); | ||
if (foundResult != _viewportInformationClients.end()){ | ||
_viewportInformationClients.erase(foundResult); | ||
} | ||
} | ||
|
||
void InformationInterfaceImp::SceneIndexAdded(const InformationInterface::ViewportInformation& _viewportInfo) | ||
{ | ||
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex); | ||
for (auto viewportInfoClient : _viewportInformationClients){ | ||
if (viewportInfoClient){ | ||
viewportInfoClient->SceneIndexAdded(_viewportInfo); | ||
} | ||
} | ||
} | ||
|
||
void InformationInterfaceImp::SceneIndexRemoved(const InformationInterface::ViewportInformation& _viewportInfo) | ||
{ | ||
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex); | ||
for (auto viewportInfoClient : _viewportInformationClients){ | ||
if (viewportInfoClient){ | ||
viewportInfoClient->SceneIndexRemoved(_viewportInfo); | ||
} | ||
} | ||
} | ||
|
||
void InformationInterfaceImp::GetViewportsInformation(ViewportInformationSet& outHydraViewportInformationArray)const | ||
{ | ||
outHydraViewportInformationArray.clear(); | ||
const ViewportInformationAndSceneIndicesPerViewportDataSet& allViewportInformationAndSceneIndicesPerViewportData = | ||
ViewportInformationAndSceneIndicesPerViewportDataManager::Get().GetViewportInfoAndSceneIndicesPerViewportData(); | ||
for (const ViewportInformationAndSceneIndicesPerViewportData& viewportInformationAndSceneIndicesPerViewportData : allViewportInformationAndSceneIndicesPerViewportData){ | ||
const InformationInterface::ViewportInformation& viewportInfo = viewportInformationAndSceneIndicesPerViewportData.GetViewportInformation(); | ||
outHydraViewportInformationArray.insert(viewportInfo); | ||
} | ||
} | ||
|
||
} //End of namespace FVP_NS_DEF { | ||
|
50 changes: 50 additions & 0 deletions
50
lib/flowViewport/API/interfacesImp/fvpInformationInterfaceImp.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright 2023 Autodesk, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#ifndef FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H | ||
#define FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H | ||
|
||
//Local headers | ||
#include <flowViewport/api.h> | ||
#include <flowViewport/API/fvpInformationInterface.h> | ||
#include <flowViewport/API/fvpInformationClient.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
///Is a singleton, use InformationInterfaceImp& InformationInterfaceImp::Get() to get an instance of that interface | ||
class InformationInterfaceImp : public InformationInterface | ||
{ | ||
public: | ||
virtual ~InformationInterfaceImp() = default; | ||
|
||
///Interface accessor | ||
static FVP_API InformationInterfaceImp& Get(); | ||
|
||
//From InformationInterface | ||
void RegisterInformationClient(const std::shared_ptr<InformationClient>& client)override; | ||
void UnregisterInformationClient(const std::shared_ptr<InformationClient>& client)override; | ||
void GetViewportsInformation(ViewportInformationSet& outHydraviewportInformationSet) const override; | ||
|
||
void SceneIndexAdded(const InformationInterface::ViewportInformation& _viewportInfo); | ||
void SceneIndexRemoved(const InformationInterface::ViewportInformation& viewportInfo); | ||
|
||
private: | ||
InformationInterfaceImp() = default; | ||
}; | ||
|
||
} //End of namespace FVP_NS_DEF | ||
|
||
#endif // FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.