| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// SPDX-License-Identifier: BSD-3-Clause |
| 2 |
|
|
#pragma once |
| 3 |
|
|
|
| 4 |
|
|
#include <array> |
| 5 |
|
|
#include <cstdint> |
| 6 |
|
|
#include <cstring> |
| 7 |
|
|
#include <string> |
| 8 |
|
|
#include <type_traits> |
| 9 |
|
|
#include <vector> |
| 10 |
|
|
|
| 11 |
|
|
#include "chrono_batch_render/stage/schema/primvars.h" |
| 12 |
|
|
#include "chrono_batch_render/stage/schema/types.h" |
| 13 |
|
|
#include "chrono_batch_render/util/span.h" |
| 14 |
|
|
|
| 15 |
|
|
namespace chrono::batch_render { |
| 16 |
|
|
|
| 17 |
|
|
enum class Interpolation : uint32_t; |
| 18 |
|
|
|
| 19 |
|
|
template <class T> constexpr PrimvarType kPrimvarType = PrimvarType::Float; |
| 20 |
|
|
template <> inline constexpr PrimvarType kPrimvarType<Float2> = PrimvarType::Float2; |
| 21 |
|
|
template <> inline constexpr PrimvarType kPrimvarType<Float3> = PrimvarType::Float3; |
| 22 |
|
|
template <> inline constexpr PrimvarType kPrimvarType<Float4> = PrimvarType::Float4; |
| 23 |
|
|
template <> inline constexpr PrimvarType kPrimvarType<Double3> = PrimvarType::Float3; |
| 24 |
|
|
template <> inline constexpr PrimvarType kPrimvarType<int32_t> = PrimvarType::Int; |
| 25 |
|
|
|
| 26 |
1/1
✓ Branch 1 taken 50 times.
|
51 |
struct Primvar { |
| 27 |
|
|
std::string name; |
| 28 |
|
|
PrimvarType type = PrimvarType::Float; |
| 29 |
|
|
Interpolation interpolation{}; |
| 30 |
|
|
uint32_t elementSize = 1; |
| 31 |
|
|
std::vector<uint32_t> words; |
| 32 |
|
|
std::vector<int32_t> indices; |
| 33 |
|
|
|
| 34 |
|
|
template <class T> |
| 35 |
|
55 |
static Primvar Create(std::string name, Interpolation interpolation, Span<const T> values, |
| 36 |
|
|
std::vector<int32_t> indices = {}) { |
| 37 |
|
|
static_assert(std::is_same_v<T, float> || std::is_same_v<T, Float2> || |
| 38 |
|
|
std::is_same_v<T, Float3> || std::is_same_v<T, Float4> || |
| 39 |
|
|
std::is_same_v<T, double> || std::is_same_v<T, Double3> || |
| 40 |
|
|
std::is_same_v<T, int32_t>); |
| 41 |
|
55 |
Primvar primvar{std::move(name), kPrimvarType<T>, interpolation}; |
| 42 |
|
|
if constexpr (std::is_same_v<T, double> || std::is_same_v<T, Double3>) { |
| 43 |
4/4
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Double3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Double3 const>, std::vector<int, std::allocator<int> >):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<double const>, std::vector<int, std::allocator<int> >):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
5 |
for (const T& value : values) { |
| 44 |
|
|
std::array<double, sizeof(T) / 8> components; |
| 45 |
|
3 |
std::memcpy(components.data(), &value, sizeof(T)); |
| 46 |
4/4
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Double3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Double3 const>, std::vector<int, std::allocator<int> >):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<double const>, std::vector<int, std::allocator<int> >):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
8 |
for (const double component : components) { |
| 47 |
2/2
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Double3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Double3 const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 3 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<double const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 2 times.
|
5 |
const float narrowed = float(component); |
| 48 |
|
|
uint32_t word; |
| 49 |
|
5 |
std::memcpy(&word, &narrowed, sizeof(word)); |
| 50 |
2/2
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Double3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Double3 const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 3 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<double const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 2 times.
|
5 |
primvar.words.push_back(word); |
| 51 |
|
|
} |
| 52 |
|
|
} |
| 53 |
|
|
} else { |
| 54 |
3/3
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Float2>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Float2 const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 30 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Float3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<chrono::batch_render::Float3 const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 13 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<float>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, chrono::batch_render::Span<float const>, std::vector<int, std::allocator<int> >):
✓ Branch 1 taken 10 times.
|
53 |
primvar.words.resize(values.size_bytes() / sizeof(uint32_t)); |
| 55 |
|
53 |
std::memcpy(primvar.words.data(), values.data(), values.size_bytes()); |
| 56 |
|
|
} |
| 57 |
|
55 |
primvar.indices = std::move(indices); |
| 58 |
|
55 |
return primvar; |
| 59 |
|
✗ |
} |
| 60 |
|
|
|
| 61 |
|
|
template <class T> |
| 62 |
|
55 |
static Primvar Create(std::string name, Interpolation interpolation, |
| 63 |
|
|
const std::vector<T>& values, std::vector<int32_t> indices = {}) { |
| 64 |
7/7
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Double3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, std::vector<chrono::batch_render::Double3, std::allocator<chrono::batch_render::Double3> > const&, std::vector<int, std::allocator<int> >):
✓ Branch 3 taken 1 time.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Float2>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, std::vector<chrono::batch_render::Float2, std::allocator<chrono::batch_render::Float2> > const&, std::vector<int, std::allocator<int> >):
✓ Branch 3 taken 27 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<chrono::batch_render::Float3>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, std::vector<chrono::batch_render::Float3, std::allocator<chrono::batch_render::Float3> > const&, std::vector<int, std::allocator<int> >):
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 7 times.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, std::vector<double, std::allocator<double> > const&, std::vector<int, std::allocator<int> >):
✓ Branch 3 taken 1 time.
chrono::batch_render::Primvar chrono::batch_render::Primvar::Create<float>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, chrono::batch_render::Interpolation, std::vector<float, std::allocator<float> > const&, std::vector<int, std::allocator<int> >):
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 3 times.
|
110 |
return Create(std::move(name), interpolation, Span<const T>(values), std::move(indices)); |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
71 |
uint32_t ValueCount() const { |
| 68 |
3/5
<unknown function 26>:
✓ Branch 1 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 6 not taken.
<unknown function 35>:
✓ Branch 1 taken 1 time.
|
71 |
return uint32_t(words.size() / (PrimvarComponents(type) * elementSize)); |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
49 |
template <class T> std::vector<T> Values() const { |
| 72 |
|
49 |
std::vector<T> values(words.size() * sizeof(uint32_t) / sizeof(T)); |
| 73 |
|
49 |
std::memcpy(static_cast<void*>(values.data()), words.data(), values.size() * sizeof(T)); |
| 74 |
|
49 |
return values; |
| 75 |
|
|
} |
| 76 |
|
|
}; |
| 77 |
|
|
|
| 78 |
|
|
} |
| 79 |
|
|
|