diff --git a/dependencies/VulkanMemoryAllocator b/dependencies/VulkanMemoryAllocator index c351692..0e89587 160000 --- a/dependencies/VulkanMemoryAllocator +++ b/dependencies/VulkanMemoryAllocator @@ -1 +1 @@ -Subproject commit c351692490513cdb0e5a2c925aaf7ea4a9b672f4 +Subproject commit 0e89587db3ebee4d463f191bd296374c5fafc8ea diff --git a/include/scene.h b/include/scene.h index a3e47af..8ba6852 100644 --- a/include/scene.h +++ b/include/scene.h @@ -107,8 +107,9 @@ class Scene { private: Application* const app_; + public: Entity next_entity_id_ = 1; // 0 is not a valid entity - +private: uint64_t framecount_ = 0; /* ecs stuff */ diff --git a/res/engine/shaders/skybox.vert b/res/engine/shaders/skybox.vert index c7e94c3..7b7eb51 100644 --- a/res/engine/shaders/skybox.vert +++ b/res/engine/shaders/skybox.vert @@ -21,4 +21,5 @@ void main() { vec3 position = mat3(frameSetUniformBuffer.view) * vec3(constants.model * vec4(inPosition, 1.0)); gl_Position = (globalSetUniformBuffer.proj * vec4(position, 0.0)).xyzz; fragUV = inUV; + gl_Position.y *= -1.0; } diff --git a/res/engine/shaders/standard.vert b/res/engine/shaders/standard.vert index 110f309..1a0ef0d 100644 --- a/res/engine/shaders/standard.vert +++ b/res/engine/shaders/standard.vert @@ -30,4 +30,6 @@ void main() { vec3 lightPos = vec3(2000.0, 2000.0, -2000.0); fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0)); + + gl_Position.y *= -1.0; } diff --git a/src/gfx_device_vulkan.cpp b/src/gfx_device_vulkan.cpp index 5e2505a..b4a98d5 100644 --- a/src/gfx_device_vulkan.cpp +++ b/src/gfx_device_vulkan.cpp @@ -47,6 +47,8 @@ #include "log.h" #include "util/files.h" +static constexpr bool flip_viewport = false; + inline static void checkVulkanError(VkResult errorCode, int lineNo) { if (errorCode != VK_SUCCESS) { const std::string message("VULKAN ERROR ON LINE " + std::to_string(lineNo)); @@ -271,7 +273,7 @@ static VkShaderModule compileShader(VkDevice device, shaderc_shader_kind kind, VkShaderModuleCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; createInfo.codeSize = shaderBytecode.size() * sizeof(uint32_t); - createInfo.pCode = compiledShader.cbegin(); + createInfo.pCode = compiledShader.cbegin(); VkShaderModule shaderModule; if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != @@ -398,8 +400,6 @@ GFXDevice::GFXDevice(const char* appName, const char* appVersion, DeviceRequirements deviceRequirements{}; deviceRequirements.requiredExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME); - deviceRequirements.requiredExtensions.push_back( - VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME); deviceRequirements.optionalExtensions.push_back( VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME); deviceRequirements.optionalExtensions.push_back( @@ -728,10 +728,17 @@ gfx::DrawBuffer* GFXDevice::BeginRender() { VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport{}; - viewport.x = 0.0f; - viewport.y = (float)pimpl->swapchain.extent.height; - viewport.width = (float)pimpl->swapchain.extent.width; - viewport.height = -(float)pimpl->swapchain.extent.height; + if (flip_viewport) { + viewport.x = 0.0f; + viewport.y = (float)pimpl->swapchain.extent.height; + viewport.width = (float)pimpl->swapchain.extent.width; + viewport.height = -(float)pimpl->swapchain.extent.height; + } else { + viewport.x = 0.0f; + viewport.y = 0.0f; + viewport.width = (float)pimpl->swapchain.extent.width; + viewport.height = (float)pimpl->swapchain.extent.height; + } viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; vkCmdSetViewport(frameData.drawBuf, 0, 1, &viewport); @@ -950,10 +957,17 @@ gfx::Pipeline* GFXDevice::CreatePipeline(const gfx::PipelineInfo& info) { inputAssembly.primitiveRestartEnable = VK_FALSE; VkViewport viewport{}; - viewport.x = 0.0f; - viewport.y = (float)pimpl->swapchain.extent.height; - viewport.width = (float)pimpl->swapchain.extent.width; - viewport.height = -(float)pimpl->swapchain.extent.height; + if (flip_viewport) { + viewport.x = 0.0f; + viewport.y = (float)pimpl->swapchain.extent.height; + viewport.width = (float)pimpl->swapchain.extent.width; + viewport.height = -(float)pimpl->swapchain.extent.height; + } else { + viewport.x = 0.0f; + viewport.y = 0.0f; + viewport.width = (float)pimpl->swapchain.extent.width; + viewport.height = (float)pimpl->swapchain.extent.height; + } viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; @@ -1172,7 +1186,8 @@ gfx::DescriptorSet* GFXDevice::AllocateDescriptorSet( void GFXDevice::FreeDescriptorSet(const gfx::DescriptorSet* set) { assert(set != nullptr); VKCHECK(vkFreeDescriptorSets(pimpl->device.device, pimpl->descriptorPool, - static_cast(set->sets.size()), set->sets.data())); + static_cast(set->sets.size()), + set->sets.data())); } void GFXDevice::UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set, @@ -1413,7 +1428,7 @@ gfx::Image* GFXDevice::CreateImage(uint32_t w, uint32_t h, const void* imageData) { assert(imageData != nullptr); - if (pimpl->FRAMECOUNT != 0) abort(); // TODO. This is annoying + if (pimpl->FRAMECOUNT != 0) abort(); // TODO. This is annoying gfx::Image* out = new gfx::Image{}; diff --git a/src/renderer.cpp b/src/renderer.cpp index 008a9f0..fddd2ce 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -4,6 +4,24 @@ #include #include +[[maybe_unused]] static glm::mat4 GenPerspectiveMatrix(float vertical_fov_radians, + float aspect_ratio, float znear, + float zfar) { + float g = 1.0f / tan(vertical_fov_radians * 0.5); + float k1 = zfar / (zfar - znear); + float k2 = -(zfar * znear) / (znear - zfar); + glm::mat4 m{1.0f}; + + m[0][0] = g / aspect_ratio; + m[1][1] = g; + m[2][2] = k1; + m[2][3] = -1.0f; + m[3][2] = k2; + m[3][3] = 0.0f; + + return m; +} + namespace engine { Renderer::Renderer(const char* app_name, const char* app_version, @@ -71,7 +89,7 @@ void Renderer::PreRender(bool window_is_resized, glm::mat4 camera_transform) { uint32_t w, h; device_->GetViewportSize(&w, &h); viewport_aspect_ratio_ = (float)w / (float)h; - const glm::mat4 proj_matrix = glm::perspectiveZO( + const glm::mat4 proj_matrix = glm::perspectiveRH_ZO( camera_settings_.vertical_fov_radians, viewport_aspect_ratio_, camera_settings_.clip_near, camera_settings_.clip_far); /* update SET 0 (rarely changing uniforms)*/ diff --git a/src/util/model_loader.cpp b/src/util/model_loader.cpp index b9f6430..2dee0b7 100644 --- a/src/util/model_loader.cpp +++ b/src/util/model_loader.cpp @@ -144,7 +144,7 @@ namespace engine::util { aiProcess_GenSmoothNormals | aiProcess_GenUVCoords | aiProcess_TransformUVCoords | - aiProcess_FlipUVs | // Maybe? + aiProcess_FlipUVs | // Collada uses bottom-left origin 0 ); diff --git a/src/vulkan/instance.cpp b/src/vulkan/instance.cpp index f435ed2..744acb5 100644 --- a/src/vulkan/instance.cpp +++ b/src/vulkan/instance.cpp @@ -147,8 +147,6 @@ namespace engine { const std::vector windowExtensions = getWindowExtensions(window); std::vector instanceExtensionsToUse = windowExtensions; - instanceExtensionsToUse.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME); - const char* validationLayer = nullptr; if (useValidation) { validationLayer = getValidationLayer(); diff --git a/src/vulkan/swapchain.cpp b/src/vulkan/swapchain.cpp index 38a1ab2..ec5b482 100644 --- a/src/vulkan/swapchain.cpp +++ b/src/vulkan/swapchain.cpp @@ -117,14 +117,9 @@ namespace engine { /* create swapchain */ - VkSurfaceFullScreenExclusiveInfoEXT fullscreenInfo{}; - fullscreenInfo.sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT; - fullscreenInfo.pNext = nullptr; - fullscreenInfo.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT; - VkSwapchainCreateInfoKHR scInfo{ .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, - .pNext = &fullscreenInfo, + .pNext = nullptr, .flags = 0, .surface = info.surface, .minImageCount = minImageCount, diff --git a/test/res/models/MY_AXES.dae b/test/res/models/MY_AXES.dae new file mode 100644 index 0000000..658f570 --- /dev/null +++ b/test/res/models/MY_AXES.dae @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee415606d016bdfcfd9eb261f5542aacc48d62c398556e90b7dfb9f7805bfbd8 +size 52261 diff --git a/test/res/models/cobble_house/_stone_bricks.png b/test/res/models/cobble_house/_stone_bricks.png new file mode 100644 index 0000000..acc7b66 Binary files /dev/null and b/test/res/models/cobble_house/_stone_bricks.png differ diff --git a/test/res/models/cobble_house/stone_bricks.png b/test/res/models/cobble_house/stone_bricks.png index acc7b66..60f42f3 100644 Binary files a/test/res/models/cobble_house/stone_bricks.png and b/test/res/models/cobble_house/stone_bricks.png differ diff --git a/test/res/models/terrain.dae b/test/res/models/terrain.dae index 937f495..9801f77 100644 --- a/test/res/models/terrain.dae +++ b/test/res/models/terrain.dae @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:453a8fa9e7228b1514c27528f7aee48f06e00ffc5bdb2261daf0eaca149102ac -size 3613212 +oid sha256:35b8b6f27ba0f7184403ea880849ff6d6a11d451abe376fe0cb76e2bc1e35c51 +size 3613159 diff --git a/test/res/models/uvcheck.dae b/test/res/models/uvcheck.dae new file mode 100644 index 0000000..a64d265 --- /dev/null +++ b/test/res/models/uvcheck.dae @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e810911adc9fec4f480c75031ff1747760428a169701e5e1f9f3d2ad89a52b9a +size 4512 diff --git a/test/res/textures/uvcheck.png b/test/res/textures/uvcheck.png new file mode 100644 index 0000000..60f42f3 Binary files /dev/null and b/test/res/textures/uvcheck.png differ diff --git a/test/src/game.cpp b/test/src/game.cpp index 7d71a7b..f2db5ce 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -142,16 +142,17 @@ void PlayGame(GameSettings settings) { LOG_DEBUG("Textbox custom component initialised!"); }; - textboxComponent->onUpdate = [](float ts) { + textboxComponent->onUpdate = [&](float ts) { static float time_elapsed; time_elapsed += ts; if (time_elapsed >= 1.0f) { time_elapsed = 0.0f; - LOG_INFO("COMPONENT UPDATE"); } }; } + engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/MY_AXES.dae"), true); + my_scene->GetComponent(engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/uvcheck.dae"), true))->position += glm::vec3{20.0f, 20.0f, 20.0f}; /* teapot */ my_scene ->GetComponent(