Skip to content

Commit

Permalink
add friend methods to OmniRasterOverlay to lock down access to Native…
Browse files Browse the repository at this point in the history
… objects
  • Loading branch information
corybarr committed Feb 14, 2024
1 parent 9fa2c66 commit 3743ec8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/core/include/cesium/omniverse/OmniRasterOverlay.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "cesium/omniverse/OmniTileset.h"

#include <CesiumRasterOverlays/RasterOverlay.h>
#include <pxr/usd/sdf/path.h>

Expand All @@ -10,9 +12,14 @@ class RasterOverlay;
namespace cesium::omniverse {

class Context;
class OmniTileset;
enum class FabricOverlayRenderMethod;

class OmniRasterOverlay {
friend void OmniTileset::addRasterOverlayIfExists(const OmniRasterOverlay* pOverlay);
friend pxr::SdfPath
OmniTileset::getRasterOverlayPathIfExists(const CesiumRasterOverlays::RasterOverlay& rasterOverlay);

public:
OmniRasterOverlay(Context* pContext, const pxr::SdfPath& path);
virtual ~OmniRasterOverlay() = default;
Expand All @@ -32,11 +39,11 @@ class OmniRasterOverlay {

[[nodiscard]] CesiumRasterOverlays::RasterOverlayOptions createRasterOverlayOptions() const;

[[nodiscard]] virtual CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const = 0;
void updateRasterOverlayOptions() const;
virtual void reload() = 0;

protected:
[[nodiscard]] virtual CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const = 0;
Context* _pContext;
pxr::SdfPath _path;

Expand Down
6 changes: 3 additions & 3 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "cesium/omniverse/OmniTileset.h"

#include <glm/glm.hpp>
#include <pxr/usd/sdf/path.h>

Expand Down Expand Up @@ -31,6 +29,7 @@ namespace cesium::omniverse {

class Context;
class FabricPrepareRenderResources;
class OmniRasterOverlay;
struct TilesetStatistics;
struct Viewport;

Expand Down Expand Up @@ -82,10 +81,11 @@ class OmniTileset {
void updateTilesetOptions();

void reload();
[[nodiscard]] pxr::SdfPath getRasterOverlayPath(const CesiumRasterOverlays::RasterOverlay& rasterOverlay) const;
[[nodiscard]] pxr::SdfPath getRasterOverlayPathIfExists(const CesiumRasterOverlays::RasterOverlay& rasterOverlay);
void updateRasterOverlayAlpha(const pxr::SdfPath& rasterOverlayPath);
void updateShaderInput(const pxr::SdfPath& shaderPath, const pxr::TfToken& attributeName);
void updateDisplayColorAndOpacity();
void addRasterOverlayIfExists(const OmniRasterOverlay* overlay);

void onUpdateFrame(const gsl::span<const Viewport>& viewports);

Expand Down
4 changes: 2 additions & 2 deletions src/core/src/FabricPrepareRenderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void FabricPrepareRenderResources::attachRasterInMainThread(
return;
}

const auto rasterOverlayPath = _pTileset->getRasterOverlayPath(rasterTile.getOverlay());
const auto rasterOverlayPath = _pTileset->getRasterOverlayPathIfExists(rasterTile.getOverlay());

if (rasterOverlayPath.IsEmpty()) {
return;
Expand Down Expand Up @@ -600,7 +600,7 @@ void FabricPrepareRenderResources::detachRasterInMainThread(
return;
}

const auto rasterOverlayPath = _pTileset->getRasterOverlayPath(rasterTile.getOverlay());
const auto rasterOverlayPath = _pTileset->getRasterOverlayPathIfExists(rasterTile.getOverlay());

if (rasterOverlayPath.IsEmpty()) {
return;
Expand Down
14 changes: 9 additions & 5 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,12 @@ void OmniTileset::reload() {
const auto pOmniRasterOverlay = _pContext->getAssetRegistry().getRasterOverlay(boundRasterOverlayPath);
if (pOmniRasterOverlay) {
pOmniRasterOverlay->reload();
const auto pNativeRasterOverlay = pOmniRasterOverlay->getRasterOverlay();
if (pNativeRasterOverlay) {
_pTileset->getOverlays().add(pNativeRasterOverlay);
}
addRasterOverlayIfExists(pOmniRasterOverlay);
}
}
}

pxr::SdfPath OmniTileset::getRasterOverlayPath(const CesiumRasterOverlays::RasterOverlay& rasterOverlay) const {
pxr::SdfPath OmniTileset::getRasterOverlayPathIfExists(const CesiumRasterOverlays::RasterOverlay& rasterOverlay) {
const auto rasterOverlayPaths = getRasterOverlayPaths();

for (const auto& rasterOverlayPath : rasterOverlayPaths) {
Expand Down Expand Up @@ -787,4 +784,11 @@ void OmniTileset::destroyNativeTileset() {
_pRenderResourcesPreparer = nullptr;
}

void OmniTileset::addRasterOverlayIfExists(const OmniRasterOverlay* pOmniRasterOverlay) {
const auto pNativeRasterOverlay = pOmniRasterOverlay->getRasterOverlay();
if (pNativeRasterOverlay) {
_pTileset->getOverlays().add(pNativeRasterOverlay);
}
}

} // namespace cesium::omniverse

0 comments on commit 3743ec8

Please sign in to comment.