MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / get_attribute_format

Function get_attribute_format

framework/gltf_loader.cpp:151–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149};
150
151inline VkFormat get_attribute_format(const tinygltf::Model *model, uint32_t accessorId)
152{
153 assert(accessorId < model->accessors.size());
154 auto &accessor = model->accessors[accessorId];
155
156 VkFormat format;
157
158 switch (accessor.componentType)
159 {
160 case TINYGLTF_COMPONENT_TYPE_BYTE:
161 {
162 static const std::map<int, VkFormat> mapped_format = {{TINYGLTF_TYPE_SCALAR, VK_FORMAT_R8_SINT},
163 {TINYGLTF_TYPE_VEC2, VK_FORMAT_R8G8_SINT},
164 {TINYGLTF_TYPE_VEC3, VK_FORMAT_R8G8B8_SINT},
165 {TINYGLTF_TYPE_VEC4, VK_FORMAT_R8G8B8A8_SINT}};
166
167 format = mapped_format.at(accessor.type);
168
169 break;
170 }
171 case TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE:
172 {
173 static const std::map<int, VkFormat> mapped_format = {{TINYGLTF_TYPE_SCALAR, VK_FORMAT_R8_UINT},
174 {TINYGLTF_TYPE_VEC2, VK_FORMAT_R8G8_UINT},
175 {TINYGLTF_TYPE_VEC3, VK_FORMAT_R8G8B8_UINT},
176 {TINYGLTF_TYPE_VEC4, VK_FORMAT_R8G8B8A8_UINT}};
177
178 static const std::map<int, VkFormat> mapped_format_normalize = {{TINYGLTF_TYPE_SCALAR, VK_FORMAT_R8_UNORM},
179 {TINYGLTF_TYPE_VEC2, VK_FORMAT_R8G8_UNORM},
180 {TINYGLTF_TYPE_VEC3, VK_FORMAT_R8G8B8_UNORM},
181 {TINYGLTF_TYPE_VEC4, VK_FORMAT_R8G8B8A8_UNORM}};
182
183 if (accessor.normalized)
184 {
185 format = mapped_format_normalize.at(accessor.type);
186 }
187 else
188 {
189 format = mapped_format.at(accessor.type);
190 }
191
192 break;
193 }
194 case TINYGLTF_COMPONENT_TYPE_SHORT:
195 {
196 static const std::map<int, VkFormat> mapped_format = {{TINYGLTF_TYPE_SCALAR, VK_FORMAT_R8_SINT},
197 {TINYGLTF_TYPE_VEC2, VK_FORMAT_R8G8_SINT},
198 {TINYGLTF_TYPE_VEC3, VK_FORMAT_R8G8B8_SINT},
199 {TINYGLTF_TYPE_VEC4, VK_FORMAT_R8G8B8A8_SINT}};
200
201 format = mapped_format.at(accessor.type);
202
203 break;
204 }
205 case TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT:
206 {
207 static const std::map<int, VkFormat> mapped_format = {{TINYGLTF_TYPE_SCALAR, VK_FORMAT_R16_UINT},
208 {TINYGLTF_TYPE_VEC2, VK_FORMAT_R16G16_UINT},

Callers 2

load_sceneMethod · 0.85
load_modelMethod · 0.85

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected