Skip to content

Commit

Permalink
Adapt for ImageCesium only design.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Oct 4, 2024
1 parent d3fbccc commit ddff9db
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ void ACesium3DTileset::updateLastViewUpdateResultState(
}

if (this->LogAssetStats && this->_pTileset) {
const CesiumGltf::SingleAssetDepot<CesiumGltf::ImageCesium>* imageDepot =
const CesiumGltf::SharedAssetDepot<CesiumGltf::ImageCesium>* imageDepot =
this->_pTileset->getSharedAssetDepot().getImageDepot();
float averageAge;
size_t deletionCount;
Expand Down
29 changes: 15 additions & 14 deletions Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ std::optional<EncodedFeatureIdSet> encodeFeatureIdTexture(
}

// Copy the image, so that we can keep a copy of it in the glTF.
CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> imageCopy =
CesiumGltf::SharedAsset(CesiumGltf::ImageCesium(*pFeatureIdImage));
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImageCopy =
new CesiumGltf::ImageCesium(*pFeatureIdImage);
encodedFeatureIdTexture.pTexture =
MakeShared<LoadedTextureResult>(std::move(*loadTextureAnyThreadPart(
*imageCopy,
*pImageCopy,
addressX,
addressY,
TextureFilter::TF_Nearest,
Expand Down Expand Up @@ -510,11 +510,12 @@ EncodedPropertyTable encodePropertyTableAnyThreadPart(
? floorSqrtFeatureCount
: (floorSqrtFeatureCount + 1);

CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> image;
image->width = image->height = textureDimension;
image->bytesPerChannel = encodedFormat.bytesPerChannel;
image->channels = encodedFormat.channels;
image->pixelData.resize(
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImage =
new CesiumGltf::ImageCesium();
pImage->width = pImage->height = textureDimension;
pImage->bytesPerChannel = encodedFormat.bytesPerChannel;
pImage->channels = encodedFormat.channels;
pImage->pixelData.resize(
textureDimension * textureDimension * encodedFormat.bytesPerChannel *
encodedFormat.channels);

Expand All @@ -523,18 +524,18 @@ EncodedPropertyTable encodePropertyTableAnyThreadPart(
CesiumEncodedMetadataParseColorFromString::encode(
*pDescription,
property,
gsl::span(image->pixelData),
gsl::span(pImage->pixelData),
encodedFormat.bytesPerChannel * encodedFormat.channels);
} else /* info.Conversion == ECesiumEncodedMetadataConversion::Coerce */ {
CesiumEncodedMetadataCoerce::encode(
*pDescription,
property,
gsl::span(image->pixelData),
gsl::span(pImage->pixelData),
encodedFormat.bytesPerChannel * encodedFormat.channels);
}

encodedProperty.pTexture = loadTextureAnyThreadPart(
*image,
*pImage,
TextureAddress::TA_Clamp,
TextureAddress::TA_Clamp,
TextureFilter::TF_Nearest,
Expand Down Expand Up @@ -657,11 +658,11 @@ EncodedPropertyTexture encodePropertyTextureAnyThreadPart(
}

// Copy the image, so that we can keep a copy of it in the glTF.
CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> imageCopy =
CesiumGltf::SharedAsset(CesiumGltf::ImageCesium(*pImage));
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImageCopy =
new CesiumGltf::ImageCesium(*pImage);
encodedProperty.pTexture =
MakeShared<LoadedTextureResult>(std::move(*loadTextureAnyThreadPart(
*imageCopy,
*pImageCopy,
addressX,
addressY,
// TODO: account for texture filter
Expand Down
40 changes: 20 additions & 20 deletions Source/CesiumRuntime/Private/CesiumEncodedMetadataUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,20 @@ EncodedMetadataFeatureTable encodeMetadataFeatureTableAnyThreadPart(
? floorSqrtFeatureCount
: (floorSqrtFeatureCount + 1);

CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> image;
image->bytesPerChannel = encodedFormat.bytesPerChannel;
image->channels = encodedFormat.channels;
image->compressedPixelFormat = CesiumGltf::GpuCompressedPixelFormat::NONE;
image->height = image->width = ceilSqrtFeatureCount;
image->pixelData.resize(size_t(
image->width * image->height * image->channels *
image->bytesPerChannel));
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImage =
new CesiumGltf::ImageCesium();
pImage->bytesPerChannel = encodedFormat.bytesPerChannel;
pImage->channels = encodedFormat.channels;
pImage->compressedPixelFormat = CesiumGltf::GpuCompressedPixelFormat::NONE;
pImage->height = pImage->width = ceilSqrtFeatureCount;
pImage->pixelData.resize(size_t(
pImage->width * pImage->height * pImage->channels *
pImage->bytesPerChannel));

if (isArray) {
switch (gpuType) {
case ECesiumMetadataPackedGpuType_DEPRECATED::Uint8_DEPRECATED: {
uint8* pWritePos = reinterpret_cast<uint8*>(image->pixelData.data());
uint8* pWritePos = reinterpret_cast<uint8*>(pImage->pixelData.data());
int64_t pixelSize =
encodedFormat.channels * encodedFormat.bytesPerChannel;
for (int64 i = 0; i < featureCount; ++i) {
Expand All @@ -233,7 +234,7 @@ EncodedMetadataFeatureTable encodeMetadataFeatureTableAnyThreadPart(
}
} break;
case ECesiumMetadataPackedGpuType_DEPRECATED::Float_DEPRECATED: {
uint8* pWritePos = reinterpret_cast<uint8*>(image->pixelData.data());
uint8* pWritePos = reinterpret_cast<uint8*>(pImage->pixelData.data());
int64_t pixelSize =
encodedFormat.channels * encodedFormat.bytesPerChannel;
for (int64 i = 0; i < featureCount; ++i) {
Expand All @@ -257,7 +258,7 @@ EncodedMetadataFeatureTable encodeMetadataFeatureTableAnyThreadPart(
} else {
switch (gpuType) {
case ECesiumMetadataPackedGpuType_DEPRECATED::Uint8_DEPRECATED: {
uint8* pWritePos = reinterpret_cast<uint8*>(image->pixelData.data());
uint8* pWritePos = reinterpret_cast<uint8*>(pImage->pixelData.data());
for (int64 i = 0; i < featureCount; ++i) {
*pWritePos = UCesiumPropertyTablePropertyBlueprintLibrary::GetByte(
property,
Expand All @@ -266,7 +267,7 @@ EncodedMetadataFeatureTable encodeMetadataFeatureTableAnyThreadPart(
}
} break;
case ECesiumMetadataPackedGpuType_DEPRECATED::Float_DEPRECATED: {
float* pWritePosF = reinterpret_cast<float*>(image->pixelData.data());
float* pWritePosF = reinterpret_cast<float*>(pImage->pixelData.data());
for (int64 i = 0; i < featureCount; ++i) {
*pWritePosF = UCesiumPropertyTablePropertyBlueprintLibrary::GetFloat(
property,
Expand All @@ -278,7 +279,7 @@ EncodedMetadataFeatureTable encodeMetadataFeatureTableAnyThreadPart(
}

encodedProperty.pTexture = loadTextureAnyThreadPart(
*image,
*pImage,
TextureAddress::TA_Clamp,
TextureAddress::TA_Clamp,
TextureFilter::TF_Nearest,
Expand Down Expand Up @@ -410,11 +411,11 @@ EncodedFeatureTexture encodeFeatureTextureAnyThreadPart(
if (pMappedUnrealImageIt) {
encodedFeatureTextureProperty.pTexture = pMappedUnrealImageIt->Pin();
} else {
CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> imageCopy =
CesiumGltf::SharedAsset(CesiumGltf::ImageCesium(*pImage));
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImageCopy =
new CesiumGltf::ImageCesium(*pImage);
encodedFeatureTextureProperty.pTexture =
MakeShared<LoadedTextureResult>(std::move(*loadTextureAnyThreadPart(
*imageCopy,
*pImageCopy,
TextureAddress::TA_Clamp,
TextureAddress::TA_Clamp,
TextureFilter::TF_Nearest,
Expand Down Expand Up @@ -516,12 +517,11 @@ EncodedMetadataPrimitive encodeMetadataPrimitiveAnyThreadPart(
if (pMappedUnrealImageIt) {
encodedFeatureIdTexture.pTexture = pMappedUnrealImageIt->Pin();
} else {
CesiumGltf::SharedAsset<CesiumGltf::ImageCesium> imageCopy =
CesiumGltf::SharedAsset(
CesiumGltf::ImageCesium(*pFeatureIdImage));
CesiumUtility::IntrusivePointer<CesiumGltf::ImageCesium> pImageCopy =
new CesiumGltf::ImageCesium(*pFeatureIdImage);
encodedFeatureIdTexture.pTexture = MakeShared<LoadedTextureResult>(
std::move(*loadTextureAnyThreadPart(
*imageCopy,
*pImageCopy,
TextureAddress::TA_Clamp,
TextureAddress::TA_Clamp,
TextureFilter::TF_Nearest,
Expand Down
2 changes: 1 addition & 1 deletion Source/CesiumRuntime/Private/CesiumGltfTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ SharedFuture<void> createTextureInLoadThread(
const ExtensionImageCesiumUnreal& extension =
ExtensionImageCesiumUnreal::getOrCreate(
asyncSystem,
*pImage->cesium,
*pImage->pCesium,
sRGB,
needsMips,
std::nullopt);
Expand Down
5 changes: 4 additions & 1 deletion Source/CesiumRuntime/Private/CesiumTextureUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ TUniquePtr<LoadedTextureResult> loadTextureFromModelAnyThreadPart(
model.getSafe(model.samplers, texture.sampler);

TUniquePtr<LoadedTextureResult> result =
loadTextureFromImageAndSamplerAnyThreadPart(*image.cesium, sampler, sRGB);
loadTextureFromImageAndSamplerAnyThreadPart(
*image.pCesium,
sampler,
sRGB);

if (result) {
extension.pTexture = result->pTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void setupForSharedImages(SceneGenerationContext& context) {
void tilesetPass(
SceneGenerationContext& context,
TestPass::TestingParameter parameter) {
CesiumGltf::SharedAssetDepot& assetDepot =
CesiumGltf::SharedAssetDepots& assetDepot =
context.tilesets[0]->GetTileset()->getSharedAssetDepot();
assert(assetDepot.getImagesCount() == 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ void FCesiumFeatureIdTextureSpec::Define() {
It("constructs valid instance for texture with nonexistent texcoord attribute",
[this]() {
Image& image = model.images.emplace_back();
image.cesium->width = image.cesium->height = 1;
image.cesium->channels = 1;
image.cesium->pixelData.push_back(std::byte(42));
image.pCesium->width = image.pCesium->height = 1;
image.pCesium->channels = 1;
image.pCesium->pixelData.push_back(std::byte(42));

Sampler& sampler = model.samplers.emplace_back();
sampler.wrapS = Sampler::WrapS::CLAMP_TO_EDGE;
Expand Down Expand Up @@ -175,9 +175,9 @@ void FCesiumFeatureIdTextureSpec::Define() {
It("constructs valid instance for texture with invalid texcoord accessor",
[this]() {
Image& image = model.images.emplace_back();
image.cesium->width = image.cesium->height = 1;
image.cesium->channels = 1;
image.cesium->pixelData.push_back(std::byte(42));
image.pCesium->width = image.pCesium->height = 1;
image.pCesium->channels = 1;
image.pCesium->pixelData.push_back(std::byte(42));

Sampler& sampler = model.samplers.emplace_back();
sampler.wrapS = Sampler::WrapS::CLAMP_TO_EDGE;
Expand Down
11 changes: 6 additions & 5 deletions Source/CesiumRuntime/Private/Tests/CesiumGltfSpecUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ CesiumGltf::FeatureId& AddFeatureIDsAsTextureToModel(
const int32_t samplerWrapS,
const int32_t samplerWrapT) {
CesiumGltf::Image& image = model.images.emplace_back();
image.cesium->bytesPerChannel = 1;
image.cesium->channels = 1;
image.cesium->width = imageWidth;
image.cesium->height = imageHeight;
image.pCesium.emplace();
image.pCesium->bytesPerChannel = 1;
image.pCesium->channels = 1;
image.pCesium->width = imageWidth;
image.pCesium->height = imageHeight;

std::vector<std::byte>& data = image.cesium->pixelData;
std::vector<std::byte>& data = image.pCesium->pixelData;
data.resize(imageWidth * imageHeight);
std::memcpy(data.data(), featureIDs.data(), data.size());

Expand Down
15 changes: 8 additions & 7 deletions Source/CesiumRuntime/Private/Tests/CesiumGltfSpecUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,16 @@ CesiumGltf::PropertyTextureProperty& AddPropertyTexturePropertyToModel(
classProperty.componentType = componentType;

CesiumGltf::Image& image = model.images.emplace_back();
image.cesium->width = 2;
image.cesium->height = 2;
image.cesium->channels = sizeof(T);
image.cesium->bytesPerChannel = 1;
image.cesium->pixelData.resize(values.size() * sizeof(T));
image.pCesium.emplace();
image.pCesium->width = 2;
image.pCesium->height = 2;
image.pCesium->channels = sizeof(T);
image.pCesium->bytesPerChannel = 1;
image.pCesium->pixelData.resize(values.size() * sizeof(T));
std::memcpy(
image.cesium->pixelData.data(),
image.pCesium->pixelData.data(),
values.data(),
image.cesium->pixelData.size());
image.pCesium->pixelData.size());

CesiumGltf::Sampler& sampler = model.samplers.emplace_back();
sampler.wrapS = CesiumGltf::Sampler::WrapS::CLAMP_TO_EDGE;
Expand Down
Loading

0 comments on commit ddff9db

Please sign in to comment.