mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Do things
This commit is contained in:
parent
5890f94fe5
commit
d76c8bb9cb
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
layout(binding = 0) uniform UBO {
|
layout(binding = 0) uniform UBO {
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
|
mat4 view;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout( push_constant ) uniform Constants {
|
layout( push_constant ) uniform Constants {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(binding = 0) uniform UBO {
|
layout(set = 0, binding = 0) uniform UBO {
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
|
mat4 view;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout( push_constant ) uniform Constants {
|
layout( push_constant ) uniform Constants {
|
||||||
|
@ -503,7 +503,7 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is called not just on initialisation, but also when the window is resized.
|
// This is called not just on initialisation, but also when the window is resized.
|
||||||
static void createSwapchain(VkDevice device, VkPhysicalDevice physicalDevice, VmaAllocator allocator, std::vector<Queue> queues, SDL_Window* window, VkSurfaceKHR surface, bool vsync, Swapchain* swapchain)
|
static void createSwapchain(VkDevice device, VkPhysicalDevice physicalDevice, VmaAllocator allocator, std::vector<Queue> queues, SDL_Window* window, VkSurfaceKHR surface, bool vsync, bool useMSAA, Swapchain* swapchain)
|
||||||
{
|
{
|
||||||
[[maybe_unused]] VkResult res;
|
[[maybe_unused]] VkResult res;
|
||||||
|
|
||||||
@ -636,7 +636,10 @@ namespace engine {
|
|||||||
assert(res == VK_SUCCESS);
|
assert(res == VK_SUCCESS);
|
||||||
|
|
||||||
// Use multisample anti-aliasing
|
// Use multisample anti-aliasing
|
||||||
|
if (useMSAA)
|
||||||
swapchain->msaaSamples = getMaxSampleCount(physicalDevice);
|
swapchain->msaaSamples = getMaxSampleCount(physicalDevice);
|
||||||
|
else
|
||||||
|
swapchain->msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
// create depth buffer if old depth buffer is wrong size.
|
// create depth buffer if old depth buffer is wrong size.
|
||||||
// Also do the same for the MSAA buffer.
|
// Also do the same for the MSAA buffer.
|
||||||
@ -663,6 +666,8 @@ namespace engine {
|
|||||||
* 0: color attachment with msaa samples,
|
* 0: color attachment with msaa samples,
|
||||||
* 1: depth attachment with msaa samples, used for fragment shading
|
* 1: depth attachment with msaa samples, used for fragment shading
|
||||||
* 2: present src (resolve) attachment with 1 sample, used for swapchain present
|
* 2: present src (resolve) attachment with 1 sample, used for swapchain present
|
||||||
|
*
|
||||||
|
* if msaa is disabled, 0 is used for swapchain present and 2 is ignored
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VkAttachmentDescription colorAttachment{};
|
VkAttachmentDescription colorAttachment{};
|
||||||
@ -673,7 +678,11 @@ namespace engine {
|
|||||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
if (useMSAA) {
|
||||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
} else {
|
||||||
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
}
|
||||||
|
|
||||||
colorAttachmentRef.attachment = 0;
|
colorAttachmentRef.attachment = 0;
|
||||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
@ -709,7 +718,11 @@ namespace engine {
|
|||||||
subpass.colorAttachmentCount = 1;
|
subpass.colorAttachmentCount = 1;
|
||||||
subpass.pColorAttachments = &colorAttachmentRef;
|
subpass.pColorAttachments = &colorAttachmentRef;
|
||||||
subpass.pDepthStencilAttachment = &depthAttachmentRef;
|
subpass.pDepthStencilAttachment = &depthAttachmentRef;
|
||||||
|
if (useMSAA) {
|
||||||
subpass.pResolveAttachments = &colorAttachmentResolveRef;
|
subpass.pResolveAttachments = &colorAttachmentResolveRef;
|
||||||
|
} else {
|
||||||
|
subpass.pResolveAttachments = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
VkSubpassDependency dependency{};
|
VkSubpassDependency dependency{};
|
||||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
@ -723,7 +736,11 @@ namespace engine {
|
|||||||
|
|
||||||
VkRenderPassCreateInfo createInfo{};
|
VkRenderPassCreateInfo createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||||
createInfo.attachmentCount = (uint32_t)attachments.size();
|
if (useMSAA) {
|
||||||
|
createInfo.attachmentCount = 3;
|
||||||
|
} else {
|
||||||
|
createInfo.attachmentCount = 2;
|
||||||
|
}
|
||||||
createInfo.pAttachments = attachments.data();
|
createInfo.pAttachments = attachments.data();
|
||||||
createInfo.subpassCount = 1;
|
createInfo.subpassCount = 1;
|
||||||
createInfo.pSubpasses = &subpass;
|
createInfo.pSubpasses = &subpass;
|
||||||
@ -766,7 +783,12 @@ namespace engine {
|
|||||||
VkFramebufferCreateInfo framebufferInfo{};
|
VkFramebufferCreateInfo framebufferInfo{};
|
||||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
framebufferInfo.renderPass = swapchain->renderpass;
|
framebufferInfo.renderPass = swapchain->renderpass;
|
||||||
framebufferInfo.attachmentCount = (uint32_t)attachments.size();
|
if (useMSAA) {
|
||||||
|
framebufferInfo.attachmentCount = 3;
|
||||||
|
} else {
|
||||||
|
attachments[0] = swapchain->imageViews[i];
|
||||||
|
framebufferInfo.attachmentCount = 2;
|
||||||
|
}
|
||||||
framebufferInfo.pAttachments = attachments.data();
|
framebufferInfo.pAttachments = attachments.data();
|
||||||
framebufferInfo.width = swapchain->extent.width;
|
framebufferInfo.width = swapchain->extent.width;
|
||||||
framebufferInfo.height = swapchain->extent.height;
|
framebufferInfo.height = swapchain->extent.height;
|
||||||
@ -1431,7 +1453,7 @@ namespace engine {
|
|||||||
|
|
||||||
|
|
||||||
// Now make the swapchain
|
// Now make the swapchain
|
||||||
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
|
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1560,7 +1582,7 @@ namespace engine {
|
|||||||
if (res == VK_ERROR_OUT_OF_DATE_KHR) {
|
if (res == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
// recreate swapchain
|
// recreate swapchain
|
||||||
waitIdle();
|
waitIdle();
|
||||||
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
|
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1693,7 +1715,7 @@ namespace engine {
|
|||||||
if (res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR) {
|
if (res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
// recreate swapchain
|
// recreate swapchain
|
||||||
waitIdle();
|
waitIdle();
|
||||||
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, &pimpl->swapchain);
|
createSwapchain(pimpl->device, pimpl->physicalDevice, pimpl->allocator, pimpl->queues, pimpl->window, pimpl->surface, pimpl->vsync, false, &pimpl->swapchain);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(res == VK_SUCCESS);
|
assert(res == VK_SUCCESS);
|
||||||
|
@ -36,7 +36,7 @@ namespace engine::resources {
|
|||||||
}
|
}
|
||||||
vertFormat.stride = stride;
|
vertFormat.stride = stride;
|
||||||
|
|
||||||
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4), alphaBlending, cullBackFace);
|
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4) * 2, alphaBlending, cullBackFace);
|
||||||
|
|
||||||
INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attributeDescriptions.size());
|
INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attributeDescriptions.size());
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,15 @@ namespace engine {
|
|||||||
assert(r->mesh != nullptr);
|
assert(r->mesh != nullptr);
|
||||||
assert(r->material->m_texture != nullptr);
|
assert(r->material->m_texture != nullptr);
|
||||||
|
|
||||||
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &projMatrix, sizeof(projMatrix), 0);
|
struct {
|
||||||
|
glm::mat4 proj;
|
||||||
|
glm::mat4 view;
|
||||||
|
} uniform{};
|
||||||
|
|
||||||
|
uniform.proj = projMatrix;
|
||||||
|
uniform.view = viewMatrix;
|
||||||
|
|
||||||
|
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &uniform, sizeof(glm::mat4) * 2, 0);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
@ -84,7 +92,7 @@ namespace engine {
|
|||||||
|
|
||||||
void RenderSystem::setCameraEntity(uint32_t entity)
|
void RenderSystem::setCameraEntity(uint32_t entity)
|
||||||
{
|
{
|
||||||
{ m_camera.camEntity = entity; }
|
m_camera.camEntity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
@ -50,8 +50,6 @@ void CameraControllerSystem::onUpdate(float ts)
|
|||||||
glm::vec3 dir = glm::normalize(glm::rotateY(glm::vec3{ 1.0f, 0.0f, 0.0f }, c->m_yaw) + glm::rotateY(glm::vec3{ 0.0f, 0.0f, 1.0f }, c->m_yaw));
|
glm::vec3 dir = glm::normalize(glm::rotateY(glm::vec3{ 1.0f, 0.0f, 0.0f }, c->m_yaw) + glm::rotateY(glm::vec3{ 0.0f, 0.0f, 1.0f }, c->m_yaw));
|
||||||
const float slope = glm::dot(dir, norm);
|
const float slope = glm::dot(dir, norm);
|
||||||
|
|
||||||
INFO("slope: {}", slope);
|
|
||||||
|
|
||||||
bool isSliding = false;
|
bool isSliding = false;
|
||||||
|
|
||||||
if (c->justCollided) {
|
if (c->justCollided) {
|
||||||
|
Loading…
Reference in New Issue
Block a user