Esempio n. 1
0
        private void CreateVertexBuffer(VkDevice device, VkPhysicalDevice physicalDevice)
        {
            // 初期頂点データ.
            var vertices = new Vertex[3] {
                new Vertex()
                {
                    Position = new vec3(-.5f, 0.5f, 0.0f), Color = new vec4(0.0f, 0.0f, 1.0f, 1.0f)
                },
                new Vertex()
                {
                    Position = new vec3(+.5f, 0.5f, 0.0f), Color = new vec4(0.0f, 1.0f, 0.0f, 1.0f)
                },
                new Vertex()
                {
                    Position = new vec3(0.0f, -.5f, 0.0f), Color = new vec4(1.0f, 0.0f, 0.0f, 1.0f)
                },
            };
            var bufferSize = Marshal.SizeOf <Vertex>() * vertices.Length;
            VkMemoryPropertyFlags memoryFlags = VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;

            SampleHelpers.CreateBuffer(device, physicalDevice, bufferSize, VkBufferUsageFlags.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, memoryFlags, out m_vertexBuffer, out m_vertexBufferMemory);

            // 初期頂点データの書き込み.
            MappedMemoryStream mappedStream;

            VulkanAPI.vkMapMemory(device, m_vertexBufferMemory, 0, VkDeviceSize.VK_WHOLE_SIZE, 0, out mappedStream);
            mappedStream.Write(vertices);
            VulkanAPI.vkUnmapMemory(device, m_vertexBufferMemory);
        }
Esempio n. 2
0
        public void CreateCubeModel(VkDevice device, VkPhysicalDevice physicalDevice)
        {
            var cubeVertices = CubeModel.GetVertices();
            var cubeIndices  = CubeModel.GetIndices();
            var vbSize       = Marshal.SizeOf <CubeModel.Vertex>() * cubeVertices.Length;
            var ibSize       = Marshal.SizeOf <ushort>() * cubeIndices.Length;

            VkMemoryPropertyFlags flags = VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;

            SampleHelpers.CreateBuffer(device, physicalDevice, vbSize, VkBufferUsageFlags.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, flags, out m_vertexBuffer, out m_vertexBufferMemory);
            SampleHelpers.CreateBuffer(device, physicalDevice, ibSize, VkBufferUsageFlags.VK_BUFFER_USAGE_INDEX_BUFFER_BIT, flags, out m_indexBuffer, out m_indexBufferMemory);

            // 初期データの書き込み.
            MappedMemoryStream mapped;

            VulkanAPI.vkMapMemory(device, m_vertexBufferMemory, 0, VkDeviceSize.VK_WHOLE_SIZE, 0, out mapped);
            mapped.Write(cubeVertices);
            VulkanAPI.vkUnmapMemory(device, m_vertexBufferMemory);
            VulkanAPI.vkMapMemory(device, m_indexBufferMemory, 0, VkDeviceSize.VK_WHOLE_SIZE, 0, out mapped);
            mapped.Write(cubeIndices);
            VulkanAPI.vkUnmapMemory(device, m_indexBufferMemory);

            m_resourceManager.Regist(m_vertexBuffer, m_vertexBufferMemory);
            m_resourceManager.Regist(m_indexBuffer, m_indexBufferMemory);
        }
Esempio n. 3
0
        private void CreateUniformBuffer(VkDevice device, VkPhysicalDevice physicalDevice)
        {
            var bufferSize = Marshal.SizeOf <Transform>();
            VkMemoryPropertyFlags memoryFlags = VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;

            SampleHelpers.CreateBuffer(device, physicalDevice, bufferSize, VkBufferUsageFlags.VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, memoryFlags, out m_uniformBuffer, out m_uniformBufferMemory);
        }