applyRotation

Updates the dynamic uniform buffer with the new rotation value

This is called on every frame to update the dynamic uniform buffer with the new rotation value. An offset is used to point to the correct slice of the buffer that corresponds to the current frame. The current frame is specified by the parameter, idx.

This memory is mapped persistently so it does not need to be mapped again on every frame. The pointer to this consistently mapped memory is the variable appManager.dynamicUniformBufferData.mappedData.

Calculate the offset.

 	VkDeviceSize offset = (appManager.offset * idx);
 

Update the angle of rotation and calculate the transformation matrix using the fixed projection matrix and a freshly-calculated rotation matrix.

The glm library is very useful for these calculations.

 	appManager.angle += 0.02f;
 	glm::mat4 mvp = viewProj * glm::rotate(appManager.angle, glm::vec3(.0f, .0f, 1.0f));
 

Copy the matrix to the mapped memory using the offset calculated above.

 	memcpy(static_cast<unsigned char*>(appManager.dynamicUniformBufferData.mappedData) + appManager.dynamicUniformBufferData.bufferInfo.range * idx, &mvp, sizeof(mvp));
 
 	VkMappedMemoryRange mapMemRange = {
 		VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
 		nullptr,
 		appManager.dynamicUniformBufferData.memory,
 		offset,
 		appManager.dynamicUniformBufferData.bufferInfo.range,
 	};
 	

ONLY flush the memory if it does not support VK_MEMORY_PROPERTY_HOST_COHERENT_BIT.

 	if ((appManager.dynamicUniformBufferData.memPropFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0)
 	{
 		vkFlushMappedMemoryRanges(appManager.device, 1, &mapMemRange);
 	}