Changeset 5a1ace0 in opengl-game
- Timestamp:
- Feb 16, 2020, 8:18:50 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 2d87297
- Parents:
- 4ece3bf
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (02/14/20 20:41:35)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (02/16/20 20:18:50)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/scene.vert
r4ece3bf r5a1ace0 18 18 layout(location = 1) in vec3 inColor; 19 19 layout(location = 2) in vec2 inTexCoord; 20 layout(location = 3) in uint obj_index; 20 21 21 22 layout(location = 0) out vec3 fragColor; … … 26 27 fragTexCoord = inTexCoord; 27 28 28 gl_Position = ubo.proj * ubo.view * sbo.objects[ 0].model * vec4(inPosition, 1.0);29 gl_Position = ubo.proj * ubo.view * sbo.objects[obj_index].model * vec4(inPosition, 1.0); 29 30 } -
vulkan-game.cpp
r4ece3bf r5a1ace0 197 197 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color)); 198 198 modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord)); 199 modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 199 200 200 201 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, … … 213 214 214 215 addObject(modelObjects, modelPipeline, 215 {216 addObjectIndex<ModelVertex>(modelObjects.size(), { 216 217 {{-0.5f, -0.5f, -2.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 217 218 {{ 0.5f, -0.5f, -2.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 218 219 {{ 0.5f, 0.5f, -2.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 219 220 {{-0.5f, 0.5f, -2.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 220 } , {221 }), { 221 222 0, 1, 2, 2, 3, 0 222 223 }); 223 224 224 225 addObject(modelObjects, modelPipeline, 225 {226 addObjectIndex<ModelVertex>(modelObjects.size(), { 226 227 {{-0.5f, -0.5f, -1.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 227 228 {{ 0.5f, -0.5f, -1.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 228 229 {{ 0.5f, 0.5f, -1.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 229 230 {{-0.5f, 0.5f, -1.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 230 } , {231 }), { 231 232 0, 1, 2, 2, 3, 0 232 233 }); … … 699 700 700 701 addObject(modelObjects, modelPipeline, 701 {702 addObjectIndex<ModelVertex>(modelObjects.size(), { 702 703 {{-0.5f, -0.5f, zOffset}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 703 704 {{ 0.5f, -0.5f, zOffset}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 704 705 {{ 0.5f, 0.5f, zOffset}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 705 706 {{-0.5f, 0.5f, zOffset}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 706 } , {707 }), { 707 708 0, 1, 2, 2, 3, 0 708 709 }); … … 774 775 so_Asteroid.model = asteroidObjects[0].model_transform * asteroidObjects[0].model_base; 775 776 776 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats); 777 778 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_scenePipeline[currentImage], so_Object); 779 780 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[currentImage], ship_VP_mats); 781 782 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_shipPipeline[currentImage], so_Ship); 783 784 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], asteroid_VP_mats); 785 786 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], so_Asteroid); 777 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], 0, object_VP_mats); 778 779 for (size_t i = 0; i < modelObjects.size(); i++) { 780 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_scenePipeline[currentImage], 781 i, so_Object); 782 } 783 784 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[currentImage], 0, ship_VP_mats); 785 786 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_shipPipeline[currentImage], 0, so_Ship); 787 788 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], 0, asteroid_VP_mats); 789 790 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], 0, so_Asteroid); 787 791 } 788 792 -
vulkan-game.hpp
r4ece3bf r5a1ace0 22 22 #endif 23 23 24 struct OverlayVertex { 25 vec3 pos; 26 vec2 texCoord; 27 }; 28 24 29 struct ModelVertex { 25 30 vec3 pos; 26 31 vec3 color; 27 32 vec2 texCoord; 28 }; 29 30 struct OverlayVertex { 31 vec3 pos; 32 vec2 texCoord; 33 unsigned int objIndex; 33 34 }; 34 35 -
vulkan-utils.hpp
r4ece3bf r5a1ace0 95 95 96 96 template<class DataType> 97 static void copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, const DataType& srcData); 97 static void copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 98 const DataType& srcData); 98 99 99 100 static bool hasStencilComponent(VkFormat format); … … 125 126 } 126 127 127 // TODO: Change copyDataToMemory so it can accept offsets for the data source and destination128 128 template<class DataType> 129 void VulkanUtils::copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, const DataType& srcData) { 129 void VulkanUtils::copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 130 const DataType& srcData) { 130 131 void* data; 131 vkMapMemory(device, bufferMemory, 0, sizeof(DataType), 0, &data); 132 133 vkMapMemory(device, bufferMemory, offset * sizeof(DataType), sizeof(DataType), 0, &data); 132 134 memcpy(data, &srcData, sizeof(DataType)); 133 135 vkUnmapMemory(device, bufferMemory);
Note:
See TracChangeset
for help on using the changeset viewer.