1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#include "NvBlastExtDataConverter.h"
#include "NvBlastExtBinaryBlockConverter.h"
#include <iostream>
// asset converters
#include "NvBlastExtAssetBlockVersionConverter_v0_v1.h"
namespace Nv
{
namespace Blast
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Asset Block Converter
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
NV_INLINE std::vector<BinaryBlockConverter::VersionConverterPtr> getAssetConverters()
{
/**
+==========================================+
| HINT: ADD NEW VERSION CONVERTERS THERE |
+==========================================+
*/
BinaryBlockConverter::VersionConverterPtr converters[] =
{
std::make_shared<NvBlastAssetBlockVersionConverter_v0_v1>()
};
return std::vector<BinaryBlockConverter::VersionConverterPtr>(converters, converters + sizeof(converters) / sizeof(converters[0]));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Family Converter
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
NV_INLINE std::vector<BinaryBlockConverter::VersionConverterPtr> getFamilyConverters()
{
/**
+==========================================+
| HINT: ADD NEW VERSION CONVERTERS THERE |
+==========================================+
*/
BinaryBlockConverter::VersionConverterPtr converters[] =
{
nullptr //std::make_shared<NvBlastFamilyVersionConverter_v0_v1>()
};
return std::vector<BinaryBlockConverter::VersionConverterPtr>(converters, converters + sizeof(converters) / sizeof(converters[0]));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Generic Block Converter
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool convertDataBlock(std::vector<char>& outBlock, const std::vector<char>& inBlock, uint32_t* outBlockVersion)
{
// Pick header to determine dataType and version
if (inBlock.size() < sizeof(NvBlastDataBlock))
{
std::cerr << "Conversion failed: invalid block, passed block is too small." << std::endl;
return false;
}
const NvBlastDataBlock* dataBlock = reinterpret_cast<const NvBlastDataBlock*>(inBlock.data());
// Select appropriate converters and version based on dataType
std::vector<BinaryBlockConverter::VersionConverterPtr> converters;
uint32_t version;
switch (dataBlock->dataType)
{
case NvBlastDataBlock::AssetDataBlock:
std::cout << "Input block dataType: NvBlastDataBlock::Asset" << std::endl;
converters = getAssetConverters();
version = (outBlockVersion == nullptr ? static_cast<uint32_t>(NvBlastAssetDataFormat::Current) : *outBlockVersion);
break;
case NvBlastDataBlock::FamilyDataBlock:
std::cout << "Input block dataType: NvBlastDataBlock::Family" << std::endl;
converters = getFamilyConverters();
version = (outBlockVersion == nullptr ? static_cast<uint32_t>(NvBlastFamilyDataFormat::Current) : *outBlockVersion);
break;
default:
std::cerr << "Conversion failed: unsupported dataType: " << dataBlock->dataType << std::endl;
return false;
}
return BinaryBlockConverter::convertBinaryBlock(outBlock, converters, inBlock, version, dataBlock->formatVersion);
}
} // namespace Blast
} // namespace Nv
|