Changeset f97c5e7 in opengl-game for vulkan-game.cpp
- Timestamp:
- Nov 22, 2019, 7:58:45 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- aa00bf2
- Parents:
- 8e02b6b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r8e02b6b rf97c5e7 184 184 185 185 createImageResources(); 186 187 186 createFramebuffers(); 188 createUniformBuffers(); 189 190 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>(physicalDevice, device, renderPass, 191 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24); 187 188 // TODO: Figure out how much of ubo creation and associated variables should be in the pipeline class 189 // Maybe combine the ubo-related objects into a new class 190 191 initGraphicsPipelines(); 192 193 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos)); 194 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color)); 195 modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord)); 196 197 createUniformBuffers<UBO_MvpMat>(uniformBuffers, uniformBuffersMemory, uniformBufferInfoList); 198 199 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 200 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList); 201 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 202 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); 192 203 193 204 modelPipeline.addObject({ … … 209 220 }, commandPool, graphicsQueue); 210 221 211 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));212 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color));213 modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord));214 215 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,216 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList);217 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,218 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);219 220 222 modelPipeline.createDescriptorSetLayout(); 221 223 modelPipeline.createPipeline("shaders/scene-vert.spv", "shaders/scene-frag.spv"); … … 223 225 modelPipeline.createDescriptorSets(swapChainImages); 224 226 225 overlayPipeline = GraphicsPipeline_Vulkan<OverlayVertex>(physicalDevice, device, renderPass, 226 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 4, 6); 227 overlayPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos)); 228 overlayPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord)); 229 230 overlayPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 231 VK_SHADER_STAGE_FRAGMENT_BIT, &sdlOverlayImageDescriptor); 227 232 228 233 overlayPipeline.addObject({ … … 235 240 }, commandPool, graphicsQueue); 236 241 237 overlayPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos));238 overlayPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord));239 240 overlayPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,241 VK_SHADER_STAGE_FRAGMENT_BIT, &sdlOverlayImageDescriptor);242 243 242 overlayPipeline.createDescriptorSetLayout(); 244 243 overlayPipeline.createPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv"); … … 253 252 } 254 253 254 void VulkanGame::initGraphicsPipelines() { 255 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>(physicalDevice, device, renderPass, 256 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24); 257 258 overlayPipeline = GraphicsPipeline_Vulkan<OverlayVertex>(physicalDevice, device, renderPass, 259 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 4, 6); 260 } 261 255 262 // TODO: Maybe changes the name to initScene() or something similar 256 263 void VulkanGame::initMatrices() { … … 263 270 mat4 pitch_mat = rotate(mat4(1.0f), radians(-cam_pitch), vec3(1.0f, 0.0f, 0.0f)); 264 271 265 mat4 R = pitch_mat * yaw_mat; 266 mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 267 268 modelMvpMats.view = R * T; 269 270 modelMvpMats.proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 271 modelMvpMats.proj[1][1] *= -1; // flip the y-axis so that +y is up 272 mat4 R_view = pitch_mat * yaw_mat; 273 mat4 T_view = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 274 mat4 view = R_view * T_view; 275 276 mat4 proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 277 proj[1][1] *= -1; // flip the y-axis so that +y is up 278 279 modelMvpMats.model = mat4(1.0f); 280 modelMvpMats.view = view; 281 modelMvpMats.proj = proj; 272 282 } 273 283 … … 895 905 } 896 906 897 void VulkanGame::createUniformBuffers() {898 VkDeviceSize bufferSize = sizeof(UBO_MvpMat);899 900 uniformBuffers.resize(swapChainImages.size());901 uniformBuffersMemory.resize(swapChainImages.size());902 uniformBufferInfoList.resize(swapChainImages.size());903 904 for (size_t i = 0; i < swapChainImages.size(); i++) {905 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,906 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,907 uniformBuffers[i], uniformBuffersMemory[i]);908 909 uniformBufferInfoList[i].buffer = uniformBuffers[i];910 uniformBufferInfoList[i].offset = 0;911 uniformBufferInfoList[i].range = sizeof(UBO_MvpMat);912 }913 }914 915 907 void VulkanGame::createCommandBuffers() { 916 908 commandBuffers.resize(swapChainImages.size()); … … 1006 998 depthImage, graphicsQueue); 1007 999 createFramebuffers(); 1008 createUniformBuffers(); 1000 1001 createUniformBuffers<UBO_MvpMat>(uniformBuffers, uniformBuffersMemory, uniformBufferInfoList); 1009 1002 1010 1003 modelPipeline.updateRenderPass(renderPass);
Note:
See TracChangeset
for help on using the changeset viewer.