Changeset e09ad38 in opengl-game
- Timestamp:
- Jul 14, 2019, 4:15:14 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 84216c7
- Parents:
- c458c58
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rc458c58 re09ad38 18 18 #include <optional> 19 19 #include <algorithm> 20 #include <fstream> 20 21 21 22 #include "game-gui-sdl.hpp" … … 55 56 vector<VkPresentModeKHR> presentModes; 56 57 }; 57 58 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(59 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,60 VkDebugUtilsMessageTypeFlagsEXT messageType,61 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,62 void* pUserData) {63 cerr << "validation layer: " << pCallbackData->pMessage << endl;64 65 return VK_FALSE;66 }67 58 68 59 VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, … … 568 559 569 560 void createGraphicsPipeline() { 561 auto vertShaderCode = readFile("shaders/vert.spv"); 562 auto fragShaderCode = readFile("shaders/frag.spv"); 563 564 VkShaderModule vertShaderModule = createShaderModule(vertShaderCode); 565 VkShaderModule fragShaderModule = createShaderModule(fragShaderCode); 566 567 VkPipelineShaderStageCreateInfo vertShaderStageInfo = {}; 568 vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; 569 vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; 570 vertShaderStageInfo.module = vertShaderModule; 571 vertShaderStageInfo.pName = "main"; 572 573 VkPipelineShaderStageCreateInfo fragShaderStageInfo = {}; 574 fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; 575 fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; 576 fragShaderStageInfo.module = fragShaderModule; 577 fragShaderStageInfo.pName = "main"; 578 579 VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; 580 581 vkDestroyShaderModule(device, vertShaderModule, nullptr); 582 vkDestroyShaderModule(device, fragShaderModule, nullptr); 583 } 584 585 VkShaderModule createShaderModule(const vector<char>& code) { 586 VkShaderModuleCreateInfo createInfo = {}; 587 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; 588 createInfo.codeSize = code.size(); 589 createInfo.pCode = reinterpret_cast<const uint32_t*>(code.data()); 590 591 VkShaderModule shaderModule; 592 if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) { 593 throw runtime_error("failed to create shader module!"); 594 } 595 596 return shaderModule; 570 597 } 571 598 … … 587 614 } 588 615 589 /* 616 /**/ 590 617 SDL_FillRect(sdlSurface, nullptr, SDL_MapRGB(sdlSurface->format, 0xFF, 0xFF, 0xFF)); 591 618 592 619 SDL_UpdateWindowSurface(window); 593 */620 /**/ 594 621 } 595 622 } … … 616 643 gui->Shutdown(); 617 644 delete gui; 645 } 646 647 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( 648 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, 649 VkDebugUtilsMessageTypeFlagsEXT messageType, 650 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, 651 void* pUserData) { 652 cerr << "validation layer: " << pCallbackData->pMessage << endl; 653 654 return VK_FALSE; 655 } 656 657 static vector<char> readFile(const string& filename) { 658 ifstream file(filename, ios::ate | ios::binary); 659 660 if (!file.is_open()) { 661 throw runtime_error("failed to open file!"); 662 } 663 664 size_t fileSize = (size_t)file.tellg(); 665 vector<char> buffer(fileSize); 666 667 file.seekg(0); 668 file.read(buffer.data(), fileSize); 669 670 file.close(); 671 672 return buffer; 618 673 } 619 674 };
Note:
See TracChangeset
for help on using the changeset viewer.