diff --git a/.gitignore b/.gitignore index 45c8290..238bd5d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .vs/ out/ build/ +/build*/ Debug/ Release/ MinSizeRel/ diff --git a/.gitmodules b/.gitmodules index f4387cb..48cd9a8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,4 +21,7 @@ url = https://github.com/zeux/volk [submodule "dependencies/VulkanMemoryAllocator"] path = dependencies/VulkanMemoryAllocator - url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator \ No newline at end of file + url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator +[submodule "dependencies/assimp"] + path = dependencies/assimp + url = https://github.com/assimp/assimp diff --git a/CMakeLists.txt b/CMakeLists.txt index 08923e4..b02f3a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,10 +203,18 @@ set(FT_DISABLE_BZIP2 TRUE CACHE INTERNAL "" FORCE) set(FT_DISABLE_PNG TRUE CACHE INTERNAL "" FORCE) set(FT_DISABLE_HARFBUZZ TRUE CACHE INTERNAL "" FORCE) set(FT_DISABLE_BROTLI TRUE CACHE INTERNAL "" FORCE) -set(BUILD_SHARED_LIBS ON) +set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE) add_subdirectory(dependencies/freetype) target_link_libraries(${PROJECT_NAME} PRIVATE freetype) target_include_directories(${PROJECT_NAME} PRIVATE dependencies/freetype/include) # stb target_include_directories(${PROJECT_NAME} PRIVATE dependencies/stb) + +# assimp +set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE) +set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "" FORCE) +set(ASSIMP_INSTALL OFF CACHE INTERNAL "" FORCE) +add_subdirectory(dependencies/assimp) +target_include_directories(${PROJECT_NAME} PRIVATE dependencies/assimp/include) +target_link_libraries(${PROJECT_NAME} PRIVATE assimp) \ No newline at end of file diff --git a/dependencies/assimp b/dependencies/assimp new file mode 160000 index 0000000..6392dbf --- /dev/null +++ b/dependencies/assimp @@ -0,0 +1 @@ +Subproject commit 6392dbfe4d9b0e23d4e573d0f3e45a198412ece1 diff --git a/include/components/mesh_renderer.hpp b/include/components/mesh_renderer.hpp index a8b86fd..dd91a58 100644 --- a/include/components/mesh_renderer.hpp +++ b/include/components/mesh_renderer.hpp @@ -24,7 +24,7 @@ public: void render(glm::mat4 model, glm::mat4 view); void setMesh(const std::string& name); - void setTexture(const std::string& name); + void setTexture(const std::string& name, bool invertV = false); std::shared_ptr m_mesh = nullptr; std::shared_ptr m_texture; diff --git a/src/components/camera.cpp b/src/components/camera.cpp index ed9c246..eb59930 100644 --- a/src/components/camera.cpp +++ b/src/components/camera.cpp @@ -73,9 +73,9 @@ void Camera::usePerspective(float fovDeg) m_mode = Modes::PERSPECTIVE; m_fovDeg = fovDeg; - glm::vec2 viewportDim = getViewportSize(); - float fovRad = glm::radians(fovDeg); + + glm::vec2 viewportDim = getViewportSize(); m_projMatrix = glm::perspectiveFovRH_ZO(fovRad, viewportDim.x, viewportDim.y, NEAR, FAR); } diff --git a/src/components/mesh_renderer.cpp b/src/components/mesh_renderer.cpp index 312f2d2..58aef6e 100644 --- a/src/components/mesh_renderer.cpp +++ b/src/components/mesh_renderer.cpp @@ -40,9 +40,15 @@ void Renderer::setMesh(const std::string& name) m_mesh = parent.res.get(name); } -void Renderer::setTexture(const std::string& name) +void Renderer::setTexture(const std::string& name, bool invertV) { - m_texture = parent.res.get(name); + if (invertV) { + // append a special character to file name + m_texture = parent.res.get(name + "_"); + } + else { + m_texture = parent.res.get(name); + } } } diff --git a/src/gfx_device_opengl45.cpp b/src/gfx_device_opengl45.cpp index 381401e..e234cce 100644 --- a/src/gfx_device_opengl45.cpp +++ b/src/gfx_device_opengl45.cpp @@ -127,7 +127,7 @@ namespace engine { *h = (uint32_t)height; } - void GFXDevice::draw(const gfx::Pipeline* pipeline, const gfx::Buffer* vertexBuffer, const gfx::Buffer* indexBuffer, uint32_t count, const void* pushConstantData, size_t pushConstantSize) + void draw(const gfx::Pipeline* pipeline, const gfx::Buffer* vertexBuffer, const gfx::Buffer* indexBuffer, uint32_t count, const void* pushConstantData, size_t pushConstantSize, const gfx::Texture* texture) { assert(vertexBuffer->type == gfx::BufferType::VERTEX); assert(vertexBuffer != nullptr); diff --git a/src/gfx_device_vulkan.cpp b/src/gfx_device_vulkan.cpp index 98c13d7..aadb76b 100644 --- a/src/gfx_device_vulkan.cpp +++ b/src/gfx_device_vulkan.cpp @@ -500,11 +500,12 @@ namespace engine { static VkSampleCountFlagBits getMaxSampleCount(VkPhysicalDevice physicalDevice) { + VkPhysicalDeviceProperties physicalDeviceProperties; vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties); VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts; - counts %= VK_SAMPLE_COUNT_8_BIT; // restricts it to 8 + //counts %= VK_SAMPLE_COUNT_8_BIT; // restricts it to 8 if (counts & VK_SAMPLE_COUNT_64_BIT) { INFO("64"); return VK_SAMPLE_COUNT_64_BIT; } if (counts & VK_SAMPLE_COUNT_32_BIT) { INFO("32"); return VK_SAMPLE_COUNT_32_BIT; } if (counts & VK_SAMPLE_COUNT_16_BIT) { INFO("16"); return VK_SAMPLE_COUNT_16_BIT; } @@ -542,7 +543,30 @@ namespace engine { res = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &surfacePresentModeCount, presentModes.data()); assert(res == VK_SUCCESS); + VkExtent2D oldExtent = swapchain->extent; + if (caps.currentExtent.width != std::numeric_limits::max()) { + swapchain->extent = caps.currentExtent; + } + else { + // if fb size isn't already found, get it from SDL + int width, height; + SDL_Vulkan_GetDrawableSize(window, &width, &height); + + swapchain->extent.width = static_cast(width); + swapchain->extent.height = static_cast(height); + + swapchain->extent.width = std::clamp( + swapchain->extent.width, + caps.minImageExtent.width, caps.maxImageExtent.width); + swapchain->extent.height = std::clamp( + swapchain->extent.height, + caps.minImageExtent.height, caps.maxImageExtent.height); + } + + if (swapchain->extent.width == 0 || swapchain->extent.height == 0) { + swapchain->extent = oldExtent; + } // delete old framebuffers for (VkFramebuffer fb : swapchain->framebuffers) { @@ -570,27 +594,6 @@ namespace engine { } } - VkExtent2D oldExtent = swapchain->extent; - - if (caps.currentExtent.width != std::numeric_limits::max()) { - swapchain->extent = caps.currentExtent; - } - else { - // if fb size isn't already found, get it from SDL - int width, height; - SDL_Vulkan_GetDrawableSize(window, &width, &height); - - swapchain->extent.width = static_cast(width); - swapchain->extent.height = static_cast(height); - - swapchain->extent.width = std::clamp( - swapchain->extent.width, - caps.minImageExtent.width, caps.maxImageExtent.width); - swapchain->extent.height = std::clamp( - swapchain->extent.height, - caps.minImageExtent.height, caps.maxImageExtent.height); - } - uint32_t imageCount = caps.minImageCount + 1; if (caps.maxImageCount > 0 && imageCount > caps.maxImageCount) { imageCount = caps.maxImageCount; @@ -1507,8 +1510,15 @@ namespace engine { { int width, height; SDL_Vulkan_GetDrawableSize(pimpl->window, &width, &height); - *w = (uint32_t)width; - *h = (uint32_t)height; + if (width == 0 || height == 0) { + *w = (uint32_t)pimpl->swapchain.extent.width; + *h = (uint32_t)pimpl->swapchain.extent.height; + } + else { + *w = (uint32_t)width; + *h = (uint32_t)height; + } + } void GFXDevice::draw(const gfx::Pipeline* pipeline, const gfx::Buffer* vertexBuffer, const gfx::Buffer* indexBuffer, uint32_t count, const void* pushConstantData, size_t pushConstantSize, const gfx::Texture* texture) diff --git a/src/resources/texture.cpp b/src/resources/texture.cpp index e6060b4..72b2445 100644 --- a/src/resources/texture.cpp +++ b/src/resources/texture.cpp @@ -63,8 +63,17 @@ static bool readGLRaw(const std::string& path, std::vector* texbuf, int } -Texture::Texture(const std::filesystem::path& resPath) : Resource(resPath, "texture") +Texture::Texture(const std::filesystem::path& originalResPath) : Resource(originalResPath, "texture") { + + std::string resString = originalResPath.string(); + bool flipV = false; + if (resString.back() == '_') { + flipV = true; + resString.pop_back(); + } + + std::filesystem::path resPath{ resString }; auto texbuf = std::make_unique>(); diff --git a/test/res/textures/gun.png b/test/res/textures/gun.png index e54ce61..178588c 100644 Binary files a/test/res/textures/gun.png and b/test/res/textures/gun.png differ diff --git a/test/src/game.cpp b/test/src/game.cpp index 7bdbde2..2f10192 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -153,5 +153,10 @@ void playGame() boundsRen->m_mesh = genSphereMesh(100.0f, 100, true); boundsRen->setTexture("textures/metal.jpg"); + auto pyramid = app.scene()->createChild("pyramid"); + auto pyramidRen = pyramid->createComponent(); + pyramidRen->setMesh("meshes/pyramid.mesh"); + pyramidRen->setTexture("textures/pyramid.png"); + app.gameLoop(); }