Compare commits
2 commits
9477f64d50
...
add71a5721
| Author | SHA1 | Date | |
|---|---|---|---|
| add71a5721 | |||
| 692fd70519 |
3 changed files with 333 additions and 30 deletions
|
|
@ -5,5 +5,5 @@ REM clang++ src/main.cpp -o build/window.exe -O0 -g -gcodeview -stdlib=libc++ -l
|
||||||
|
|
||||||
set VSCMD_SKIP_SENDTELEMETRY=1
|
set VSCMD_SKIP_SENDTELEMETRY=1
|
||||||
set VCPKG_KEEP_ENV_VARS=VSCMD_SKIP_SENDTELEMETRY
|
set VCPKG_KEEP_ENV_VARS=VSCMD_SKIP_SENDTELEMETRY
|
||||||
vcvarsall.bat x64 && cl.exe /Fe:build\window.exe /std:c++20 /Od /MDd /EHsc -I%VULKAN_SDK%/Include src/main.cpp user32.lib gdi32.lib kernel32.lib vulkan-1.lib SPIRV.lib SPIRV-Toolsd.lib SPIRV-Tools-diffd.lib SPIRV-Tools-optd.lib SPVRemapperd.lib glslangd.lib OSDependentd.lib GenericCodeGend.lib MachineIndependentd.lib glslang-default-resource-limitsd.lib /link /DEBUG:FULL /IGNORE:4099 /LIBPATH:%VULKAN_SDK%/Lib
|
vcvarsall.bat x64 && cl.exe /Fe:build\window.exe /Fo:build\ /std:c++20 /Zi /Od /MDd /EHsc -I%VULKAN_SDK%/Include src/main.cpp user32.lib gdi32.lib kernel32.lib vulkan-1.lib SPIRV.lib SPIRV-Toolsd.lib SPIRV-Tools-diffd.lib SPIRV-Tools-optd.lib SPVRemapperd.lib glslangd.lib OSDependentd.lib GenericCodeGend.lib MachineIndependentd.lib glslang-default-resource-limitsd.lib /link /DEBUG:FULL /IGNORE:4099 /LIBPATH:%VULKAN_SDK%/Lib
|
||||||
|
|
||||||
|
|
|
||||||
236
src/main.cpp
236
src/main.cpp
|
|
@ -39,6 +39,8 @@
|
||||||
#include <glslang/Include/glslang_c_interface.h>
|
#include <glslang/Include/glslang_c_interface.h>
|
||||||
#include <glslang/Public/resource_limits_c.h>
|
#include <glslang/Public/resource_limits_c.h>
|
||||||
|
|
||||||
|
#include "triangle.h"
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <winuser.h>
|
#include <winuser.h>
|
||||||
#include <wingdi.h>
|
#include <wingdi.h>
|
||||||
|
|
@ -520,12 +522,12 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
VkMemoryRequirements memoryRequirements;
|
VkMemoryRequirements memoryRequirements;
|
||||||
vkGetBufferMemoryRequirements(device, uniformData.buf, &memoryRequirements);
|
vkGetBufferMemoryRequirements(device, uniformData.buf, &memoryRequirements);
|
||||||
|
|
||||||
VkMemoryAllocateInfo memoryAllocInfo = {};
|
VkMemoryAllocateInfo uniformMemoryAllocInfo = {};
|
||||||
memoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
uniformMemoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
memoryAllocInfo.pNext = NULL;
|
uniformMemoryAllocInfo.pNext = NULL;
|
||||||
memoryAllocInfo.memoryTypeIndex = 0;
|
uniformMemoryAllocInfo.memoryTypeIndex = 0;
|
||||||
|
|
||||||
memoryAllocInfo.allocationSize = memoryRequirements.size;
|
uniformMemoryAllocInfo.allocationSize = memoryRequirements.size;
|
||||||
|
|
||||||
VkFlags requirements = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
VkFlags requirements = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
// Search memtypes to find first index with those properties
|
// Search memtypes to find first index with those properties
|
||||||
|
|
@ -533,15 +535,15 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
if ((memoryRequirements.memoryTypeBits & 1) == 1) {
|
if ((memoryRequirements.memoryTypeBits & 1) == 1) {
|
||||||
// Type is available, does it match user properties?
|
// Type is available, does it match user properties?
|
||||||
if ((memoryProperties.memoryTypes[i].propertyFlags & requirements) == requirements) {
|
if ((memoryProperties.memoryTypes[i].propertyFlags & requirements) == requirements) {
|
||||||
memoryAllocInfo.memoryTypeIndex = i;
|
uniformMemoryAllocInfo.memoryTypeIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memoryRequirements.memoryTypeBits >>= 1;
|
memoryRequirements.memoryTypeBits >>= 1;
|
||||||
}
|
}
|
||||||
// No memory types matched, return failure
|
// No memory types matched, return failure
|
||||||
assert(memoryAllocInfo.memoryTypeIndex && "No mappable, coherent memory");
|
assert(uniformMemoryAllocInfo.memoryTypeIndex && "No mappable, coherent memory");
|
||||||
|
|
||||||
result = vkAllocateMemory(device, &memoryAllocInfo, NULL, &(uniformData.mem));
|
result = vkAllocateMemory(device, &uniformMemoryAllocInfo, NULL, &(uniformData.mem));
|
||||||
assert(result == VK_SUCCESS);
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
uint8_t* pData; //VK_WHOLE_SIZE = through buffer end
|
uint8_t* pData; //VK_WHOLE_SIZE = through buffer end
|
||||||
|
|
@ -687,28 +689,28 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
// the color attachment's layout will be transitioned to
|
// the color attachment's layout will be transitioned to
|
||||||
// LAYOUT_PRESENT_SRC_KHR to be ready to present. This is all done as part
|
// LAYOUT_PRESENT_SRC_KHR to be ready to present. This is all done as part
|
||||||
// of the renderpass, no barriers are necessary.
|
// of the renderpass, no barriers are necessary.
|
||||||
VkAttachmentDescription attachments[1];
|
VkAttachmentDescription attachmentsDescription[1];
|
||||||
attachments[0].format = format;
|
attachmentsDescription[0].format = format;
|
||||||
attachments[0].samples = NUM_SAMPLES;
|
attachmentsDescription[0].samples = NUM_SAMPLES;
|
||||||
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachmentsDescription[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachmentsDescription[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachmentsDescription[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachmentsDescription[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
attachmentsDescription[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
attachmentsDescription[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
attachments[0].flags = 0;
|
attachmentsDescription[0].flags = 0;
|
||||||
|
|
||||||
// Depth
|
// Depth
|
||||||
/*
|
/*
|
||||||
* attachments[1].format = info.depth.format;
|
* attachmentsDescription[1].format = info.depth.format;
|
||||||
* attachments[1].samples = NUM_SAMPLES;
|
* attachmentsDescription[1].samples = NUM_SAMPLES;
|
||||||
* attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
* attachmentsDescription[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
* attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
* attachmentsDescription[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
* attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
* attachmentsDescription[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
* attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
* attachmentsDescription[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
* attachments[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
* attachmentsDescription[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
* attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
* attachmentsDescription[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
* attachments[1].flags = 0;
|
* attachmentsDescription[1].flags = 0;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VkAttachmentReference color_reference = {};
|
VkAttachmentReference color_reference = {};
|
||||||
|
|
@ -748,7 +750,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||||
renderPassInfo.pNext = NULL;
|
renderPassInfo.pNext = NULL;
|
||||||
renderPassInfo.attachmentCount = 1;
|
renderPassInfo.attachmentCount = 1;
|
||||||
renderPassInfo.pAttachments = attachments;
|
renderPassInfo.pAttachments = attachmentsDescription;
|
||||||
renderPassInfo.subpassCount = 1;
|
renderPassInfo.subpassCount = 1;
|
||||||
renderPassInfo.pSubpasses = &subpass;
|
renderPassInfo.pSubpasses = &subpass;
|
||||||
renderPassInfo.dependencyCount = 1;
|
renderPassInfo.dependencyCount = 1;
|
||||||
|
|
@ -804,7 +806,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
};
|
};
|
||||||
|
|
||||||
glslang_shader_t* shader = glslang_shader_create(&input);
|
glslang_shader_t* shader = glslang_shader_create(&input);
|
||||||
OutputDebugStringA("GLSL parse faild\n");
|
|
||||||
if (!glslang_shader_preprocess(shader, &input)) {
|
if (!glslang_shader_preprocess(shader, &input)) {
|
||||||
OutputDebugStringA("GLSL preprocessing fail\n");
|
OutputDebugStringA("GLSL preprocessing fail\n");
|
||||||
OutputDebugStringA(glslang_shader_get_info_log(shader));
|
OutputDebugStringA(glslang_shader_get_info_log(shader));
|
||||||
|
|
@ -949,6 +951,177 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
shaderStages[1].pName = "main";
|
shaderStages[1].pName = "main";
|
||||||
shaderStages[1].module = fragmentShader;
|
shaderStages[1].module = fragmentShader;
|
||||||
|
|
||||||
|
/* Framebuffer setup */
|
||||||
|
VkImageView attachments[1];
|
||||||
|
//attachments[1] = info.depth.view;
|
||||||
|
|
||||||
|
VkFramebufferCreateInfo framebufferInfo = {};
|
||||||
|
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
|
framebufferInfo.pNext = NULL;
|
||||||
|
framebufferInfo.renderPass = renderPass;
|
||||||
|
framebufferInfo.attachmentCount = 1;
|
||||||
|
framebufferInfo.pAttachments = attachments;
|
||||||
|
framebufferInfo.width = swapchainExtent.width;
|
||||||
|
framebufferInfo.height = swapchainExtent.height;
|
||||||
|
framebufferInfo.layers = 1;
|
||||||
|
|
||||||
|
VkFramebuffer* framebuffers;
|
||||||
|
uint32_t i;
|
||||||
|
framebuffers = (VkFramebuffer *)malloc(swapchainImageCount * sizeof(VkFramebuffer));
|
||||||
|
assert(framebuffers);
|
||||||
|
|
||||||
|
for (i = 0; i < swapchainImageCount; i++) {
|
||||||
|
attachments[0] = buffers[i].view;
|
||||||
|
result = vkCreateFramebuffer(device, &framebufferInfo, NULL, &framebuffers[i]);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Vertex buffer setup */
|
||||||
|
/*
|
||||||
|
* Similar to uniform buffer before
|
||||||
|
* Set up a vertex buffer:
|
||||||
|
* - Create a buffer
|
||||||
|
* - Map it and write the vertex data into it
|
||||||
|
* - Bind it using vkCmdBindVertexBuffers
|
||||||
|
* - Later, at pipeline creation,
|
||||||
|
* - fill in vertex input part of the pipeline with relevent data
|
||||||
|
*/
|
||||||
|
struct {
|
||||||
|
VkBuffer buf;
|
||||||
|
VkDeviceMemory mem;
|
||||||
|
VkDescriptorBufferInfo bufferInfo;
|
||||||
|
} vertexData;
|
||||||
|
VkVertexInputBindingDescription vertexInputBindingDescription;
|
||||||
|
VkVertexInputAttributeDescription vertexInputBindingAttributes[2];
|
||||||
|
|
||||||
|
//g_vb_solid_face_colors_Data = triangle vertex data array (triangle.h)
|
||||||
|
VkBufferCreateInfo vertexBufferInfo = {};
|
||||||
|
vertexBufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
|
vertexBufferInfo.pNext = NULL;
|
||||||
|
vertexBufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
|
||||||
|
vertexBufferInfo.size = sizeof(g_vb_solid_face_colors_Data);
|
||||||
|
vertexBufferInfo.queueFamilyIndexCount = 0;
|
||||||
|
vertexBufferInfo.pQueueFamilyIndices = NULL;
|
||||||
|
vertexBufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
|
vertexBufferInfo.flags = 0;
|
||||||
|
result = vkCreateBuffer(device, &vertexBufferInfo, NULL, &vertexData.buf);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
VkMemoryRequirements mem_reqs;
|
||||||
|
vkGetBufferMemoryRequirements(device, vertexData.buf, &mem_reqs);
|
||||||
|
|
||||||
|
VkMemoryAllocateInfo vertexMemoryAllocInfo = {};
|
||||||
|
vertexMemoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
|
vertexMemoryAllocInfo.pNext = NULL;
|
||||||
|
vertexMemoryAllocInfo.memoryTypeIndex = 0;
|
||||||
|
vertexMemoryAllocInfo.allocationSize = mem_reqs.size;
|
||||||
|
|
||||||
|
//same requirements as uniform
|
||||||
|
requirements = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
|
// Search memtypes to find first index with those properties
|
||||||
|
for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) {
|
||||||
|
if ((mem_reqs.memoryTypeBits & 1) == 1) {
|
||||||
|
// Type is available, does it match user properties?
|
||||||
|
if ((memoryProperties.memoryTypes[i].propertyFlags & requirements) == requirements) {
|
||||||
|
vertexMemoryAllocInfo.memoryTypeIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mem_reqs.memoryTypeBits >>= 1;
|
||||||
|
}
|
||||||
|
// No memory types matched, return failure
|
||||||
|
assert(vertexMemoryAllocInfo.memoryTypeIndex && "Vertex: No mappable, coherent memory");
|
||||||
|
|
||||||
|
result = vkAllocateMemory(device, &vertexMemoryAllocInfo, NULL, &(vertexData.mem));
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
//uint8_t *pData;
|
||||||
|
result = vkMapMemory(device, vertexData.mem, 0, mem_reqs.size, 0, (void **)&pData);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
memcpy(pData, g_vb_solid_face_colors_Data, sizeof(g_vb_solid_face_colors_Data));
|
||||||
|
|
||||||
|
vkUnmapMemory(device, vertexData.mem);
|
||||||
|
|
||||||
|
result = vkBindBufferMemory(device, vertexData.buf, vertexData.mem, 0);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
/* We won't use these here, but we will need this info when creating the
|
||||||
|
* pipeline */
|
||||||
|
vertexInputBindingDescription.binding = 0;
|
||||||
|
vertexInputBindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
vertexInputBindingDescription.stride = sizeof(g_vb_solid_face_colors_Data[0]);
|
||||||
|
|
||||||
|
vertexInputBindingAttributes[0].binding = 0; //location in glsl
|
||||||
|
vertexInputBindingAttributes[0].location = 0; //location in glsl
|
||||||
|
vertexInputBindingAttributes[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; //4byte pos def even if color flag
|
||||||
|
vertexInputBindingAttributes[0].offset = 0; // where to start looking from
|
||||||
|
vertexInputBindingAttributes[1].binding = 0;
|
||||||
|
vertexInputBindingAttributes[1].location = 1;
|
||||||
|
vertexInputBindingAttributes[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||||
|
vertexInputBindingAttributes[1].offset = 16;
|
||||||
|
|
||||||
|
const VkDeviceSize offsets[1] = {0};
|
||||||
|
|
||||||
|
/* We cannot bind the vertex buffer until we begin a renderpass */
|
||||||
|
VkClearValue clear_values[1];
|
||||||
|
clear_values[0].color.float32[0] = 0.2f;
|
||||||
|
clear_values[0].color.float32[1] = 0.2f;
|
||||||
|
clear_values[0].color.float32[2] = 0.2f;
|
||||||
|
clear_values[0].color.float32[3] = 0.2f;
|
||||||
|
//clear_values[1].depthStencil.depth = 1.0f;
|
||||||
|
//clear_values[1].depthStencil.stencil = 0;
|
||||||
|
|
||||||
|
/* I think repe and will repe later?
|
||||||
|
* VkSemaphore imageAcquiredSemaphore;
|
||||||
|
* VkSemaphoreCreateInfo imageAcquiredSemaphoreCreateInfo;
|
||||||
|
* imageAcquiredSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||||
|
* imageAcquiredSemaphoreCreateInfo.pNext = NULL;
|
||||||
|
* imageAcquiredSemaphoreCreateInfo.flags = 0;
|
||||||
|
*
|
||||||
|
* res = vkCreateSemaphore(info.device, &imageAcquiredSemaphoreCreateInfo, NULL, &imageAcquiredSemaphore);
|
||||||
|
* assert(res == VK_SUCCESS);
|
||||||
|
*
|
||||||
|
* // Get the index of the next available swapchain image:
|
||||||
|
* res = vkAcquireNextImageKHR(info.device, info.swap_chain, UINT64_MAX, imageAcquiredSemaphore, VK_NULL_HANDLE,
|
||||||
|
* &info.current_buffer);
|
||||||
|
* // TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR
|
||||||
|
* // return codes
|
||||||
|
* assert(res == VK_SUCCESS);
|
||||||
|
*/
|
||||||
|
|
||||||
|
VkCommandBufferBeginInfo cmdBufferBeginInfo = {};
|
||||||
|
cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
cmdBufferBeginInfo.pNext = NULL;
|
||||||
|
cmdBufferBeginInfo.flags = 0;
|
||||||
|
cmdBufferBeginInfo.pInheritanceInfo = NULL;
|
||||||
|
|
||||||
|
result = vkBeginCommandBuffer(cmd, &cmdBufferBeginInfo);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
VkRenderPassBeginInfo renderPassBeginInfo = {};
|
||||||
|
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
|
renderPassBeginInfo.pNext = NULL;
|
||||||
|
renderPassBeginInfo.renderPass = renderPass;
|
||||||
|
renderPassBeginInfo.framebuffer = framebuffers[currentBuffer];
|
||||||
|
renderPassBeginInfo.renderArea.offset.x = 0;
|
||||||
|
renderPassBeginInfo.renderArea.offset.y = 0;
|
||||||
|
renderPassBeginInfo.renderArea.extent.width = swapchainExtent.width;
|
||||||
|
renderPassBeginInfo.renderArea.extent.height = swapchainExtent.height;
|
||||||
|
renderPassBeginInfo.clearValueCount = 1;
|
||||||
|
renderPassBeginInfo.pClearValues = clear_values;
|
||||||
|
|
||||||
|
vkCmdBeginRenderPass(cmd, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
|
||||||
|
vkCmdBindVertexBuffers(cmd, 0, /* Start Binding */
|
||||||
|
1, /* Binding Count */
|
||||||
|
&vertexData.buf, /* pBuffers */
|
||||||
|
offsets); /* pOffsets */
|
||||||
|
|
||||||
|
vkCmdEndRenderPass(cmd);
|
||||||
|
//U_ASSERT_ONLY result
|
||||||
|
result = vkEndCommandBuffer(cmd);
|
||||||
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -962,6 +1135,11 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < swapchainImageCount; i++) {
|
||||||
|
vkDestroyFramebuffer(device, framebuffers[i], NULL);
|
||||||
|
}
|
||||||
|
free(framebuffers);
|
||||||
vkDestroyShaderModule(device, shaderStages[0].module, NULL);
|
vkDestroyShaderModule(device, shaderStages[0].module, NULL);
|
||||||
vkDestroyShaderModule(device, shaderStages[1].module, NULL);
|
vkDestroyShaderModule(device, shaderStages[1].module, NULL);
|
||||||
vkDestroyRenderPass(device, renderPass, NULL);
|
vkDestroyRenderPass(device, renderPass, NULL);
|
||||||
|
|
|
||||||
125
src/triangle.h
Normal file
125
src/triangle.h
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// Mesh and VertexFormat Data
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
struct Vertex {
|
||||||
|
float posX, posY, posZ, posW; // Position data
|
||||||
|
float r, g, b, a; // Color
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexUV {
|
||||||
|
float posX, posY, posZ, posW; // Position data
|
||||||
|
float u, v; // texture u,v
|
||||||
|
};
|
||||||
|
|
||||||
|
#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
|
||||||
|
#define UV(_u_, _v_) (_u_), (_v_)
|
||||||
|
|
||||||
|
static const Vertex g_vbData[] = {
|
||||||
|
{XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)},
|
||||||
|
|
||||||
|
{XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)}, {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)},
|
||||||
|
|
||||||
|
{XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Vertex g_vb_solid_face_colors_Data[] = {
|
||||||
|
// red face
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
{XYZ1(1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
|
||||||
|
// green face
|
||||||
|
{XYZ1(-1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
|
||||||
|
// blue face
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 1.f)},
|
||||||
|
// yellow face
|
||||||
|
{XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
{XYZ1(1, -1, -1), XYZ1(1.f, 1.f, 0.f)},
|
||||||
|
// magenta face
|
||||||
|
{XYZ1(1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
{XYZ1(-1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
|
||||||
|
// cyan face
|
||||||
|
{XYZ1(1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
{XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
{XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
{XYZ1(-1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const VertexUV g_vb_texture_Data[] = {
|
||||||
|
// left face
|
||||||
|
{XYZ1(-1, -1, -1), UV(1.f, 0.f)}, // lft-top-front
|
||||||
|
{XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
|
||||||
|
{XYZ1(-1, -1, 1), UV(0.f, 0.f)}, // lft-top-back
|
||||||
|
{XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
|
||||||
|
{XYZ1(-1, -1, -1), UV(1.f, 0.f)}, // lft-top-front
|
||||||
|
{XYZ1(-1, 1, -1), UV(1.f, 1.f)}, // lft-btm-front
|
||||||
|
// front face
|
||||||
|
{XYZ1(-1, -1, -1), UV(0.f, 0.f)}, // lft-top-front
|
||||||
|
{XYZ1(1, -1, -1), UV(1.f, 0.f)}, // rgt-top-front
|
||||||
|
{XYZ1(1, 1, -1), UV(1.f, 1.f)}, // rgt-btm-front
|
||||||
|
{XYZ1(-1, -1, -1), UV(0.f, 0.f)}, // lft-top-front
|
||||||
|
{XYZ1(1, 1, -1), UV(1.f, 1.f)}, // rgt-btm-front
|
||||||
|
{XYZ1(-1, 1, -1), UV(0.f, 1.f)}, // lft-btm-front
|
||||||
|
// top face
|
||||||
|
{XYZ1(-1, -1, -1), UV(0.f, 1.f)}, // lft-top-front
|
||||||
|
{XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
|
||||||
|
{XYZ1(1, -1, -1), UV(1.f, 1.f)}, // rgt-top-front
|
||||||
|
{XYZ1(-1, -1, -1), UV(0.f, 1.f)}, // lft-top-front
|
||||||
|
{XYZ1(-1, -1, 1), UV(0.f, 0.f)}, // lft-top-back
|
||||||
|
{XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
|
||||||
|
// bottom face
|
||||||
|
{XYZ1(-1, 1, -1), UV(0.f, 0.f)}, // lft-btm-front
|
||||||
|
{XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
|
||||||
|
{XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
|
||||||
|
{XYZ1(-1, 1, -1), UV(0.f, 0.f)}, // lft-btm-front
|
||||||
|
{XYZ1(1, 1, -1), UV(1.f, 0.f)}, // rgt-btm-front
|
||||||
|
{XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
|
||||||
|
// right face
|
||||||
|
{XYZ1(1, 1, -1), UV(0.f, 1.f)}, // rgt-btm-front
|
||||||
|
{XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
|
||||||
|
{XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
|
||||||
|
{XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
|
||||||
|
{XYZ1(1, 1, -1), UV(0.f, 1.f)}, // rgt-btm-front
|
||||||
|
{XYZ1(1, -1, -1), UV(0.f, 0.f)}, // rgt-top-front
|
||||||
|
// back face
|
||||||
|
{XYZ1(-1, 1, 1), UV(1.f, 1.f)}, // lft-btm-back
|
||||||
|
{XYZ1(1, 1, 1), UV(0.f, 1.f)}, // rgt-btm-back
|
||||||
|
{XYZ1(-1, -1, 1), UV(1.f, 0.f)}, // lft-top-back
|
||||||
|
{XYZ1(-1, -1, 1), UV(1.f, 0.f)}, // lft-top-back
|
||||||
|
{XYZ1(1, 1, 1), UV(0.f, 1.f)}, // rgt-btm-back
|
||||||
|
{XYZ1(1, -1, 1), UV(0.f, 0.f)}, // rgt-top-back
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue