----------------------------------------------------------------------------- Purpose: create a sea of cubes -----------------------------------------------------------------------------
| 2330 | // Purpose: create a sea of cubes |
| 2331 | //----------------------------------------------------------------------------- |
| 2332 | void CMainApplication::SetupScene() |
| 2333 | { |
| 2334 | if ( !m_pHMD ) |
| 2335 | return; |
| 2336 | |
| 2337 | std::vector<float> vertdataarray; |
| 2338 | |
| 2339 | Matrix4 matScale; |
| 2340 | matScale.scale( m_fScale, m_fScale, m_fScale ); |
| 2341 | Matrix4 matTransform; |
| 2342 | matTransform.translate( |
| 2343 | -( (float)m_iSceneVolumeWidth * m_fScaleSpacing ) / 2.f, |
| 2344 | -( (float)m_iSceneVolumeHeight * m_fScaleSpacing ) / 2.f, |
| 2345 | -( (float)m_iSceneVolumeDepth * m_fScaleSpacing ) / 2.f); |
| 2346 | |
| 2347 | Matrix4 mat = matScale * matTransform; |
| 2348 | |
| 2349 | for( int z = 0; z< m_iSceneVolumeDepth; z++ ) |
| 2350 | { |
| 2351 | for( int y = 0; y< m_iSceneVolumeHeight; y++ ) |
| 2352 | { |
| 2353 | for( int x = 0; x< m_iSceneVolumeWidth; x++ ) |
| 2354 | { |
| 2355 | AddCubeToScene( mat, vertdataarray ); |
| 2356 | mat = mat * Matrix4().translate( m_fScaleSpacing, 0, 0 ); |
| 2357 | } |
| 2358 | mat = mat * Matrix4().translate( -((float)m_iSceneVolumeWidth) * m_fScaleSpacing, m_fScaleSpacing, 0 ); |
| 2359 | } |
| 2360 | mat = mat * Matrix4().translate( 0, -((float)m_iSceneVolumeHeight) * m_fScaleSpacing, m_fScaleSpacing ); |
| 2361 | } |
| 2362 | m_uiVertcount = vertdataarray.size()/5; |
| 2363 | |
| 2364 | // Create the vertex buffer and fill with data |
| 2365 | if ( !CreateVulkanBuffer( m_pDevice, m_physicalDeviceMemoryProperties, &vertdataarray[ 0 ], vertdataarray.size() * sizeof( float ), |
| 2366 | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, &m_pSceneVertexBuffer, &m_pSceneVertexBufferMemory ) ) |
| 2367 | { |
| 2368 | return; |
| 2369 | } |
| 2370 | |
| 2371 | // Create constant buffer to hold the per-eye CB data |
| 2372 | for ( uint32_t nEye = 0; nEye < 2; nEye++ ) |
| 2373 | { |
| 2374 | VkBufferCreateInfo bufferCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 2375 | bufferCreateInfo.size = sizeof( Matrix4 ); |
| 2376 | bufferCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 2377 | vkCreateBuffer( m_pDevice, &bufferCreateInfo, nullptr, &m_pSceneConstantBuffer[ nEye ] ); |
| 2378 | |
| 2379 | VkMemoryRequirements memoryRequirements = { }; |
| 2380 | vkGetBufferMemoryRequirements( m_pDevice, m_pSceneConstantBuffer[ nEye ], &memoryRequirements ); |
| 2381 | |
| 2382 | VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO }; |
| 2383 | MemoryTypeFromProperties( m_physicalDeviceMemoryProperties, memoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, &allocInfo.memoryTypeIndex ); |
| 2384 | allocInfo.allocationSize = memoryRequirements.size; |
| 2385 | |
| 2386 | vkAllocateMemory( m_pDevice, &allocInfo, nullptr, &m_pSceneConstantBufferMemory[ nEye ] ); |
| 2387 | vkBindBufferMemory( m_pDevice, m_pSceneConstantBuffer[ nEye ], m_pSceneConstantBufferMemory[ nEye ], 0 ); |
| 2388 | |
| 2389 | // Map and keep mapped persistently |
nothing calls this directly
no test coverage detected