add macOS implementation
This commit is contained in:
32
macos/include/uberz/ArchiveEnums.h
Normal file
32
macos/include/uberz/ArchiveEnums.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* 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 UBERZ_ARCHIVE_ENUMS_H
|
||||
#define UBERZ_ARCHIVE_ENUMS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::uberz {
|
||||
|
||||
enum class ArchiveFeature : uint64_t {
|
||||
UNSUPPORTED,
|
||||
OPTIONAL,
|
||||
REQUIRED,
|
||||
};
|
||||
|
||||
} // namespace filament::uberz
|
||||
|
||||
#endif // UBERZ_ARCHIVE_ENUMS_H
|
||||
79
macos/include/uberz/ReadableArchive.h
Normal file
79
macos/include/uberz/ReadableArchive.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* 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 UBERZ_READABLE_ARCHIVE_H
|
||||
#define UBERZ_READABLE_ARCHIVE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <uberz/ArchiveEnums.h>
|
||||
|
||||
#include <filament/MaterialEnums.h>
|
||||
|
||||
namespace filament::uberz {
|
||||
|
||||
// ArchiveSpec is a parse-free binary format. The client simply casts a word-aligned content blob
|
||||
// into a ReadableArchive struct pointer, then calls the following function to convert all the
|
||||
// offset fields into pointers.
|
||||
void convertOffsetsToPointers(struct ReadableArchive* archive);
|
||||
|
||||
UTILS_WARNING_PUSH
|
||||
UTILS_WARNING_ENABLE_PADDED
|
||||
|
||||
// Precompiled set of materials bundled with a list of features flags that each material supports.
|
||||
// This is the readable counterpart to WriteableArchive.
|
||||
// Used by gltfio; users do not need to access this class directly.
|
||||
struct ReadableArchive {
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
uint64_t specsCount;
|
||||
union {
|
||||
struct ArchiveSpec* specs;
|
||||
uint64_t specsOffset;
|
||||
};
|
||||
};
|
||||
|
||||
static constexpr Shading INVALID_SHADING_MODEL = (Shading) 0xff;
|
||||
static constexpr BlendingMode INVALID_BLENDING = (BlendingMode) 0xff;
|
||||
|
||||
struct ArchiveSpec {
|
||||
Shading shadingModel;
|
||||
BlendingMode blendingMode;
|
||||
uint16_t flagsCount;
|
||||
uint32_t packageByteCount;
|
||||
union {
|
||||
struct ArchiveFlag* flags;
|
||||
uint64_t flagsOffset;
|
||||
};
|
||||
union {
|
||||
uint8_t* package;
|
||||
uint64_t packageOffset;
|
||||
};
|
||||
};
|
||||
|
||||
struct ArchiveFlag {
|
||||
union {
|
||||
const char* name;
|
||||
uint64_t nameOffset;
|
||||
};
|
||||
ArchiveFeature value;
|
||||
};
|
||||
|
||||
UTILS_WARNING_POP
|
||||
|
||||
} // namespace filament::uberz
|
||||
|
||||
#endif // UBERZ_READABLE_ARCHIVE_H
|
||||
67
macos/include/uberz/WritableArchive.h
Normal file
67
macos/include/uberz/WritableArchive.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* 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 UBERZ_WRITABLE_ARCHIVE_H
|
||||
#define UBERZ_WRITABLE_ARCHIVE_H
|
||||
|
||||
#include <filament/MaterialEnums.h>
|
||||
|
||||
#include <uberz/ArchiveEnums.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/CString.h>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include <tsl/robin_map.h>
|
||||
|
||||
namespace filament::uberz {
|
||||
|
||||
// Precompiled set of materials bundled with a list of features flags that each material supports.
|
||||
// This is the writeable counterpart to ReadableArchive.
|
||||
// Users do not need to access this class directly, they should go through gltfio.
|
||||
class WritableArchive {
|
||||
public:
|
||||
WritableArchive(size_t materialCount) : mMaterials(uint32_t(materialCount)) {
|
||||
assert(materialCount <= UINT_MAX);
|
||||
}
|
||||
|
||||
void addMaterial(const char* name, const uint8_t* package, size_t packageSize);
|
||||
void addSpecLine(std::string_view line);
|
||||
utils::FixedCapacityVector<uint8_t> serialize() const;
|
||||
|
||||
// Low-level alternatives to addSpecLine that do not involve parsing:
|
||||
void setShadingModel(Shading sm);
|
||||
void setBlendingModel(BlendingMode bm);
|
||||
void setFeatureFlag(const char* key, ArchiveFeature value);
|
||||
|
||||
private:
|
||||
size_t mLineNumber = 1;
|
||||
ssize_t mMaterialIndex = -1;
|
||||
|
||||
struct Material {
|
||||
utils::CString name;
|
||||
utils::FixedCapacityVector<uint8_t> package;
|
||||
Shading shadingModel;
|
||||
BlendingMode blendingMode;
|
||||
tsl::robin_map<utils::CString, ArchiveFeature, utils::CString::Hasher> flags;
|
||||
};
|
||||
|
||||
utils::FixedCapacityVector<Material> mMaterials;
|
||||
};
|
||||
|
||||
} // namespace filament::uberz
|
||||
|
||||
#endif // UBERZ_WRITABLE_ARCHIVE_H
|
||||
Reference in New Issue
Block a user