Changeset 3782d66 in opengl-game for vulkan-game.cpp
- Timestamp:
- Nov 22, 2019, 9:21:37 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1802a41
- Parents:
- aa00bf2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
raa00bf2 r3782d66 27 27 28 28 modelMvpMats = {}; 29 shipMvpMats = {}; 29 30 } 30 31 … … 245 246 overlayPipeline.createDescriptorSets(swapChainImages); 246 247 248 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos)); 249 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color)); 250 251 createUniformBuffers<UBO_MvpMat>(uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 252 253 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 254 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 255 256 shipPipeline.addObject({ 257 //back 258 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 259 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 260 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 261 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 262 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 263 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 264 265 // left back 266 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 267 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 268 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 269 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 270 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 271 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 272 273 // right back 274 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 275 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 276 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 277 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 278 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 279 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 280 281 // left mid 282 {{-0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 283 {{-0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 284 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 285 {{-0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 286 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 287 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 288 289 // right mid 290 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 291 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 292 {{ 0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 293 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 0.3f}}, 294 {{ 0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 295 {{ 0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 296 297 // left front 298 {{ 0.0f, 0.0f, -3.5f}, {0.0f, 0.0f, 1.0f}}, 299 {{-0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 300 {{-0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 301 302 // right front 303 {{ 0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 304 {{ 0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 305 {{ 0.0f, 0.0f, -3.5f}, {0.0f, 0.0f, 1.0f}}, 306 307 // top back 308 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 309 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 310 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 311 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 312 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 313 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 314 315 // bottom back 316 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 317 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 318 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 319 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, 320 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 321 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 322 323 // top mid 324 {{-0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 325 {{ -0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 326 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 327 {{ -0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 328 {{ 0.5f, 0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 329 {{ 0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 330 331 // bottom mid 332 {{ -0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 333 {{-0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 334 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 335 {{ 0.5f, 0.0f, -2.0f}, {0.0f, 0.0f, 1.0f}}, 336 {{-0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 337 {{ 0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 1.0f}}, 338 339 // top front 340 {{-0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 341 {{ 0.25f, 0.3f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 342 {{ 0.0f, 0.0f, -3.5f}, {0.0f, 0.0f, 0.3f}}, 343 344 // bottom front 345 {{ 0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 346 {{-0.25f, 0.0f, -3.0f}, {0.0f, 0.0f, 0.3f}}, 347 {{ 0.0f, 0.0f, -3.5f}, {0.0f, 0.0f, 0.3f}}, 348 349 // left wing start back 350 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 351 {{ -1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 352 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 353 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 354 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 355 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 356 357 // left wing start top 358 {{ -0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 359 {{ -1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 360 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 361 {{ -0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 362 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 363 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 364 365 // left wing start front 366 {{ -0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 367 {{ -0.5f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 368 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 369 {{ -0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 370 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 371 {{ -1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 372 373 // left wing start bottom 374 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 375 {{ -1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 376 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 377 {{ -0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 378 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 379 {{ -0.5f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 380 381 // left wing end outside 382 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 383 {{ -2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 384 {{ -1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 385 386 // left wing end top 387 {{ -1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 388 {{ -2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 389 {{ -1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 390 391 // left wing end front 392 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 393 {{ -2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 394 {{ -1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 395 396 // left wing end bottom 397 {{ -1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 398 {{ -2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 399 {{ -1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 400 401 // right wing start back 402 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 403 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 404 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 405 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 406 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 407 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 408 409 // right wing start top 410 {{ 1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 411 {{ 0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 412 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 413 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 414 {{ 0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 415 {{ 0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 416 417 // right wing start front 418 {{ 0.5f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 419 {{ 0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 420 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 421 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 422 {{ 0.5f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 423 {{ 1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 424 425 // right wing start bottom 426 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 427 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 428 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 429 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 430 {{ 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 431 {{ 0.5f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 432 433 // right wing end outside 434 {{ 2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 435 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 436 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 437 438 // right wing end top 439 {{ 2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 440 {{ 1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 441 {{ 1.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 442 443 // right wing end front 444 {{ 2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 445 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 446 {{ 1.3f, 0.3f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 447 448 // right wing end bottom 449 {{ 2.2f, 0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}}, 450 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 451 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 452 }, { 453 0, 1, 2, 3, 4, 5, 454 6, 7, 8, 9, 10, 11, 455 12, 13, 14, 15, 16, 17, 456 18, 19, 20, 21, 22, 23, 457 24, 25, 26, 27, 28, 29, 458 30, 31, 32, 459 33, 34, 35, 460 36, 37, 38, 39, 40, 41, 461 42, 43, 44, 45, 46, 47, 462 48, 49, 50, 51, 52, 53, 463 54, 55, 56, 57, 58, 59, 464 60, 61, 62, 465 63, 64, 65, 466 66, 67, 68, 69, 70, 71, 467 72, 73, 74, 75, 76, 77, 468 78, 79, 80, 81, 82, 83, 469 84, 85, 86, 87, 88, 89, 470 90, 91, 92, 471 93, 94, 95, 472 96, 97, 98, 473 99, 100, 101, 474 102, 103, 104, 105, 106, 107, 475 108, 109, 110, 111, 112, 113, 476 114, 115, 116, 117, 118, 119, 477 120, 121, 122, 123, 124, 125, 478 126, 127, 128, 479 129, 130, 131, 480 132, 133, 134, 481 135, 136, 137, 482 }, commandPool, graphicsQueue); 483 484 shipPipeline.createDescriptorSetLayout(); 485 shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv"); 486 shipPipeline.createDescriptorPool(swapChainImages); 487 shipPipeline.createDescriptorSets(swapChainImages); 488 247 489 cout << "Created all the graphics pipelines" << endl; 248 490 … … 258 500 overlayPipeline = GraphicsPipeline_Vulkan<OverlayVertex>(physicalDevice, device, renderPass, 259 501 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 4, 6); 502 503 shipPipeline = GraphicsPipeline_Vulkan<ShipVertex>(physicalDevice, device, renderPass, 504 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138); 260 505 } 261 506 … … 280 525 modelMvpMats.view = view; 281 526 modelMvpMats.proj = proj; 527 528 mat4 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)); 529 mat4 R_model(1.0f); 530 531 shipMvpMats.model = T_model * R_model * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 532 shipMvpMats.view = view; 533 shipMvpMats.proj = proj; 282 534 } 283 535 … … 363 615 364 616 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory[currentImage], modelMvpMats); 617 618 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[currentImage], shipMvpMats); 365 619 } 366 620 … … 465 719 modelPipeline.cleanupBuffers(); 466 720 overlayPipeline.cleanupBuffers(); 721 shipPipeline.cleanupBuffers(); 467 722 468 723 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { … … 945 1200 946 1201 modelPipeline.createRenderCommands(commandBuffers[i], i); 1202 shipPipeline.createRenderCommands(commandBuffers[i], i); 1203 1204 // Always render this pipeline last 947 1205 overlayPipeline.createRenderCommands(commandBuffers[i], i); 948 1206 … … 1011 1269 overlayPipeline.createDescriptorSets(swapChainImages); 1012 1270 1271 createUniformBuffers<UBO_MvpMat>(uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 1272 1273 shipPipeline.updateRenderPass(renderPass); 1274 shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv"); 1275 shipPipeline.createDescriptorPool(swapChainImages); 1276 shipPipeline.createDescriptorSets(swapChainImages); 1277 1013 1278 createCommandBuffers(); 1014 1279 } … … 1025 1290 modelPipeline.cleanup(); 1026 1291 overlayPipeline.cleanup(); 1292 shipPipeline.cleanup(); 1027 1293 1028 1294 vkDestroyRenderPass(device, renderPass, nullptr); … … 1038 1304 vkFreeMemory(device, uniformBuffersMemory[i], nullptr); 1039 1305 } 1040 } 1306 1307 for (size_t i = 0; i < uniformBuffers_shipPipeline.size(); i++) { 1308 vkDestroyBuffer(device, uniformBuffers_shipPipeline[i], nullptr); 1309 vkFreeMemory(device, uniformBuffersMemory_shipPipeline[i], nullptr); 1310 } 1311 }
Note:
See TracChangeset
for help on using the changeset viewer.