Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Show changes
Commits on Source (153)
Showing
with 164 additions and 55 deletions
......@@ -80,4 +80,7 @@ set(vkcv_sources
${vkcv_source}/vkcv/CommandStreamManager.cpp
${vkcv_include}/vkcv/CommandRecordingFunctionTypes.hpp
${vkcv_include}/vkcv/ImageConfig.hpp
${vkcv_source}/vkcv/ImageConfig.cpp
)
......@@ -78,8 +78,6 @@ namespace vkcv
event_handle<int,int> e_resizeHandle;
static std::vector<vk::ImageView> createSwapchainImageViews( Context &context, Swapchain& swapChain);
public:
/**
* Destructor of #Core destroys the Vulkan objects contained in the core's context.
......@@ -215,13 +213,14 @@ namespace vkcv
*/
[[nodiscard]]
Image createImage(
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth = 1,
bool createMipChain = false,
bool supportStorage = false,
bool supportColorAttachment = false);
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth = 1,
bool createMipChain = false,
bool supportStorage = false,
bool supportColorAttachment = false,
Multisampling multisampling = Multisampling::None);
[[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle);
......@@ -290,7 +289,8 @@ namespace vkcv
void prepareImageForStorage(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordImageMemoryBarrier(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordBufferMemoryBarrier(const CommandStreamHandle cmdStream, const BufferHandle buffer);
void resolveMSAAImage(CommandStreamHandle cmdStream, ImageHandle src, ImageHandle dst);
vk::ImageView getSwapchainImageView() const;
};
......
......@@ -37,11 +37,12 @@ namespace vkcv {
};
struct DrawcallInfo {
inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets)
: mesh(mesh), descriptorSets(descriptorSets) {}
inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets, const uint32_t instanceCount = 1)
: mesh(mesh), descriptorSets(descriptorSets), instanceCount(instanceCount){}
Mesh mesh;
std::vector<DescriptorSetUsage> descriptorSets;
uint32_t instanceCount;
};
void recordDrawcall(
......
......@@ -7,11 +7,11 @@
#include "vulkan/vulkan.hpp"
#include "Handles.hpp"
#include "vkcv/ImageConfig.hpp"
namespace vkcv {
// forward declares
class ImageManager;
class ImageManager;
bool isDepthFormat(const vk::Format format);
......@@ -50,15 +50,16 @@ namespace vkcv {
Image(ImageManager* manager, const ImageHandle& handle);
static Image create(
ImageManager* manager,
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipCount,
bool supportStorage,
bool supportColorAttachment);
ImageManager* manager,
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipCount,
bool supportStorage,
bool supportColorAttachment,
Multisampling msaa);
};
}
#pragma once
#include <vulkan/vulkan.hpp>
namespace vkcv {
enum class Multisampling { None, MSAA2X, MSAA4X, MSAA8X };
vk::SampleCountFlagBits msaaToVkSampleCountFlag(Multisampling msaa);
uint32_t msaaToSampleCount(Multisampling msaa);
}
......@@ -2,6 +2,7 @@
#include <vector>
#include <vulkan/vulkan.hpp>
#include "ImageConfig.hpp"
namespace vkcv
{
......@@ -45,7 +46,8 @@ namespace vkcv
struct PassConfig
{
explicit PassConfig(std::vector<AttachmentDescription> attachments) noexcept;
explicit PassConfig(std::vector<AttachmentDescription> attachments, Multisampling msaa = Multisampling::None) noexcept;
std::vector<AttachmentDescription> attachments{};
Multisampling msaa;
};
}
\ No newline at end of file
......@@ -10,21 +10,35 @@
#include "Handles.hpp"
#include "ShaderProgram.hpp"
#include "VertexLayout.hpp"
#include "ImageConfig.hpp"
namespace vkcv {
enum class PrimitiveTopology{PointList, LineList, TriangleList };
enum class CullMode{ None, Front, Back };
enum class DepthTest { None, Less, LessEqual, Greater, GreatherEqual, Equal };
// add more as needed
// alternatively we could expose the blend factors directly
enum class BlendMode{ None, Additive };
struct PipelineConfig {
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
bool m_EnableDepthClamping = false;
Multisampling m_multisampling = Multisampling::None;
CullMode m_culling = CullMode::None;
DepthTest m_depthTest = DepthTest::LessEqual;
bool m_depthWrite = true;
bool m_alphaToCoverage = false;
};
}
\ No newline at end of file
......@@ -7,6 +7,9 @@
namespace vkcv
{
const uint32_t MIN_SWAPCHAIN_SIZE = 2;
class Swapchain final {
private:
friend class Core;
......@@ -119,4 +122,5 @@ namespace vkcv
const vk::Extent2D& getExtent() const;
};
}
......@@ -157,6 +157,13 @@ namespace vkcv {
* Destructor of #Window, terminates GLFW
*/
virtual ~Window();
/**
* gets the windows framebuffer size
* @param width
* @param height
*/
void getFramebufferSize(int& width, int& height) const;
};
}
......@@ -9,6 +9,7 @@
#include <vector>
#include <array>
#include <cstdint>
#include <filesystem>
/** These macros define limits of the following structs. Implementations can
* test against these limits when performing sanity checks. The main constraint
......@@ -114,7 +115,8 @@ enum class PrimitiveType : uint32_t {
POSITION = 1,
NORMAL = 2,
TEXCOORD_0 = 3,
TEXCOORD_1 = 4
TEXCOORD_1 = 4,
TANGENT = 5
};
/** These integer values are used the same way in OpenGL, Vulkan and glTF. This
......@@ -189,5 +191,12 @@ typedef struct {
* */
int loadScene(const std::string &path, Scene &scene);
struct TextureData {
int width;
int height;
int componentCount;
std::vector<char*> data;
};
TextureData loadTexture(const std::filesystem::path& path);
}
......@@ -63,8 +63,7 @@ enum IndexType getIndexType(const enum fx::gltf::Accessor::ComponentType &t)
case fx::gltf::Accessor::ComponentType::UnsignedInt:
return IndexType::UINT32;
default:
std::cerr << "ERROR: Index type not supported: " <<
static_cast<uint16_t>(t) << std::endl;
vkcv_log(LogLevel::ERROR, "Index type not supported: %u", static_cast<uint16_t>(t));
return IndexType::UNDEFINED;
}
}
......@@ -174,8 +173,11 @@ int loadScene(const std::string &path, Scene &scene){
attribute.type = PrimitiveType::NORMAL;
} else if (attrib.first == "TEXCOORD_0") {
attribute.type = PrimitiveType::TEXCOORD_0;
} else if (attrib.first == "TEXCOORD_1") {
}
else if (attrib.first == "TEXCOORD_1") {
attribute.type = PrimitiveType::TEXCOORD_1;
} else if (attrib.first == "TANGENT") {
attribute.type = PrimitiveType::TANGENT;
} else {
return 0;
}
......@@ -363,4 +365,23 @@ int loadScene(const std::string &path, Scene &scene){
return 1;
}
TextureData loadTexture(const std::filesystem::path& path) {
TextureData texture;
uint8_t* data = stbi_load(path.string().c_str(), &texture.width, &texture.height, &texture.componentCount, 4);
if (!data) {
vkcv_log(LogLevel::ERROR, "Texture could not be loaded from '%s'", path.c_str());
texture.width = 0;
texture.height = 0;
texture.componentCount = 0;
return texture;
}
texture.data.resize(texture.width * texture.height * 4);
memcpy(texture.data.data(), data, texture.data.size());
return texture;
}
}
......@@ -75,7 +75,7 @@ namespace vkcv::camera {
* @brief Gets the current projection of the camera
* @return The current projection matrix
*/
const glm::mat4& getProjection() const;
glm::mat4 getProjection() const;
/**
* @brief Gets the model-view-projection matrix of the camera with y-axis-correction applied
......
......@@ -37,22 +37,22 @@ namespace vkcv::camera {
m_view = view;
}
const glm::mat4& Camera::getProjection() const {
return m_projection;
const glm::mat4 y_correction(
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
glm::mat4 Camera::getProjection() const {
return y_correction * m_projection;
}
void Camera::setProjection(const glm::mat4& projection) {
m_projection = projection;
m_projection = glm::inverse(y_correction) * projection;
}
glm::mat4 Camera::getMVP() const {
const glm::mat4 y_correction (
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
return y_correction * m_projection * m_view;
}
......
......@@ -3,5 +3,6 @@
add_subdirectory(bloom)
add_subdirectory(first_triangle)
add_subdirectory(first_mesh)
add_subdirectory(particle_simulation)
add_subdirectory(first_scene)
add_subdirectory(voxelization)
\ No newline at end of file
add_subdirectory(voxelization)
......@@ -175,8 +175,8 @@ int main(int argc, const char** argv) {
std::vector<vkcv::DrawcallInfo> shadowDrawcalls;
for (const auto& position : instancePositions) {
modelMatrices.push_back(glm::translate(glm::mat4(1.f), position));
drawcalls.push_back(vkcv::DrawcallInfo(loadedMesh, { descriptorUsage }));
shadowDrawcalls.push_back(vkcv::DrawcallInfo(loadedMesh, {}));
drawcalls.push_back(vkcv::DrawcallInfo(loadedMesh, { descriptorUsage },1));
shadowDrawcalls.push_back(vkcv::DrawcallInfo(loadedMesh, {},1));
}
modelMatrices.back() *= glm::scale(glm::mat4(1.f), glm::vec3(10.f, 1.f, 10.f));
......
......@@ -83,6 +83,7 @@ int main(int argc, const char** argv) {
firstMeshProgram.addShader(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/frag.spv"));
auto& attributes = mesh.vertexGroups[0].vertexBuffer.attributes;
std::sort(attributes.begin(), attributes.end(), [](const vkcv::asset::VertexAttribute& x, const vkcv::asset::VertexAttribute& y) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
......@@ -149,7 +150,7 @@ int main(int argc, const char** argv) {
const vkcv::Mesh renderMesh(vertexBufferBindings, indexBuffer.getVulkanHandle(), mesh.vertexGroups[0].numIndices);
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle);
vkcv::DrawcallInfo drawcall(renderMesh, { descriptorUsage });
vkcv::DrawcallInfo drawcall(renderMesh, { descriptorUsage },1);
vkcv::camera::CameraManager cameraManager(window);
uint32_t camIndex0 = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
......
......@@ -199,7 +199,7 @@ int main(int argc, const char** argv) {
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSets[i]).vulkanHandle);
drawcalls.push_back(vkcv::DrawcallInfo(renderMesh, {descriptorUsage}));
drawcalls.push_back(vkcv::DrawcallInfo(renderMesh, {descriptorUsage},1));
}
std::vector<glm::mat4> modelMatrices;
......
......@@ -167,7 +167,7 @@ int main(int argc, const char** argv) {
vkcv::ImageHandle swapchainImageHandle = vkcv::ImageHandle::createSwapchainImageHandle();
const vkcv::Mesh renderMesh({}, triangleIndexBuffer.getVulkanHandle(), 3);
vkcv::DrawcallInfo drawcall(renderMesh, {});
vkcv::DrawcallInfo drawcall(renderMesh, {},1);
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
......
particle_simulation
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(particle_simulation)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# this should fix the execution path to load local files from the project
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project
add_executable(particle_simulation
src/main.cpp
src/ParticleSystem.hpp
src/ParticleSystem.cpp
src/Particle.hpp
src/Particle.cpp
src/BloomAndFlares.hpp
src/BloomAndFlares.cpp)
# this should fix the execution path to load local files from the project (for MSVC)
if(MSVC)
set_target_properties(particle_simulation PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set_target_properties(particle_simulation PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
# in addition to setting the output directory, the working directory has to be set
# by default visual studio sets the working directory to the build directory, when using the debugger
set_target_properties(particle_simulation PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
# including headers of dependencies and the VkCV framework
target_include_directories(particle_simulation SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(particle_simulation vkcv vkcv_testing vkcv_camera vkcv_shader_compiler)