14
14
namespace nbl ::asset
15
15
{
16
16
17
- #if 0
18
17
core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCube (const hlsl::float32_t3 size) const
19
18
{
20
19
using namespace hlsl ;
21
20
22
-
23
- // {0u,EF_R32G32B32_SFLOAT,offsetof(CubeVertex,pos)},
24
- // {0u,EF_R8G8B8A8_UNORM,offsetof(CubeVertex,color)},
25
- // {0u,EF_R8G8_USCALED,offsetof(CubeVertex,uv)},
26
- // {0u,EF_R8G8B8_SSCALED,offsetof(CubeVertex,normal)}
21
+ auto retval = core::make_smart_refctd_ptr<ICPUPolygonGeometry>();
22
+ retval->setIndexing (IPolygonGeometryBase::TriangleList ());
27
23
28
24
// Create indices
25
+ using index_t = uint16_t ;
29
26
{
30
- retval.indexCount = 36u;
31
- auto indices = asset::ICPUBuffer::create({ sizeof(uint16_t)*retval.indexCount }) ;
32
- indices->addUsageFlags(asset:: IBuffer::EUF_INDEX_BUFFER_BIT);
33
- auto u = reinterpret_cast<uint16_t *>(indices->getPointer());
27
+ constexpr auto IndexCount = 36u ;
28
+ constexpr auto bytesize = sizeof (index_t ) * IndexCount ;
29
+ auto indices = ICPUBuffer::create ({bytesize, IBuffer::EUF_INDEX_BUFFER_BIT} );
30
+ auto u = reinterpret_cast <index_t *>(indices->getPointer ());
34
31
for (uint32_t i=0u ; i<6u ; ++i)
35
32
{
36
33
u[i*6 +0 ] = 4 *i+0 ;
@@ -40,104 +37,147 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCube(const h
40
37
u[i*6 +4 ] = 4 *i+2 ;
41
38
u[i*6 +5 ] = 4 *i+3 ;
42
39
}
43
- retval.indexBuffer = {0ull,std::move(indices)};
40
+ shapes::AABB<4 ,index_t > aabb;
41
+ aabb.minVx [0 ] = 0 ;
42
+ aabb.maxVx [0 ] = 23 ;
43
+ retval->setIndexView ({
44
+ .composed = {
45
+ .encodedDataRange = {.u16 =aabb},
46
+ .stride = sizeof (index_t ),
47
+ .format = EF_R16_UINT,
48
+ .rangeFormat = IGeometryBase::EAABBFormat::U16
49
+ },
50
+ .src = {.offset =0 ,.size =bytesize,.buffer =std::move (indices)}
51
+ });
44
52
}
45
53
46
- // Create vertices
47
- auto vertices = asset::ICPUBuffer::create({ 24u*vertexSize });
48
- vertices->addUsageFlags(IBuffer::EUF_VERTEX_BUFFER_BIT);
49
- CubeVertex* ptr = (CubeVertex*)vertices->getPointer();
50
-
51
- const core::vector3d<int8_t> normals[6] =
54
+ //
55
+ const hlsl::float32_t3 pos[8 ] =
52
56
{
53
- core::vector3d<int8_t>(0, 0, 1),
54
- core::vector3d<int8_t>(1, 0, 0),
55
- core::vector3d<int8_t>(0, 0, -1),
56
- core::vector3d<int8_t>(-1, 0, 0),
57
- core::vector3d<int8_t>(0, 1, 0),
58
- core::vector3d<int8_t>(0, -1, 0)
57
+ hlsl::float32_t3 (-0 .5f ,-0 .5f , 0 .5f ) * size,
58
+ hlsl::float32_t3 (0 .5f ,-0 .5f , 0 .5f ) * size,
59
+ hlsl::float32_t3 (0 .5f , 0 .5f , 0 .5f ) * size,
60
+ hlsl::float32_t3 (-0 .5f , 0 .5f , 0 .5f ) * size,
61
+ hlsl::float32_t3 (0 .5f ,-0 .5f ,-0 .5f ) * size,
62
+ hlsl::float32_t3 (-0 .5f , 0 .5f ,-0 .5f ) * size,
63
+ hlsl::float32_t3 (-0 .5f ,-0 .5f ,-0 .5f ) * size,
64
+ hlsl::float32_t3 (0 .5f , 0 .5f ,-0 .5f ) * size
59
65
};
60
- const float32_t3 pos[8] =
66
+ constexpr auto Dim = 4 ; // for now because no reliable RGB10A2 encode and scant support for 24-bit UTB formats
67
+ const hlsl::vector<int8_t ,Dim> norm[6 ] =
61
68
{
62
- float32_t3(-0.5f,-0.5f, 0.5f)*size,
63
- float32_t3( 0.5f,-0.5f, 0.5f)*size,
64
- float32_t3( 0.5f, 0.5f, 0.5f)*size,
65
- float32_t3(-0.5f, 0.5f, 0.5f)*size,
66
- float32_t3( 0.5f,-0.5f,-0.5f)*size,
67
- float32_t3(-0.5f, 0.5f,-0.5f)*size,
68
- float32_t3(-0.5f,-0.5f,-0.5f)*size,
69
- float32_t3( 0.5f, 0.5f,-0.5f)*size
69
+ hlsl::vector<int8_t ,Dim>(0 , 0 , 127 , 0 ),
70
+ hlsl::vector<int8_t ,Dim>(127 , 0 , 0 , 0 ),
71
+ hlsl::vector<int8_t ,Dim>(0 , 0 ,-127 , 0 ),
72
+ hlsl::vector<int8_t ,Dim>(-127 , 0 , 0 , 0 ),
73
+ hlsl::vector<int8_t ,Dim>(0 , 127 , 0 , 0 ),
74
+ hlsl::vector<int8_t ,Dim>(0 ,-127 , 0 , 0 )
70
75
};
71
- const core::vector2d <uint8_t> uvs [4] =
76
+ const hlsl::vector <uint8_t , 2 > uv [4 ] =
72
77
{
73
- core::vector2d <uint8_t>(0, 1 ),
74
- core::vector2d <uint8_t>(1, 1 ),
75
- core::vector2d <uint8_t>(1, 0),
76
- core::vector2d <uint8_t>(0, 0)
78
+ hlsl::vector <uint8_t , 2 >( 0 , 127 ),
79
+ hlsl::vector <uint8_t , 2 >( 127 , 127 ),
80
+ hlsl::vector <uint8_t , 2 >( 127 , 0 ),
81
+ hlsl::vector <uint8_t , 2 >( 0 , 0 )
77
82
};
78
83
84
+ // Create vertex attributes with NONE usage because we have no clue how they'll be used
85
+ hlsl::float32_t3* positions;
86
+ hlsl::vector<int8_t ,Dim>* normals;
87
+ hlsl::vector<uint8_t ,2 >* uvs;
88
+ {
89
+ {
90
+ auto buff = ICPUBuffer::create ({sizeof (pos),IBuffer::EUF_NONE});
91
+ positions = reinterpret_cast <decltype (positions)>(buff->getPointer ());
92
+ shapes::AABB<4 ,float32_t > aabb;
93
+ aabb.maxVx = float32_t4 (size*0 .5f ,0 .f );
94
+ aabb.minVx = -aabb.maxVx ;
95
+ retval->setPositionView ({
96
+ .composed = {
97
+ .encodedDataRange = {.f32 =aabb},
98
+ .stride = sizeof (pos[0 ]),
99
+ .format = EF_R32G32B32_SFLOAT,
100
+ .rangeFormat = IGeometryBase::EAABBFormat::F32
101
+ },
102
+ .src = {.offset =0 ,.size =sizeof (pos),.buffer =std::move (buff)}
103
+ });
104
+ }
105
+ {
106
+ auto buff = ICPUBuffer::create ({sizeof (norm),IBuffer::EUF_NONE});
107
+ normals = reinterpret_cast <decltype (normals)>(buff->getPointer ());
108
+ shapes::AABB<4 ,int8_t > aabb;
109
+ aabb.maxVx = hlsl::vector<int8_t ,4 >(127 ,127 ,127 ,0 );
110
+ aabb.minVx = -aabb.maxVx ;
111
+ retval->setPositionView ({
112
+ .composed = {
113
+ .encodedDataRange = {.s8 =aabb},
114
+ .stride = sizeof (norm[0 ]),
115
+ .format = EF_R8G8B8A8_SNORM,
116
+ .rangeFormat = IGeometryBase::EAABBFormat::S8_NORM
117
+ },
118
+ .src = {.offset =0 ,.size =sizeof (norm),.buffer =std::move (buff)}
119
+ });
120
+ }
121
+ {
122
+ auto buff = ICPUBuffer::create ({sizeof (uv),IBuffer::EUF_NONE});
123
+ uvs = reinterpret_cast <decltype (uvs)>(buff->getPointer ());
124
+ shapes::AABB<4 ,uint8_t > aabb;
125
+ aabb.minVx = hlsl::vector<uint8_t ,4 >(0 ,0 ,0 ,0 );
126
+ aabb.maxVx = hlsl::vector<uint8_t ,4 >(127 ,127 ,0 ,0 );
127
+ retval->setPositionView ({
128
+ .composed = {
129
+ .encodedDataRange = {.u8 =aabb},
130
+ .stride = sizeof (uv[0 ]),
131
+ .format = EF_R8G8_UNORM,
132
+ .rangeFormat = IGeometryBase::EAABBFormat::U8_NORM
133
+ },
134
+ .src = {.offset =0 ,.size =sizeof (uv),.buffer =std::move (buff)}
135
+ });
136
+ }
137
+ }
138
+
139
+ //
140
+ positions[0 ] = hlsl::float32_t3 (pos[0 ][0 ], pos[0 ][1 ], pos[0 ][2 ]);
141
+ positions[1 ] = hlsl::float32_t3 (pos[1 ][0 ], pos[1 ][1 ], pos[1 ][2 ]);
142
+ positions[2 ] = hlsl::float32_t3 (pos[2 ][0 ], pos[2 ][1 ], pos[2 ][2 ]);
143
+ positions[3 ] = hlsl::float32_t3 (pos[3 ][0 ], pos[3 ][1 ], pos[3 ][2 ]);
144
+ positions[4 ] = hlsl::float32_t3 (pos[1 ][0 ], pos[1 ][1 ], pos[1 ][2 ]);
145
+ positions[5 ] = hlsl::float32_t3 (pos[4 ][0 ], pos[4 ][1 ], pos[4 ][2 ]);
146
+ positions[6 ] = hlsl::float32_t3 (pos[7 ][0 ], pos[7 ][1 ], pos[7 ][2 ]);
147
+ positions[7 ] = hlsl::float32_t3 (pos[2 ][0 ], pos[2 ][1 ], pos[2 ][2 ]);
148
+ positions[8 ] = hlsl::float32_t3 (pos[4 ][0 ], pos[4 ][1 ], pos[4 ][2 ]);
149
+ positions[9 ] = hlsl::float32_t3 (pos[6 ][0 ], pos[6 ][1 ], pos[6 ][2 ]);
150
+ positions[10 ] = hlsl::float32_t3 (pos[5 ][0 ], pos[5 ][1 ], pos[5 ][2 ]);
151
+ positions[11 ] = hlsl::float32_t3 (pos[7 ][0 ], pos[7 ][1 ], pos[7 ][2 ]);
152
+ positions[12 ] = hlsl::float32_t3 (pos[6 ][0 ], pos[6 ][1 ], pos[6 ][2 ]);
153
+ positions[13 ] = hlsl::float32_t3 (pos[0 ][0 ], pos[0 ][1 ], pos[0 ][2 ]);
154
+ positions[14 ] = hlsl::float32_t3 (pos[3 ][0 ], pos[3 ][1 ], pos[3 ][2 ]);
155
+ positions[15 ] = hlsl::float32_t3 (pos[5 ][0 ], pos[5 ][1 ], pos[5 ][2 ]);
156
+ positions[16 ] = hlsl::float32_t3 (pos[3 ][0 ], pos[3 ][1 ], pos[3 ][2 ]);
157
+ positions[17 ] = hlsl::float32_t3 (pos[2 ][0 ], pos[2 ][1 ], pos[2 ][2 ]);
158
+ positions[18 ] = hlsl::float32_t3 (pos[7 ][0 ], pos[7 ][1 ], pos[7 ][2 ]);
159
+ positions[19 ] = hlsl::float32_t3 (pos[5 ][0 ], pos[5 ][1 ], pos[5 ][2 ]);
160
+ positions[20 ] = hlsl::float32_t3 (pos[0 ][0 ], pos[0 ][1 ], pos[0 ][2 ]);
161
+ positions[21 ] = hlsl::float32_t3 (pos[6 ][0 ], pos[6 ][1 ], pos[6 ][2 ]);
162
+ positions[22 ] = hlsl::float32_t3 (pos[4 ][0 ], pos[4 ][1 ], pos[4 ][2 ]);
163
+ positions[23 ] = hlsl::float32_t3 (pos[1 ][0 ], pos[1 ][1 ], pos[1 ][2 ]);
164
+
165
+ //
79
166
for (size_t f=0ull ; f<6ull ; ++f)
80
167
{
81
168
const size_t v = f*4ull ;
82
169
83
170
for (size_t i=0ull ; i<4ull ; ++i)
84
171
{
85
- const core::vector3d<int8_t>& n = normals[f];
86
- const core::vector2d<uint8_t>& uv = uvs[i];
87
- ptr[v+i].setColor(255, 255, 255, 255);
88
- ptr[v+i].setNormal(n.X, n.Y, n.Z);
89
- ptr[v+i].setUv(uv.X, uv.Y);
90
- }
91
-
92
- switch (f)
93
- {
94
- case 0:
95
- ptr[v+0].setPos(pos[0].X, pos[0].Y, pos[0].Z);
96
- ptr[v+1].setPos(pos[1].X, pos[1].Y, pos[1].Z);
97
- ptr[v+2].setPos(pos[2].X, pos[2].Y, pos[2].Z);
98
- ptr[v+3].setPos(pos[3].X, pos[3].Y, pos[3].Z);
99
- break;
100
- case 1:
101
- ptr[v+0].setPos(pos[1].X, pos[1].Y, pos[1].Z);
102
- ptr[v+1].setPos(pos[4].X, pos[4].Y, pos[4].Z);
103
- ptr[v+2].setPos(pos[7].X, pos[7].Y, pos[7].Z);
104
- ptr[v+3].setPos(pos[2].X, pos[2].Y, pos[2].Z);
105
- break;
106
- case 2:
107
- ptr[v+0].setPos(pos[4].X, pos[4].Y, pos[4].Z);
108
- ptr[v+1].setPos(pos[6].X, pos[6].Y, pos[6].Z);
109
- ptr[v+2].setPos(pos[5].X, pos[5].Y, pos[5].Z);
110
- ptr[v+3].setPos(pos[7].X, pos[7].Y, pos[7].Z);
111
- break;
112
- case 3:
113
- ptr[v+0].setPos(pos[6].X, pos[6].Y, pos[6].Z);
114
- ptr[v+2].setPos(pos[3].X, pos[3].Y, pos[3].Z);
115
- ptr[v+1].setPos(pos[0].X, pos[0].Y, pos[0].Z);
116
- ptr[v+3].setPos(pos[5].X, pos[5].Y, pos[5].Z);
117
- break;
118
- case 4:
119
- ptr[v+0].setPos(pos[3].X, pos[3].Y, pos[3].Z);
120
- ptr[v+1].setPos(pos[2].X, pos[2].Y, pos[2].Z);
121
- ptr[v+2].setPos(pos[7].X, pos[7].Y, pos[7].Z);
122
- ptr[v+3].setPos(pos[5].X, pos[5].Y, pos[5].Z);
123
- break;
124
- case 5:
125
- ptr[v+0].setPos(pos[0].X, pos[0].Y, pos[0].Z);
126
- ptr[v+1].setPos(pos[6].X, pos[6].Y, pos[6].Z);
127
- ptr[v+2].setPos(pos[4].X, pos[4].Y, pos[4].Z);
128
- ptr[v+3].setPos(pos[1].X, pos[1].Y, pos[1].Z);
129
- break;
172
+ normals[v+i] = norm[f];
173
+ uvs[v+i] = uv[i];
130
174
}
131
175
}
132
- retval.bindings[0] = {0ull,std::move(vertices)};
133
-
134
- // Recalculate bounding box
135
- retval.indexType = asset::EIT_16BIT;
136
- retval.bbox = core::aabbox3df(-size*0.5f,size*0.5f);
137
176
138
177
return retval;
139
178
}
140
179
180
+ #if 0
141
181
142
182
/*
143
183
a cylinder, a cone and a cross
0 commit comments