diff --git a/shaders/shader.vert b/shaders/shader.vert index f4f4c7d..6ab16da 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -1,5 +1,9 @@ #version 450 +layout(location = 0) in vec3 inPosition; +layout(location = 1) in vec3 inNormal; +layout(location = 2) in vec2 inUV; + layout(location = 0) out vec3 fragColor; vec2 positions[3] = vec2[]( @@ -15,6 +19,6 @@ vec3 colors[3] = vec3[] ( ); void main() { - gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); - fragColor = colors[gl_VertexIndex]; + gl_Position = vec4(inPosition, 1.0); + fragColor = inNormal; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index cdf424a..72b4d00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,6 +143,7 @@ private: const std::string engineName = "The Best Engine"; const std::vector deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, "VK_KHR_portability_subset", }; const std::vector validationLayers = { @@ -267,41 +268,7 @@ private: if (!ret) { throw std::runtime_error("Failed to load GLTF: " + err); } - for (const auto& mesh : model.meshes) { - for (const auto& primitive : mesh.primitives) { - // 1. Проверка атрибутов - auto posAttr = primitive.attributes.find("POSITION"); - auto normalAttr = primitive.attributes.find("NORMAL"); - if (posAttr == primitive.attributes.end() || normalAttr == primitive.attributes.end()) { - std::cerr << "Missing required attributes in primitive" << std::endl; - continue; - } - - // 2. Загрузка вершин - const auto& positionAccessor = model.accessors[posAttr->second]; - // ... (остальной код загрузки позиций) - - // 3. Загрузка индексов с проверкой типа - const auto& indexAccessor = model.accessors[primitive.indices]; - if (indexAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) { - const uint16_t* indicesSrc = reinterpret_cast( - &indexBuffer.data[indexView.byteOffset + indexAccessor.byteOffset]); - // Конвертация в uint32_t - for (size_t i = 0; i < indexAccessor.count; i++) { - indices.push_back(static_cast(indicesSrc[i])); - } - } - else if (indexAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) { - const uint32_t* indicesSrc = reinterpret_cast( - &indexBuffer.data[indexView.byteOffset + indexAccessor.byteOffset]); - indices.insert(indices.end(), indicesSrc, indicesSrc + indexAccessor.count); - } - else { - std::cerr << "Unsupported index type: " << indexAccessor.componentType << std::endl; - } - } - } // Получение данных вершин и индексов for (const auto& mesh : model.meshes) { for (const auto& primitive : mesh.primitives) { @@ -626,6 +593,11 @@ private: createInfo.ppEnabledExtensionNames = deviceExtensions.data(); createInfo.enabledLayerCount = 0; + VkPhysicalDeviceSynchronization2Features syncFeatures{}; + syncFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES; + syncFeatures.synchronization2 = true; + createInfo.pNext = &syncFeatures; + if (enableValidationLayers) { createInfo.enabledLayerCount = validationLayers.size(); createInfo.ppEnabledLayerNames = validationLayers.data(); @@ -1029,7 +1001,12 @@ private: scissor.extent = swapChainExtent; vkCmdSetScissor(commandBuffer, 0, 1, &scissor); - vkCmdDraw(commandBuffer, 3, 1, 0, 0); + // TODO: Add VertexBUffer binding + VkDeviceSize offsets[] = {0}; + vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer, offsets); + vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); + + vkCmdDraw(commandBuffer, indices.size(), 1, 0, 0); vkCmdEndRenderPass(commandBuffer);