File include/jrf/vertices.h changed (mode: 100644) (index 9ec76b3..21794c0) |
8 |
8 |
|
|
9 |
9 |
namespace jrf |
namespace jrf |
10 |
10 |
{ |
{ |
11 |
|
struct Vertices |
|
12 |
|
{ |
|
13 |
|
enum Format : uint8_t { |
|
14 |
|
F16, F32, F64, |
|
15 |
|
I8, I16, I32, I64, |
|
16 |
|
U8, U16, U32, U64 |
|
17 |
|
}; |
|
18 |
|
|
|
19 |
|
constexpr static const uint8_t FORMAT_SIZE[] = { |
|
20 |
|
2, 4, 8, |
|
21 |
|
1, 2, 4, 8, |
|
22 |
|
1, 2, 4, 8 |
|
23 |
|
}; |
|
24 |
|
|
|
25 |
|
struct Attribute |
|
|
11 |
|
struct Vertices |
|
12 |
|
{ |
|
13 |
|
enum Format : uint16_t { |
|
14 |
|
F16, F32, F64, |
|
15 |
|
I8, I16, I32, I64, |
|
16 |
|
U8, U16, U32, U64 |
|
17 |
|
}; |
|
18 |
|
|
|
19 |
|
constexpr static const uint8_t FORMAT_SIZE[] = { |
|
20 |
|
2, 4, 8, |
|
21 |
|
1, 2, 4, 8, |
|
22 |
|
1, 2, 4, 8 |
|
23 |
|
}; |
|
24 |
|
|
|
25 |
|
enum AttributeType { |
|
26 |
|
POSITION, TEXTURE_COORDINATE, NORMAL, |
|
27 |
|
RESERVED_BEGIN, |
|
28 |
|
RESERVED_COUNT = 16 |
|
29 |
|
}; |
|
30 |
|
static_assert (RESERVED_BEGIN < RESERVED_COUNT); |
|
31 |
|
constexpr static const uint8_t ATTRIBUTE_COUNT = RESERVED_COUNT; |
|
32 |
|
|
|
33 |
|
struct Attribute { |
|
34 |
|
uint32_t offset; |
|
35 |
|
uint16_t dimension_count; |
|
36 |
|
Format format; |
|
37 |
|
}; |
|
38 |
|
using Attributes = jl::array<Attribute, ATTRIBUTE_COUNT>; |
|
39 |
|
|
|
40 |
|
Attributes attributes; |
|
41 |
|
uint64_t vecs_count; |
|
42 |
|
uint64_t vecs_size; |
|
43 |
|
void *p_vecs; |
|
44 |
|
|
|
45 |
|
void destroy() { jl::deallocate(&p_vecs); } |
|
46 |
|
|
|
47 |
|
template<typename IO = jl::io_agent> |
|
48 |
|
[[nodiscard]] Result read(IO *p_mediator) |
|
49 |
|
{ |
|
50 |
|
auto *p_io = jl::io_agent_p_alt_cast(p_mediator);\ |
|
51 |
|
|
|
52 |
|
if (not p_io->read_items(&attributes)) |
|
53 |
|
return Result::MEDIATOR_ERROR; |
|
54 |
|
|
|
55 |
|
if (not p_io->read_items(&vecs_size)) |
|
56 |
|
return Result::MEDIATOR_ERROR; |
|
57 |
|
|
|
58 |
|
if (not p_io->read_items(&vecs_count)) |
|
59 |
|
return Result::MEDIATOR_ERROR; |
|
60 |
|
|
|
61 |
|
if (vecs_size == 0) |
|
62 |
|
p_vecs = nullptr; |
|
63 |
|
else |
26 |
64 |
{ |
{ |
27 |
|
uint8_t dimention_count; |
|
28 |
|
Format format; |
|
29 |
|
}; |
|
30 |
|
|
|
31 |
|
constexpr static const uint8_t MAX_ATTR_COUNT = 8; |
|
32 |
|
|
|
33 |
|
jl::array<Attribute, MAX_ATTR_COUNT> attributes; |
|
34 |
|
uint16_t attr_count; |
|
35 |
|
uint64_t vecs_count; |
|
36 |
|
uint64_t vecs_size; |
|
37 |
|
void *p_vecs; |
|
38 |
|
|
|
39 |
|
void destroy() { |
|
40 |
|
jl::deallocate(&p_vecs); |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
template<typename IO = jl::io_agent> |
|
44 |
|
[[nodiscard]] Result read(IO *p_mediator) |
|
45 |
|
{ |
|
46 |
|
auto *p_io = jl::io_agent_p_alt_cast(p_mediator); |
|
47 |
|
if (not p_io->read_items(&attr_count)) |
|
48 |
|
return Result::MEDIATOR_ERROR; |
|
49 |
|
|
|
50 |
|
if (attr_count != 0) |
|
51 |
|
if (not p_io->read_items(&attributes)) |
|
52 |
|
return Result::MEDIATOR_ERROR; |
|
53 |
|
|
|
54 |
|
if (not p_io->read_items(&vecs_size)) |
|
55 |
|
return Result::MEDIATOR_ERROR; |
|
56 |
|
|
|
57 |
|
if (not p_io->read_items(&vecs_count)) |
|
58 |
|
return Result::MEDIATOR_ERROR; |
|
59 |
|
|
|
60 |
|
if (vecs_size == 0) |
|
61 |
|
p_vecs = nullptr; |
|
62 |
|
else |
|
63 |
|
{ |
|
64 |
|
if (not jl::allocate_bytes(&p_vecs, vecs_size)) |
|
65 |
|
return Result::MEDIATOR_ERROR; |
|
66 |
|
if (not p_io->read_bytes(p_vecs, vecs_size)) |
|
67 |
|
return this->destroy(), Result::MEDIATOR_ERROR; |
|
68 |
|
} |
|
69 |
|
|
|
70 |
|
return Result::SUCCESS; |
|
|
65 |
|
if (not jl::allocate_bytes(&p_vecs, vecs_size)) |
|
66 |
|
return Result::MEDIATOR_ERROR; |
|
67 |
|
if (not p_io->read_bytes(p_vecs, vecs_size)) |
|
68 |
|
return this->destroy(), Result::MEDIATOR_ERROR; |
71 |
69 |
} |
} |
72 |
70 |
|
|
73 |
|
template<typename IO = jl::io_agent> |
|
74 |
|
[[nodiscard]] Result write(IO *p_mediator) const |
|
75 |
|
{ |
|
76 |
|
auto *p_io = jl::io_agent_p_alt_cast(p_mediator); |
|
77 |
|
if (not p_io->write_items(&attr_count)) |
|
78 |
|
return Result::MEDIATOR_ERROR; |
|
79 |
|
if (not p_io->write_items(&attributes)) |
|
80 |
|
return Result::MEDIATOR_ERROR; |
|
81 |
|
if (not p_io->write_items(&vecs_size)) |
|
82 |
|
return Result::MEDIATOR_ERROR; |
|
83 |
|
if (not p_io->write_items(&vecs_count)) |
|
84 |
|
return Result::MEDIATOR_ERROR; |
|
85 |
|
if (not p_io->write_bytes(p_vecs, vecs_size)) |
|
86 |
|
return Result::MEDIATOR_ERROR; |
|
87 |
|
|
|
88 |
|
return Result::SUCCESS; |
|
89 |
|
} |
|
90 |
|
}; |
|
|
71 |
|
return Result::SUCCESS; |
|
72 |
|
} |
|
73 |
|
|
|
74 |
|
template<typename IO = jl::io_agent> |
|
75 |
|
[[nodiscard]] Result write(IO *p_mediator) const |
|
76 |
|
{ |
|
77 |
|
auto *p_io = jl::io_agent_p_alt_cast(p_mediator); |
|
78 |
|
if (not p_io->write_items(&attributes)) |
|
79 |
|
return Result::MEDIATOR_ERROR; |
|
80 |
|
if (not p_io->write_items(&vecs_size)) |
|
81 |
|
return Result::MEDIATOR_ERROR; |
|
82 |
|
if (not p_io->write_items(&vecs_count)) |
|
83 |
|
return Result::MEDIATOR_ERROR; |
|
84 |
|
if (not p_io->write_bytes(p_vecs, vecs_size)) |
|
85 |
|
return Result::MEDIATOR_ERROR; |
|
86 |
|
|
|
87 |
|
return Result::SUCCESS; |
|
88 |
|
} |
|
89 |
|
}; |
91 |
90 |
} |
} |