diff options
author | dan sinclair <dj2@everburning.com> | 2019-04-05 11:07:56 -0400 |
---|---|---|
committer | David Neto <dneto@google.com> | 2019-04-05 11:07:56 -0400 |
commit | a8acd2ec631cfafb3ea68c82524defca81a20547 (patch) | |
tree | c75b01aa6feab9e9811ccd91549b77b72fd632d9 /src/datum_type_test.cc | |
parent | da78976bbc877e37fd7bd662621857fe15b297e5 (diff) | |
download | amber-a8acd2ec631cfafb3ea68c82524defca81a20547.tar.gz |
Generate a Format from a DataBuffer. (#448)
Generate a Format from a DataBuffer.
When sending a VertexBuffer to Vulkan the data format is passed as a
VkFormat string. When the buffer is provided in AmberScript it is not a
FORMAT buffer. This CL adds the necessary code to generate a Format from
a DatumType. This will allow creating the necessary format to send to
Vulkan.
Diffstat (limited to 'src/datum_type_test.cc')
-rw-r--r-- | src/datum_type_test.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/datum_type_test.cc b/src/datum_type_test.cc new file mode 100644 index 0000000..ef20bed --- /dev/null +++ b/src/datum_type_test.cc @@ -0,0 +1,89 @@ +// Copyright 2019 The Amber Authors. +// +// 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. + +#include "src/datum_type.h" +#include "gtest/gtest.h" + +namespace amber { + +using DatumTypeTest = testing::Test; + +struct Data { + DataType type; + uint32_t row_count; + FormatType format_type; +}; +using DatumTypeTestFormat = testing::TestWithParam<Data>; +TEST_P(DatumTypeTestFormat, ToFormat) { + auto test_data = GetParam(); + + DatumType dt; + dt.SetType(test_data.type); + dt.SetRowCount(test_data.row_count); + + auto fmt = dt.AsFormat(); + ASSERT_TRUE(fmt != nullptr); + EXPECT_EQ(test_data.format_type, fmt->GetFormatType()); +} +INSTANTIATE_TEST_CASE_P( + DatumTypeTestFormat, + DatumTypeTestFormat, + testing::Values( + Data{DataType::kInt8, 1, FormatType::kR8_SINT}, + Data{DataType::kInt8, 2, FormatType::kR8G8_SINT}, + Data{DataType::kInt8, 3, FormatType::kR8G8B8_SINT}, + Data{DataType::kInt8, 4, FormatType::kR8G8B8A8_SINT}, + Data{DataType::kInt16, 1, FormatType::kR16_SINT}, + Data{DataType::kInt16, 2, FormatType::kR16G16_SINT}, + Data{DataType::kInt16, 3, FormatType::kR16G16B16_SINT}, + Data{DataType::kInt16, 4, FormatType::kR16G16B16A16_SINT}, + Data{DataType::kInt32, 1, FormatType::kR32_SINT}, + Data{DataType::kInt32, 2, FormatType::kR32G32_SINT}, + Data{DataType::kInt32, 3, FormatType::kR32G32B32_SINT}, + Data{DataType::kInt32, 4, FormatType::kR32G32B32A32_SINT}, + Data{DataType::kInt64, 1, FormatType::kR64_SINT}, + Data{DataType::kInt64, 2, FormatType::kR64G64_SINT}, + Data{DataType::kInt64, 3, FormatType::kR64G64B64_SINT}, + Data{DataType::kInt64, 4, FormatType::kR64G64B64A64_SINT}, + + Data{DataType::kUint8, 1, FormatType::kR8_UINT}, + Data{DataType::kUint8, 2, FormatType::kR8G8_UINT}, + Data{DataType::kUint8, 3, FormatType::kR8G8B8_UINT}, + Data{DataType::kUint8, 4, FormatType::kR8G8B8A8_UINT}, + Data{DataType::kUint16, 1, FormatType::kR16_UINT}, + Data{DataType::kUint16, 2, FormatType::kR16G16_UINT}, + Data{DataType::kUint16, 3, FormatType::kR16G16B16_UINT}, + Data{DataType::kUint16, 4, FormatType::kR16G16B16A16_UINT}, + Data{DataType::kUint32, 1, FormatType::kR32_UINT}, + Data{DataType::kUint32, 2, FormatType::kR32G32_UINT}, + Data{DataType::kUint32, 3, FormatType::kR32G32B32_UINT}, + Data{DataType::kUint32, 4, FormatType::kR32G32B32A32_UINT}, + Data{DataType::kUint64, 1, FormatType::kR64_UINT}, + Data{DataType::kUint64, 2, FormatType::kR64G64_UINT}, + Data{DataType::kUint64, 3, FormatType::kR64G64B64_UINT}, + Data{DataType::kUint64, 4, FormatType::kR64G64B64A64_UINT}, + + Data{DataType::kFloat, 1, FormatType::kR32_SFLOAT}, + Data{DataType::kFloat, 2, FormatType::kR32G32_SFLOAT}, + Data{DataType::kFloat, 3, FormatType::kR32G32B32_SFLOAT}, + Data{DataType::kFloat, 4, FormatType::kR32G32B32A32_SFLOAT}, + + Data{DataType::kDouble, 1, FormatType::kR64_SFLOAT}, + Data{DataType::kDouble, 2, FormatType::kR64G64_SFLOAT}, + Data{DataType::kDouble, 3, FormatType::kR64G64B64_SFLOAT}, + Data{ + DataType::kDouble, 4, + FormatType::kR64G64B64A64_SFLOAT}), ); // NOLINT(whitespace/parens) + +} // namespace amber |