2021-07-01 14:34:08 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-21 01:00:09 +08:00
|
|
|
#include <Cesium3DTilesSelection/IPrepareRendererResources.h>
|
|
|
|
|
#include <Cesium3DTilesSelection/Tile.h>
|
2024-12-21 00:56:49 +08:00
|
|
|
#include <CesiumRasterOverlays/RasterOverlayTile.h>
|
2022-07-30 05:38:14 +08:00
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
#include <doctest/doctest.h>
|
2023-11-02 16:48:57 +08:00
|
|
|
|
2022-07-30 05:37:35 +08:00
|
|
|
#include <atomic>
|
2025-04-02 02:03:03 +08:00
|
|
|
#include <functional>
|
2021-07-01 14:34:08 +08:00
|
|
|
|
2022-07-23 03:04:29 +08:00
|
|
|
namespace Cesium3DTilesSelection {
|
2021-07-01 14:34:08 +08:00
|
|
|
class SimplePrepareRendererResource
|
2021-07-15 21:33:29 +08:00
|
|
|
: public Cesium3DTilesSelection::IPrepareRendererResources {
|
2021-07-01 14:34:08 +08:00
|
|
|
public:
|
2022-07-30 05:37:35 +08:00
|
|
|
std::atomic<size_t> totalAllocation{};
|
2021-07-01 14:34:08 +08:00
|
|
|
|
2022-07-30 05:37:35 +08:00
|
|
|
struct AllocationResult {
|
2022-07-30 05:38:14 +08:00
|
|
|
AllocationResult(std::atomic<size_t>& allocCount_)
|
|
|
|
|
: allocCount{allocCount_} {
|
2022-07-30 05:37:35 +08:00
|
|
|
++allocCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~AllocationResult() noexcept { --allocCount; }
|
2021-07-01 14:34:08 +08:00
|
|
|
|
2022-07-30 05:37:35 +08:00
|
|
|
std::atomic<size_t>& allocCount;
|
|
|
|
|
};
|
2021-07-01 14:34:08 +08:00
|
|
|
|
2022-07-30 05:37:35 +08:00
|
|
|
~SimplePrepareRendererResource() noexcept { CHECK(totalAllocation == 0); }
|
2021-07-01 14:34:08 +08:00
|
|
|
|
2022-09-22 16:35:21 +08:00
|
|
|
virtual CesiumAsync::Future<TileLoadResultAndRenderResources>
|
|
|
|
|
prepareInLoadThread(
|
|
|
|
|
const CesiumAsync::AsyncSystem& asyncSystem,
|
|
|
|
|
TileLoadResult&& tileLoadResult,
|
2022-09-03 03:24:42 +08:00
|
|
|
const glm::dmat4& /*transform*/,
|
|
|
|
|
const std::any& /*rendererOptions*/) override {
|
2025-04-02 02:03:03 +08:00
|
|
|
prepareInLoadThreadTestCallback(tileLoadResult);
|
2022-09-22 16:35:21 +08:00
|
|
|
return asyncSystem.createResolvedFuture(TileLoadResultAndRenderResources{
|
|
|
|
|
std::move(tileLoadResult),
|
|
|
|
|
new AllocationResult{totalAllocation}});
|
2021-07-01 14:34:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void* prepareInMainThread(
|
2021-07-15 21:33:29 +08:00
|
|
|
Cesium3DTilesSelection::Tile& /*tile*/,
|
2022-07-30 05:37:35 +08:00
|
|
|
void* pLoadThreadResult) override {
|
|
|
|
|
if (pLoadThreadResult) {
|
|
|
|
|
AllocationResult* loadThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pLoadThreadResult);
|
|
|
|
|
delete loadThreadResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new AllocationResult{totalAllocation};
|
2021-07-01 14:34:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void free(
|
2021-07-15 21:33:29 +08:00
|
|
|
Cesium3DTilesSelection::Tile& /*tile*/,
|
2021-07-01 14:34:08 +08:00
|
|
|
void* pLoadThreadResult,
|
|
|
|
|
void* pMainThreadResult) noexcept override {
|
|
|
|
|
if (pMainThreadResult) {
|
2022-07-30 05:37:35 +08:00
|
|
|
AllocationResult* mainThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pMainThreadResult);
|
2021-07-01 14:34:08 +08:00
|
|
|
delete mainThreadResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pLoadThreadResult) {
|
2022-07-30 05:37:35 +08:00
|
|
|
AllocationResult* loadThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pLoadThreadResult);
|
2021-07-01 14:34:08 +08:00
|
|
|
delete loadThreadResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-26 07:49:39 +08:00
|
|
|
virtual void* prepareRasterInLoadThread(
|
2024-10-10 23:26:58 +08:00
|
|
|
CesiumGltf::ImageAsset& /*image*/,
|
2022-03-29 11:48:21 +08:00
|
|
|
const std::any& /*rendererOptions*/) override {
|
2022-07-30 05:37:35 +08:00
|
|
|
return new AllocationResult{totalAllocation};
|
2021-07-01 14:34:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void* prepareRasterInMainThread(
|
2023-11-14 15:29:47 +08:00
|
|
|
CesiumRasterOverlays::RasterOverlayTile& /*rasterTile*/,
|
2022-07-30 05:37:35 +08:00
|
|
|
void* pLoadThreadResult) override {
|
|
|
|
|
if (pLoadThreadResult) {
|
|
|
|
|
AllocationResult* loadThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pLoadThreadResult);
|
|
|
|
|
delete loadThreadResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new AllocationResult{totalAllocation};
|
2021-07-01 14:34:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void freeRaster(
|
2023-11-14 15:29:47 +08:00
|
|
|
const CesiumRasterOverlays::RasterOverlayTile& /*rasterTile*/,
|
2021-07-01 14:34:08 +08:00
|
|
|
void* pLoadThreadResult,
|
|
|
|
|
void* pMainThreadResult) noexcept override {
|
|
|
|
|
if (pMainThreadResult) {
|
2022-07-30 05:37:35 +08:00
|
|
|
AllocationResult* mainThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pMainThreadResult);
|
2021-07-01 14:34:08 +08:00
|
|
|
delete mainThreadResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pLoadThreadResult) {
|
2022-07-30 05:37:35 +08:00
|
|
|
AllocationResult* loadThreadResult =
|
|
|
|
|
reinterpret_cast<AllocationResult*>(pLoadThreadResult);
|
2021-07-01 14:34:08 +08:00
|
|
|
delete loadThreadResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void attachRasterInMainThread(
|
2021-07-15 21:33:29 +08:00
|
|
|
const Cesium3DTilesSelection::Tile& /*tile*/,
|
2021-08-24 11:32:56 +08:00
|
|
|
int32_t /*overlayTextureCoordinateID*/,
|
2023-11-14 15:29:47 +08:00
|
|
|
const CesiumRasterOverlays::RasterOverlayTile& /*rasterTile*/,
|
2021-07-01 14:34:08 +08:00
|
|
|
void* /*pMainThreadRendererResources*/,
|
|
|
|
|
const glm::dvec2& /*translation*/,
|
|
|
|
|
const glm::dvec2& /*scale*/) override {}
|
|
|
|
|
|
|
|
|
|
virtual void detachRasterInMainThread(
|
2021-07-15 21:33:29 +08:00
|
|
|
const Cesium3DTilesSelection::Tile& /*tile*/,
|
2021-08-24 11:32:56 +08:00
|
|
|
int32_t /*overlayTextureCoordinateID*/,
|
2023-11-14 15:29:47 +08:00
|
|
|
const CesiumRasterOverlays::RasterOverlayTile& /*rasterTile*/,
|
2021-08-26 12:47:25 +08:00
|
|
|
void* /*pMainThreadRendererResources*/) noexcept override {}
|
2025-04-02 02:03:03 +08:00
|
|
|
|
|
|
|
|
std::function<void(const TileLoadResult&)> prepareInLoadThreadTestCallback =
|
|
|
|
|
[](const TileLoadResult& /*result*/) {};
|
2021-07-01 14:34:08 +08:00
|
|
|
};
|
2022-07-23 03:04:29 +08:00
|
|
|
} // namespace Cesium3DTilesSelection
|